We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
p5.js dist() Function
The dist() function calculates the Euclidean distance in 2D or 3D. Means the p5.js | dist() Function is used to measure the distance between two points in 2D or 3D. Below is the formula for distance in 2D and 3D.
2D formula:
3D formula:
Syntax:
dist(x1, y1, x2, y2)
dist(x1, y1, z1, x2, y2, z2)
Parameters:
x1: These parameters holds the x-coordinate of the first point.
y1: These parameters hold the y-coordinate of the first point.
z1: These parameters hold the z-coordinate of the first point.
x2: These parameters hold the x-coordinate of the second point.
y2: These parameters hold the y-coordinate of the second point.
z2: These parameters hold the z-coordinate of the second point.
Return value: Distance between two points.
Example: This example calculates and prints the distance between a fixed point and the cursor.