Original Post
🔒 Locked
Direction(digrees) between two points
Advertisement
Create a right angled triangle with the points as either end of the hypotenuse, then use trigonomitry functions to calculate the angles from whichever end you like.
I would give a proper description but I can't remember right now which function is which, so rather than risk getting it wrong and making it worse, I'll leave it as that. Basically you're gonna need to use atan, asin or acos after doing some division of the height and width of the triangle. Like I said, dont remember which.
I can answer properly tommorow if you need, but I'm sure someone else will have provided an answer by then.
"Because there'll be no safety in numbers,
When the right one walks out of the door"
[edited by - allsorts46 on March 21, 2003 6:04:07 PM]
I would give a proper description but I can't remember right now which function is which, so rather than risk getting it wrong and making it worse, I'll leave it as that. Basically you're gonna need to use atan, asin or acos after doing some division of the height and width of the triangle. Like I said, dont remember which.
I can answer properly tommorow if you need, but I'm sure someone else will have provided an answer by then.
"Because there'll be no safety in numbers,
When the right one walks out of the door"
[edited by - allsorts46 on March 21, 2003 6:04:07 PM]
two points: A(ax, ay) & B(bx, by)
the angle between AB and the x axis is:
angle = asin((by-ay) / L)
angle = acos((bx-ax) / L)
angle = atan((by-ay) / (bx-ax))
where L = ((by-ay)^2 + (bx-ax)^2)^(1/2)
BEWARE: the angle you''ll get will range from -90° to 90°, -pi/2 to pi/2. Meaning that you point could on the "opposite part of the circle". Therefore, a position check is necessary if you desire an angle between 0 and 360.
the angle between AB and the x axis is:
angle = asin((by-ay) / L)
angle = acos((bx-ax) / L)
angle = atan((by-ay) / (bx-ax))
where L = ((by-ay)^2 + (bx-ax)^2)^(1/2)
BEWARE: the angle you''ll get will range from -90° to 90°, -pi/2 to pi/2. Meaning that you point could on the "opposite part of the circle". Therefore, a position check is necessary if you desire an angle between 0 and 360.
U(x, y, z) = U(3, 4, 6) //arbitrary
V(x, y, z) = V(6, 8, 1) //U & V are the 2 vectors starting at the origin.
Dot Product:
U.V = U(x)*V(x) + U(y)*V(y) + U(z)*V(z)//the dot product is the distance between the origin and the projection of a vector 90 degrees to another vector. If a leg of a right triange and the hypotenuse were the two vectors, then the length of the leg would be the dot product of the two.
Dot Product in Relation to Angles:
U.V = |U| * |V| * cos(angle_between_UandV)
Doing some basic algebra yields:
cos(angle) = |U|*|V|/U.V
******cos-1(|U|*|V|/U.V) = angle ********
Magnitude:
|U| = magnitude or "distance" of vector U.
|U| = sqrt(U(x)2 + U(y)2 + U(z)2)
...basically just pythagorean theorem in 3 dimensions.
A and B are legs of a right triangle, and C is the hypotenuse.
A2 + B2 = C2
So C equals the square root of {A squared plus B squared}.
[edited by - 63616c68h on March 21, 2003 6:23:37 PM]
V(x, y, z) = V(6, 8, 1) //U & V are the 2 vectors starting at the origin.
Dot Product:
U.V = U(x)*V(x) + U(y)*V(y) + U(z)*V(z)//the dot product is the distance between the origin and the projection of a vector 90 degrees to another vector. If a leg of a right triange and the hypotenuse were the two vectors, then the length of the leg would be the dot product of the two.
Dot Product in Relation to Angles:
U.V = |U| * |V| * cos(angle_between_UandV)
Doing some basic algebra yields:
cos(angle) = |U|*|V|/U.V
******cos-1(|U|*|V|/U.V) = angle ********
Magnitude:
|U| = magnitude or "distance" of vector U.
|U| = sqrt(U(x)2 + U(y)2 + U(z)2)
...basically just pythagorean theorem in 3 dimensions.
A and B are legs of a right triangle, and C is the hypotenuse.
A2 + B2 = C2
So C equals the square root of {A squared plus B squared}.
[edited by - 63616c68h on March 21, 2003 6:23:37 PM]
If it''s not clear, you should try a google search for "angle between vectors" or "dot product".
Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement