I am trying to find the formula for this.... maybe I am phrasing wrong.
E.g. starting at Moscow, calculate what compass-bearing would you need to travel to eventually reach Paris?
Bonus points if the solution is already in LUA.
Determine Vector between 2 coordinates
Moderator: Defcon moderators
- roflamingo
- level3
- Posts: 404
- Joined: Fri Jan 19, 2007 10:25 am
Code: Select all
function Bearing(x1, y1, x2, y2)
local dx = x2 - x1
local dy = y2 - y1
return math.atan2(dx, dy)
end
Results in radians, not degrees
The above post is not intended as an attack on you. It's not about making you look stupid for not searching. It merely states the facts. Please don't be offended.
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
Ace Rimmer wrote:What happened to math.deg?
Since all the trig functions work with radians it's best to stick to them. Only use math.deg for outputting results. That way you don't waste CPU converting types needlessly, less code, and you don't risk accidentally forgetting to convert back.
Last edited by DinoSteve on Tue Feb 23, 2010 3:01 am, edited 1 time in total.
The above post is not intended as an attack on you. It's not about making you look stupid for not searching. It merely states the facts. Please don't be offended.
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
Who is online
Users browsing this forum: No registered users and 10 guests