Advertisement

Angle Between Two 2D Points.

Started by July 22, 2003 09:06 PM
14 comments, last by Programmer Four 21 years, 7 months ago
I think this about the third time I''ve posted this question, but here goes... How do I find the angle between two 2D points?
You''re gonna have to clarify that question a bit. Two independent 2d points don''t exactly have an angle between them, you''d have to specify a 3rd point to compare against.

Jonathan
Advertisement
I think he means..the angle of the vector between two points mapped against a standard XY plain.

eg point (1,1) point (4,4) is a vector of (3,3) which is a 45 degree slope. But hey..its all open to interpretation.

Andrew
Programmer of Screech for INSANE SOFTWARE
Maybe the two points located on the surface of a circle or sphere, or perhaps you want the angle between vectors from the origin to the points?
hmmmmmmmm...i thought it was pretty clear lol. damn, im confused now.
quote:
I think he means..the angle of the vector between two points mapped against a standard XY plain.

heh this is what i mean
Well if that''s the question, the answer should be pretty easy. If you mean the angle that I think you mean, it is atan(delta-y / delta-x). You can work around cases where delta-x is 0.

Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,
fasting, good works and so on. Up until Doom, no one seemed to have thought about the
double-barrel shotgun. Eat leaden death, demon...
-- Terry Pratchett
Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,fasting, good works and so on. Up until Doom, no one seemed to have thought about thedouble-barrel shotgun. Eat leaden death, demon... -- Terry Pratchett
Advertisement
thx m8 - what''s the delta? (im a maths n00b )
The delta looks like an triangle. It represent''s an angle. Also used is theta. This stuff is taught in geometry ya know.

Power User / Programmer / Game Player ( Not computer nerd
Power User / Programmer / Game Player ( Not computer nerd :)
Δ = "Delta" usually means change in (eg. ΔT = change in T).

The most commonly used symbols for angles are θ = "Theta" or φ = "phi". All three are letters of the greek alphabet.

Kentaro's angle calculation is typically used to find the angle of a triangle based on the opposite and adjacent side lengths when the triangle is configured as so:
      A     /|    / |       /  |    /   | Δy /    | /θ____B   Δx 

Note the locations of θ and the two points A and B that I think Kentaro was referring to. Δy is the vertical distance between the points, and Δx is the horizontal distance from the origin to the poitns. Note that one of the points, B has to be on the x-axis, and the other point, A has to be directly "above" B.

Another possibility is the angle between vectors from the origin to the points (I referred to this before).
  y-axis  |    A  |   /  |  /  | /a  |/--O----- x-axis  |\   | \b    |  \    |   B   

The two vectors would be from the origin O to the two points A and B respectively. The vectors' endpoints can be located anywhere on the plane. The angle between the vectors can be determined using the dot-product of the vectors. Calling the vector from O to A "a" and from O to B "b" (as labelled):

a.b = |a||b|cos(θ

where . means the dot product
|a| is the magnitude of the vector a (same for |b| and b)
and θ is the (smallest) angle between the vectors (not labelled on diagram)

[edited by - Geoff the Medio on July 23, 2003 2:06:46 AM]
This is how I would do it:

vDif = v2 - v1; //get the difference between the vectors
fAngle = atan2( vDif.y, vDif.x );

atan2 handles divide by 0''s and increases the range to (-PI, PI)

This topic is closed to new replies.

Advertisement