Distance From Point A To Point B //JavaScript Repository

Description

Distance from the point A to point B.
Created: 2005.08.20

Code (Download)

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/math/line-length [rev. #1]

lineLength = function(x, y, x0, y0){
    return Math.sqrt((x -= x0) * x + (y -= y0) * y);
};

Example (Example)

<script type="text/javascript">
//<![CDATA[

alert(lineLength(0, 0, 10, 10));

//]]>
</script>

Help

lineLength(x0: Integer, y0: Integer, x1: Integer, y1: Integer): Double
Returns the distance from a point A to a point B.
x0
x coord of the line's A point
y0
y coord of the line's A point
x1
x coord of the line's B point
y1
y coord of the line's B point

Rank (Votes: 55)

3.65