dist()
Calculates the distance between two points.
Examples

function setup()
size(100, 100)
background(200)
-- Set the coordinates.
local x1 = 10
local y1 = 50
local x2 = 90
local y2 = 50
-- Draw the points and a line connecting them.
line(x1, y1, x2, y2)
strokeWeight(5)
point(x1, y1)
point(x2, y2)
-- Calculate the distance.
local d = dist(x1, y1, x2, y2)
-- Style the text.
textAlign(CENTER)
textSize(16)
-- Display the distance.
text(d, 43, 40)
describe('Two dots connected by a horizontal line. The number 80 is written above the center of the line.')
end
Syntax
dist(x1, y1, x2, y2)
Parameters
| Parameter | |
|---|---|
| x1 | Number: x-coordinate of the first point. |
| y1 | Number: y-coordinate of the first point. |
| x2 | Number: x-coordinate of the second point. |
| y2 | Number: y-coordinate of the second point. |
Returns
Number: distance between the two points.