Advertisement

how do u get the angle of a vector?

Started by November 29, 2002 07:23 AM
6 comments, last by pag 22 years, 2 months ago
Im wondering how the get the angle of a vector, with my calculator i simply press the inverse button, but i havent found an equal function in c++... Anyone knows the algorithm or some other way to figure this out?
I am a signature virus. Please add me to your signature so that I may multiply.
the angle of a vector with respect to what ? there is no such thing as "an angle of a vector"
Advertisement
eh well, from the origin(0.0, 0.0, 0.0)...

ex. if the vector is (1.0, 1.0, 0.0)
how do i get the angle between the origin and the vector?
I am a signature virus. Please add me to your signature so that I may multiply.
Angles are defined between lines, so you can''t have an angle betwixt a vector and the origin.

For the angle between two vectors, use dot products,

a.b = (length a)(length b) cos (shortest angle betwixt a and b)

where the cosine is in radians.

The angle your calculator gives is probably the anticlockwise angle from the x-axis to the vector.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Have a look at:

http://www.flipcode.com/geometry/

There is a decent introduction to Vector math including the dot product
eh now im totally lost...
I mean vectors work pretty much the same way as triangles, and you can calculate the angle of a triangle...
imagine this:>

     /|  v / |   /  |  /   | b /____|   a      

The "v" is the vector, the length of this vector is the hypotenuse of the triangle. and u know what, what acctually is calculated when u calculate the vectors magnitude is the hyptonuse of a triangle...

So we know one side is 90 degrees, so let's calculate the other:>

hypotenuse = 1.0^2 + 1.0^2 + 0.0 == 2.0

sin(30) = 1.0/hypotenuse == 0.5

angle = inv(sin(0.5)) == 30 degrees

so now we know that the angle between the "b" side and the hypotenuse is 30 degrees, and that makes it easy to figure out what the angle I really want is, simply:>

90+30 = 120 = 180-120 == 60 degrees

the 180 is the total sum a triangle can have... So we got 60 degrees hurray, so u see we can get an angle of a vector, or at least I triangle that has an hypotenuse that is the vector, heh, ah well...


Anyway what i want to know is how to calculate this, so you can
skip the above and just tell me how to calculate this, and ill try it out, if it doesnt work, then congrats you were right...

angle = inv(sin(0.5)) in c++...


if what i said above doesnt work, i got some huge rethinking to do...


[edited by - pag on November 29, 2002 10:00:05 AM]

[edited by - pag on November 29, 2002 10:03:54 AM]
I am a signature virus. Please add me to your signature so that I may multiply.
Advertisement
The inverse of sin (aka arcsin) can be calculated using asin() or asinf() in C/C++ (include math.h)
Define the "origin" (the radius of the unit sphere when theta == phi == 0) to be <1, 0, 0>. The inverse cosine of the dot-product between this and your vector is the angle between them. I think.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links


[edited by - zealouselixir on November 29, 2002 10:06:57 AM]

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement