On 18.02.2015 02:31, anp me@anp.me wrote:
Then the question is, how do I calculate the needed rotations and
translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end at
POINTS[i+1] ?
The following code should do what you want. The connectPoints module generates a cylinder centred at the midpoint of p1 and p2, rotated
appropriately to face the two points:
module connectPoints(p1,p2,RADIUS){
translate((p1+p2)/2)
rotate([-acos((p2[2]-p1[2]) / norm(p1-p2)),0,
-atan2(p2[0]-p1[0],p2[1]-p1[1])])
cylinder(r=RADIUS, h=norm(p1-p2), center = true, $fn=12);
}
POINTS =
[[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]];
for(i = [0:len(POINTS)-2]){
connectPoints(POINTS[i],POINTS[i+1],1);
}
I use this to generate connections between bases on DNA models. The code for doing the rotation was picked up somewhere from the web, but I
can't recall where -- it's a somewhat common problem.
Big thanks for all the guys ! Hypher's code worked awesome, topic can be
closed!
Sorry for "small talk", just I don't know how to close thread another way :)
Love!
--
View this message in context: http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11665.html
Sent from the OpenSCAD mailing list archive at Nabble.com.