finding angle from a coordinate

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

finding angle from a coordinate

tony873004
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!
Reply | Threaded
Open this post in threaded view
|

Re: finding angle from a coordinate

Felipe Sanches
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
Reply | Threaded
Open this post in threaded view
|

Re: finding angle from a coordinate

Ronaldo
In reply to this post by tony873004
You may try this solution:
Drawing lines...


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
Reply | Threaded
Open this post in threaded view
|

Re: finding angle from a coordinate

donbright
In reply to this post by tony873004
Here is my attempt

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

It is somewhat certain to work in all 8 octants

--
  don bright
  [hidden email]

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
> [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
Reply | Threaded
Open this post in threaded view
|

Re: finding angle from a coordinate

Ronaldo
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);
Reply | Threaded
Open this post in threaded view
|

Re: finding angle from a coordinate

tony873004
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.
Reply | Threaded
Open this post in threaded view
|

Re: finding angle from a coordinate

tony873004
In reply to this post by Ronaldo
The rotation rule from the manual was exactly what I was looking for. Worked in all 8 octants. Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: finding angle from a coordinate

ottojas
In reply to this post by tony873004
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 <[hidden email]> 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
> [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