Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Angle between two points
#11
Vector math works best though.

|a + b| = |a||b|cos(alpha)

Now to split this into cartesian components after this:

alpha = ArcCos(|a + b| / |a||b|)


:

alpha = ArcCos(Sqr((a.x + b.x) * (a.x + b.x) + (a.y + b.y) * (a.y + b.y)) / Sqr(a.x * a.x + a.y * a.y) / Sqr(b.x * b.x + b.y * b.y))

Make sure there's no division by zero.
Reply
#12
Quote:Huh? Those brackets shouldn't be needed...
Well, try it. Tongue

Oh, and to solve the acute angle problem,
Code:
if degrees < 0 then degrees = degrees + 360

(which, looking at some other people's replies, is the same as Dr Davs. Thanks DrD Smile)

Quote:Just a note about adding 90... in trigonometry, or any math/science zero degrees always points east. It's only on your compass that it will ever point north, for obvious reasons Smile
Oh right! I never knew that, but it always annoyed me how my calculations always resulted in 0 degrees being east, and north being 270. Thanks

Quote:there are math teachers somewhere crying.
Oh yes. Maths teachers usualy cry when I go near them. Im getting ready to get a C in AH Maths this year Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)