I'm trying to construct a model where I have a set of 3D points, and I want to create "rods" connecting certain pairs of these points
Here's how I've done it in the past. This draws a cylinder centred at the midpoint of p1 and p2, rotated so that its [previously vertical]
extrusion axis is between the points.
module drawRay(p1,p2,tk){ // draw ray between 2 specified points
translate((p1+p2)/2)
rotate([-acos((p2[2]-p1[2]) / norm(p1-p2)),0,
-atan2(p2[0]-p1[0],p2[1]-p1[1])])
cylinder(r1=tk, r2=tk*0.5, h=norm(p1-p2), $fn = 6, center = true);
}
p1, p2: source and target point respectively
tk: thickness of cylinder
- Change $fn to something higher to make a smoother cylinder
- Delete "r2=..." to have a constant thickness of cylinder
- Add additional "sphere" definitions at each point if you want rounded edges.
> I'm trying to construct a model where I have a set of 3D points, and I want to create "rods" connecting certain pairs of these points
Here's how I've done it in the past. This draws a cylinder centred at the midpoint of p1 and p2, rotated so that its [previously vertical]
extrusion axis is between the points.
module drawRay(p1,p2,tk){ // draw ray between 2 specified points
translate((p1+p2)/2)
rotate([-acos((p2[2]-p1[2]) / norm(p1-p2)),0,
-atan2(p2[0]-p1[0],p2[1]-p1[1])])
cylinder(r1=tk, r2=tk*0.5, h=norm(p1-p2), $fn = 6, center = true);
}
p1, p2: source and target point respectively
tk: thickness of cylinder
* Change $fn to something higher to make a smoother cylinder
* Delete "r2=..." to have a constant thickness of cylinder
* Add additional "sphere" definitions at each point if you want rounded edges.
- David