Finding the angle from ( x, y )
I know this seems really easy, but I just can''t remember how.
If I have a point ( x, y ), how can a find the angle with respect to the origin point ( 0, 0 )?
Something like atan( y / x ) will work for most angles, but not all ( when x = 0 for example ).
I''m sure there''s a way to do this.
atan2(x,y)
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
a point doesn''t have an angle with another point. 2 points make a line
but i think you mean find the angle between the line (0,0 to x,y) with the x axis.
which is just a simple vector equation:
you need 2 vectors. one vector is x,y the other on the x axis lets choose 1,0
so you do:
invcos [ ((x,y) dot (1,0)) / ( |(x,y)| * |(1,0)| ) ]
definition of dot product:
http://www.geocities.com/SiliconValley/2151/math2d.html
basically:
(x,y) dot (1,0) = x * 1 + y * 0
and |(x,y)| is the magnitude of vector x,y which is:
sqrt(x^2 + y^2)
also try looking here:
http://www.geocities.com/SiliconValley/Horizon/6933/3d.html
they have a description as well further down the page (search for the text "find the angle between the normal and the light")
but i think you mean find the angle between the line (0,0 to x,y) with the x axis.
which is just a simple vector equation:
you need 2 vectors. one vector is x,y the other on the x axis lets choose 1,0
so you do:
invcos [ ((x,y) dot (1,0)) / ( |(x,y)| * |(1,0)| ) ]
definition of dot product:
http://www.geocities.com/SiliconValley/2151/math2d.html
basically:
(x,y) dot (1,0) = x * 1 + y * 0
and |(x,y)| is the magnitude of vector x,y which is:
sqrt(x^2 + y^2)
also try looking here:
http://www.geocities.com/SiliconValley/Horizon/6933/3d.html
they have a description as well further down the page (search for the text "find the angle between the normal and the light")
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement