discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

finding angle from a coordinate

T
tony873004
Thu, Oct 13, 2016 1:26 AM

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.

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.
FS
Felipe Sanches
Thu, Oct 13, 2016 1:55 AM

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(XX + YY) / Z), 0])

cylinder(r = R, h = sqrt(XX + YY + Z*Z));

color("red")

translate([X,Y,Z])

sphere(r=R);

2016-10-12 22:26 GMT-03:00 tony873004 tony@gravitysimulator.com:

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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <tony@gravitysimulator.com>: > 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
RP
Ronaldo Persiano
Thu, Oct 13, 2016 2:01 AM

You may try this solution:
Drawing lines...
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Tips_and_Tricks#Drawing_.22lines.22_in_OpenSCAD

2016-10-12 22:26 GMT-03:00 tony873004 tony@gravitysimulator.com:

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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

You may try this solution: Drawing lines... <https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Tips_and_Tricks#Drawing_.22lines.22_in_OpenSCAD> 2016-10-12 22:26 GMT-03:00 tony873004 <tony@gravitysimulator.com>: > 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
DB
don bright
Thu, Oct 13, 2016 2:03 AM

Here is my attempt

https://gist.github.com/donbright/b1999d40048b771d32fe9324e904a9f8

It is somewhat certain to work in all 8 octants

--
don bright
hmbright@fastmail.com

On Wed, Oct 12, 2016, at 08:26 PM, tony873004 wrote:

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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Here is my attempt https://gist.github.com/donbright/b1999d40048b771d32fe9324e904a9f8 It is somewhat certain to work in all 8 octants -- don bright hmbright@fastmail.com On Wed, Oct 12, 2016, at 08:26 PM, tony873004 wrote: > 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
R
Ronaldo
Thu, Oct 13, 2016 3:08 AM

Your solution is restricted to X!=0 and Z!=0.
For a robust trigonometric solution, see  Rotation Rule
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#Rotation_rule_help
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(XX + YY) / Z), 0])

cylinder(r = R, h = sqrt(XX + YY + Z*Z));

color("red")

translate([X,Y,Z])

sphere(r=R);

--
View this message in context: http://forum.openscad.org/finding-angle-from-a-coordinate-tp18684p18688.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Your solution is restricted to X!=0 and Z!=0. For a robust trigonometric solution, see Rotation Rule <https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#Rotation_rule_help> 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); -- View this message in context: http://forum.openscad.org/finding-angle-from-a-coordinate-tp18684p18688.html Sent from the OpenSCAD mailing list archive at Nabble.com.
T
tony873004
Thu, Oct 13, 2016 3:08 AM

Thanks for all the fast and great replies!
I'll try them tomorrow and let you know how it goes.

--
View this message in context: http://forum.openscad.org/finding-angle-from-a-coordinate-tp18684p18689.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Thanks for all the fast and great replies! I'll try them tomorrow and let you know how it goes. -- View this message in context: http://forum.openscad.org/finding-angle-from-a-coordinate-tp18684p18689.html Sent from the OpenSCAD mailing list archive at Nabble.com.
T
tony873004
Fri, Oct 14, 2016 2:40 AM

The rotation rule from the manual was exactly what I was looking for. Worked
in all 8 octants. Thanks!

--
View this message in context: http://forum.openscad.org/finding-angle-from-a-coordinate-tp18684p18701.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

The rotation rule from the manual was exactly what I was looking for. Worked in all 8 octants. Thanks! -- View this message in context: http://forum.openscad.org/finding-angle-from-a-coordinate-tp18684p18701.html Sent from the OpenSCAD mailing list archive at Nabble.com.
O
otto
Thu, Nov 17, 2016 7:36 PM

Questions like yours are one of the motivations for a new turtle.scad
library at:

https://github.com/ottojas/openscad-affine

Documentation is in md file and there are some examples.  These
avoid explictly calculating the angle.

your program could then be (for cylinder alone)

include <turtle.scad>
path = [[lookAt([3,4,5]),turnDown(90)]];
    turtlePath(path){cylinder(r1 = 1, r2= .5, h = 7.071);}

You do not need to do the trig yourself.

Regards
Otto

On Wed, 12 Oct 2016 18:26:59 -0700 (MST)
tony873004 tony@gravitysimulator.com wrote:

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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Questions like yours are one of the motivations for a new turtle.scad library at: https://github.com/ottojas/openscad-affine Documentation is in md file and there are some examples. These avoid explictly calculating the angle. your program could then be (for cylinder alone) ``` include <turtle.scad> path = [[lookAt([3,4,5]),turnDown(90)]]; turtlePath(path){cylinder(r1 = 1, r2= .5, h = 7.071);} ``` You do not need to do the trig yourself. Regards Otto On Wed, 12 Oct 2016 18:26:59 -0700 (MST) tony873004 <tony@gravitysimulator.com> wrote: > 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org