[][src]Static p5_sys::global::dist

pub static dist: DistInternalType

Calculates the distance between two points, in either two or three dimensions.

Examples

// Move your mouse inside the canvas to see the
// change in distance between two points!
function draw() {
  background(200);
  fill(0);

  let x1 = 10;
  let y1 = 90;
  let x2 = mouseX;
  let y2 = mouseY;

  line(x1, y1, x2, y2);
  ellipse(x1, y1, 7, 7);
  ellipse(x2, y2, 7, 7);

  // d is the length of the line
  // the distance from point 1 to point 2.
  let d = int(dist(x1, y1, x2, y2));

  // Let's write d along the line we are drawing!
  push();
  translate((x1 + x2) / 2, (y1 + y2) / 2);
  rotate(atan2(y2 - y1, x2 - x1));
  text(nfc(d, 1), 0, -5);
  pop();
  // Fancy!
}

Overloads

x1 x-coordinate of the first point

y1 y-coordinate of the first point

x2 x-coordinate of the second point

y2 y-coordinate of the second point


x1 x-coordinate of the first point

y1 y-coordinate of the first point

z1 z-coordinate of the first point

x2 x-coordinate of the second point

y2 y-coordinate of the second point

z2 z-coordinate of the second point