Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math formula

Status
Not open for further replies.

sakmrb

Programmer
Jun 27, 2005
1
0
0
CA
Is there a mathematical formula the you could punch in two co-ordinates and have it find the degrees from one point to another?

In other words, if you had two XY points (100,570) and (200,400) and you want to find out what degree (0 to 360) it was from one point to the other.

Any suggestions? I'm muddling through it, but there must be an easier way.

S.
 
It depends on what you mean by "degrees from one point to another". Let's say it is the angle between the horizontal line starting from point A and the line between point A and B. If the coordinate of point A is (x1, y1) and point B is (x2, y2), the angle (radian) is the arc tangent of (y2 - y1)/(x2 - x1). In Lingo it would be:
[tt]--
on findAngle x1, y1, x2, y2
x1 = float(x1)
return atan((y2 - y1)/(x2 - x1))*180/pi
end findAngle
--[/tt]
Let's try with your two points A(100, 570) and B(200, 400):
[tt]--
put findAngle(100, 570, 200, 400)
-- -59.5345
--[/tt]
So, your point B is angled about 60° below the point A.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top