Click to See Complete Forum and Search --> : 2d angles... 0 to 360 given two points.


messin18
January 2nd, 2007, 06:08 PM
I have two 3d points in space.

Vector 1, Vector 2

Looking overhead and assumeing vector 1 is the center and vector 2 is some point rotated around vector 1 i need to find that angle from 0 to 360 degrees. Useing the length from vector 1 to vector 2 as the radius of the circle. Basically it boils down to 2d math because i eliminate y and just use x and z from my vector.

I can't figure out how to do this..

I tried useing: angle = opposite / adjacent * tan -1

And i was calculateing it like:

opposite = vector2.z - vector1.z
adjacent = vector2.x = vector1.x

This wont' give me the angle from 0 to 360 around a circle... so how do i do it? I'm assumeing it'll have something to do with a forumla useing Arc Length of a Circle... but i can't quite figure it out.

messin18
January 3rd, 2007, 02:02 PM
anyone?

Zachm
January 3rd, 2007, 02:52 PM
Ok, so you've got a vector rotating around a point with the Y axis as pivot.
You must have a reference dimension to check the vector angle relative to it,
or in other words, you must decide which direction does the 0 degrees angle points toward.
You can check the angle relative to the X axis this way:

1) angle = arctan(vector.z / vector.x) * 180/PI
This angle is in radians. To convert to degrees, multiply angle by 180/PI.

2) if vector.x < 0, then add 180 to angle (since arctan is in the range [-90,90] degrees).

3) if you don't want negative degrees, add 360 to the angle if it's negative.

That's it, good luck !

messin18
January 3rd, 2007, 05:14 PM
Cool easy enough thanks.