Created
March 3, 2012 12:22
-
-
Save fguillen/1965850 to your computer and use it in GitHub Desktop.
Calculation of the coordinates or a point in the middle of two points
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function distancePoints( xA, yA, xB, yB ){ | |
var xDistance = Math.abs( xA - xB ); | |
var yDistance = Math.abs( yA - yB ); | |
return Math.sqrt( Math.pow( xDistance, 2 ) + Math.pow( yDistance, 2 ) ); | |
} | |
function coordinatesMediumPoint( xA, yA, xB, yB, distanceAC ){ | |
var distanceAB = distancePoints( xA, yA, xB, yB ); | |
var angleAB = Math.atan2( ( yB - yA ), ( xB - xA ) ); | |
var deltaXAC = distanceAC * Math.cos( angleAB ); | |
var deltaYAC = distanceAC * Math.sin( angleAB ); | |
var xC = xA + deltaXAC; | |
var yC = yA + deltaYAC; | |
return { x: xC, y: yC }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello can you tell me what unit of measurement is the distance