Closed imran514 closed 6 years ago
Wow that's some overkill.
You are using the Haversine formula, which computes the shortest distance between two points on a sphere. That's a great approximation for computing distances on Earth but unfortunately, in Carla we use a flat-earth model [*]. But no worries, math got you covered, we can just say our cities have an infinite radius and work out a simpler solution.
The Haversine formula can be expressed as
you can see how setting the radius to infinite wouldn't work, we can however use the opposite approach, lets assume the radius is some finite constant (say 1) but angles are extremely small compared to this radius. Under these assumptions we can use the small angle approximation for sinus and cosinus
applying this approximation to the original formula we get
multiplying by 4 and changing the variable names to x and y (to follow Carla convention), we get
that's a much simpler formula :stuck_out_tongue_winking_eye:
Now really, I'm kidding, in Carla you should use the Cartesian distance.
[*] We actually follow a Discworld model, we just don't simulate the 4 elephants and the turtle for performance reasons.
I am trying to calculate distance between vehicles using their transform locations using the below code
But i need the radius of the town to get the distance