dist()
Math / CalculationDescription
Calculates the distance between two points. Supports 2D and 3D.
Syntax
float dist(float x1, float y1, float x2, float y2)
float dist(float x1, float y1, float z1, float x2, float y2, float z2)
Parameters
| Name | Type | Description |
|---|---|---|
| x1/y1 | float | x,y of the first point |
| x2/y2 | float | x,y of the second point |
| z1/z2 | float | z-coordinates (optional, 3D) |
Returns
floatRelated
Under the Hood
From Processing.h:
float dist(const PVector& v) const { float dx=x-v.x,dy=y-v.y,dz=z-v.z; return std::sqrt(dx*dx+dy*dy+dz*dz); }
static float dist(const PVector& a, const PVector& b) { return a.dist(b); }
static float dist(const PVector& a, const PVector& b) { return a.dist(b);
inline float dist(A x1,B y1,C x2,D y2){ return dist((float)x1,(float)y1,(float)x2,(float)y2);
inline float dist(A x1,B y1,C z1,D x2,E y2,F z2){ return dist((float)x1,(float)y1,(float)z1,(float)x2,(float)y2,(float)z2);
static float dist(float x1,float y1,float x2,float y2)
{ float dx=x2-x1,dy=y2-y1; return std::sqrt(dx*dx+dy*dy); }
static float dist(float x1,float y1,float z1,float x2,float y2,float z2)
{ float dx=x2-x1,dy=y2-y1,dz=z2-z1; return std::sqrt(dx*dx+dy*dy+dz*dz); }