// AngelCAD code.
shape@ main_shape()
{
// the straight pipe is vertical in range z=[0,100]
polyhedron@ p = polyhedron("xcsg/pipe_straight.amf");
// bend between z=[z1,z2]
double z1=30,z2=70;
// bend radius and bend angle
double b_rad= 25;
double b_ang= 90;
// perform the bend by transforming polyhedron vertices selectively
uint nvert = p.nvert();
for(uint i=0; i<nvert;i++) {
pos3d@ vpos = p.vertex(i); // vertex position
double z = vpos.z();
if(z>=z1 && z<z2) {
// bend area
double angle = b_ang*(z-z1)/(z2-z1);
tmatrix@ t = translate(b_rad,0,z1)*rotate_y(deg:angle)*translate(-b_rad,0,-z);
p.set_vertex(i,t*vpos);
}
else if(z > z2) {
// above bend area
tmatrix@ t = translate(b_rad,0,z1)*rotate_y(deg:b_ang)*translate(-b_rad,0,-z2);
p.set_vertex(i,t*vpos);
}
}
return p;
}
void main()
{
shape@ obj = main_shape();
obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}
Last active
May 8, 2018 19:41
-
-
Save arnholm/fadb3e6c7e38983643377569ca94d0b9 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment