Thread Tools Display Modes
Prev Previous Post   Next Post Next
11-12-11, 08:58 AM   #1
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Distance formula to calculate speed between two points

I've spotted the InFlight thread about posting distance results of flights, so I wrote a script that parses the DBC data to extract this information, but I am stuck making this function properly:

Code:
// get delay between two points on a map and the movement speed modifier
function getDelay($from, $to, $speed) {
  $time = 0;
  if(is_array($from) && is_array($to)) {
    $m1 = $from['mapId']; $x1 = $from['x']; $y1 = $from['y']; $z1 = $from['z'];
    $m2 = $to['mapId'];   $x2 = $to['x'];   $y2 = $to['y'];   $z2 = $to['z'];
    $dx = abs($x1 - $x2); // TODO: are these correctly calculated?
    $dy = abs($y1 - $y2); // TODO: are these correctly calculated?
    $R = 1000; // NYI: mean radius of world (mapId)
    $a = pow(sin($dx/2), 2) + cos($x1)*cos($x2)*pow(sin($dy/2), 2);
    $c = 2*atan2(sqrt($a), sqrt(1-$a));
    $d = $R * $c;
    $S = 10; // NYI: speed constant that will be modified by $speed (%)
    $time = $d/($S*$speed);
  }
  return $time;
}
Basically, I have to calculate the distance between the two points (mapId1,x1,y1,z1) and (mapId2,x2,y2,z2) and I have the speed modifier here (100%, 150%, e.g.) but my speed constant and the radius of the mapId will be a challenge, anyone got any help on this matter?

If I get this to work sure I'll post source and best of all no flight addon will have to calculate on the fly, the time it will take to fly the path! One can in advance of a patch calculate the data from the DBC themselves and produce a LUA database with all the exact timers, cool right?
  Reply With Quote
 

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Distance formula to calculate speed between two points

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off