P5 Python Docs
  • Getting Started
  • Simple mode
  • Reference
    • Shapes
      • 2D
        • point()
        • line()
        • rect()
        • square()
        • triangle()
        • circle()
        • ellipse()
        • arc()
        • quad()
        • beginShape()
      • 3D
        • plane()
        • box()
        • sphere()
        • cone()
        • cylinder()
        • ellipsoid()
        • torus()
    • Controlling the environment
      • coordinateMode()
      • rectMode()
      • ellipseMode()
      • frameRate()
      • setup()
      • draw()
    • Built-in Variables
      • Environment
      • Keyboard
      • Mouse
    • Built-in Functions
      • keyIsDown()
      • millis()
      • second()
      • minute()
      • hour()
      • translate()
      • rotate()
      • createSlider()
      • createGraphics()
      • createVector()
    • Events
      • Keyboard
        • keyPressed()
        • keyReleased()
      • Mouse
        • mouseMoved()
        • mouseDragged()
        • mousePressed()
        • doubleClicked()
        • mouseWheel()
    • Text
      • text()
      • textSize()
      • textAlign()
    • Math
      • drawTickAxes()
      • random()
      • randomGaussian()
      • dist()
      • linmap()
      • bounce()
      • wave()
    • Colour and Outline
      • colorMode()
      • fill()
      • stroke()
      • strokeWeight()
      • background()
    • Images & Audio
      • loadImage() and image()
      • loadSound()
    • 3D Controls
      • orbitControl()
      • translate()
      • rotateZ()
      • rotateX()
      • rotateY()
      • scale()
Powered by GitBook
On this page
  • Example
  • Syntax
  • Description
  1. Reference
  2. Math

dist()

Calculate the distance between 2 points

PreviousrandomGaussian()Nextlinmap()

Last updated 2 years ago

Example

Syntax

In two dimensions

dist(x1, y1, x2, y2)
Input
Description

x1

the x-coordinate of the first point

y1

the y-coordinate of the first point

x2

the x-coordinate of the second point

y2

the y-coordinate of the second point

In three dimensions

dist(x1, y1, x2, y2, z1, z2)
Input
Description

z1

the z-coordinate of the first point

z2

the z-coordinate of the second point

    text(round(dist(x1, y1, x2, y2)), 50, 50)
  sphere(dist(0, 0, 0, x, y, z))
  
  x+=3*noise(2*frameCount)*random([-1, 1])
  y+=4*noise(frameCount)*random([im-1, 1])
  z+=noise(0.5*frameCount)*random([-1, 1])

Description

Calculates the distance between two points, in either two or three dimensions. This uses the Euclidean distance, usually called the Pythagorean distance

Find these documents helpful? Let the people who made them help your child learn to code at !

We'd love to hear your Feedback/Comments .

Strivemath
here