# finding angle from a coordinate Classic List Threaded 8 messages Open this post in threaded view
|

## finding angle from a coordinate

 I have a column with a radius of 1. The column's base is located at 0,0,0, and its top is located at 3,4,5. As I understand it, to orient the column I need to use rotate, rather than specify the endpoint. [code] translate([0,0,0]) {   rotate([a,b,c]) {     cylinder(r = 1, h = 7.071); } } [/code] How would I go about finding the angles a,b,c, knowing the endpoint? Thanks!
Open this post in threaded view
|

## Re: finding angle from a coordinate

 decompose it into a couple rotates and use some trigonometry: \$fn=30; X = 3; Y = 4; Z = 5; R = 1; rotate([0,0,atan(Y/X)]) rotate([0, atan(sqrt(X*X + Y*Y) / Z), 0]) cylinder(r = R, h = sqrt(X*X + Y*Y + Z*Z)); color("red") translate([X,Y,Z]) sphere(r=R); 2016-10-12 22:26 GMT-03:00 tony873004 <[hidden email]>: > I have a column with a radius of 1. > The column's base is located at 0,0,0, and its top is located at 3,4,5. > As I understand it, to orient the column I need to use rotate, rather than > specify the endpoint. > [code] > translate([0,0,0]) { >   rotate([a,b,c]) { >     cylinder(r = 1, h = 7.071); > } > } > [/code] > How would I go about finding the angles a,b,c, knowing the endpoint? > Thanks! > > > > > -- > View this message in context: http://forum.openscad.org/finding-angle-from-a-coordinate-tp18684.html> Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > [hidden email] > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: finding angle from a coordinate

Open this post in threaded view
|

## Re: finding angle from a coordinate

Open this post in threaded view
|

## Re: finding angle from a coordinate

 In reply to this post by Felipe Sanches Your solution is restricted to X!=0 and Z!=0. For a robust trigonometric solution, see Rotation Rule in the manual. It uses atan2(). Felipe Sanches wrote decompose it into a couple rotates and use some trigonometry: \$fn=30; X = 3; Y = 4; Z = 5; R = 1; rotate([0,0,atan(Y/X)]) rotate([0, atan(sqrt(X*X + Y*Y) / Z), 0]) cylinder(r = R, h = sqrt(X*X + Y*Y + Z*Z)); color("red") translate([X,Y,Z]) sphere(r=R);
Open this post in threaded view
|

## Re: finding angle from a coordinate

 In reply to this post by tony873004 Thanks for all the fast and great replies! I'll try them tomorrow and let you know how it goes.