Posted By

ricosushi on 07/14/10


Tagged

distance Vector


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ricosushi


Get vector distance


 / Published in: ActionScript
 

Returns the distance from 2 points.

  1. // getDistance between two points
  2. function getDistance(x1:Number, x2:Number, y1:Number, y2:Number):Number{
  3. var difX:Number = x2-x1;
  4. var difY:Number = y2-y1;
  5. //
  6. var doubleX:Number = Math.pow(difX, 2);
  7. var doubleY:Number = Math.pow(difY, 2);
  8. //
  9. return Math.sqrt(doubleX * doubleX + doubleY * doubleY);
  10. }
  11.  
  12. // Usage
  13. getDistance(0, 0, 100, 100);

Report this snippet  

You need to login to post a comment.