# CFLib.org – Common Function Library Project

## CoDistance(x1, y1, x2, y2)

##### Last updated July 17, 2001

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Calculates the distance between two sets of coordinates on the Cartesian coordinate system

Return Values:
Returns a simple value

Example:

``````<CFSET x1=1>
<CFSET y1=5>
<CFSET x2=1>
<CFSET y2=-5>
<CFOUTPUT>
Given:
<UL>
<LI>x1,y1 = (1,5)
<LI>x2,y2 = (1,-5)
</UL>
The distance between (#x1#,#y1#) and (#x2#,#y2#) = #CoDistance(x1,y1,x2,y2)#
</CFOUTPUT>
``````

Parameters:

Name Description Required
x1 x position of the first point Yes
y1 y position of the first point Yes
x2 x position of the second point Yes
y2 y position of the second point Yes

Full UDF Source:

``````/**
* Calculates the distance between two sets of coordinates.
*
* @param x1      x position of the first point
* @param y1      y position of the first point
* @param x2      x position of the second point
* @param y2      y position of the second point
* @return Returns a simple value
* @author Rob Brooks-Bilson (rbils@amkor.com)
* @version 1.0, July 17, 2001
*/
function CoDistance(x1,y1,x2,y2)
{
Return SQR(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
}
``````

### Search CFLib.org

QueryDeleteRows
November 04, 2017

May 11, 2016