# dist()

## Example

<figure><img src="https://768248463-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqbs7pgU3AVBY06Rl9M31%2Fuploads%2F6J770whEK4hCaec9f5bo%2Fdist()2d.gif?alt=media&#x26;token=0d281b5f-f272-4d11-b8c9-4d4ab748a2c7" alt=""><figcaption></figcaption></figure>

### Syntax

#### In two dimensions

```
dist(x1, y1, x2, y2)
```

<table><thead><tr><th width="94">Input</th><th>Description</th></tr></thead><tbody><tr><td>x1</td><td>the x-coordinate of the first point</td></tr><tr><td>y1</td><td>the y-coordinate of the first point</td></tr><tr><td>x2</td><td>the x-coordinate of the second point</td></tr><tr><td>y2</td><td>the y-coordinate of the second point</td></tr></tbody></table>

#### In three dimensions

```
dist(x1, y1, x2, y2, z1, z2)
```

<table><thead><tr><th width="110">Input</th><th>Description</th></tr></thead><tbody><tr><td>z1</td><td>the z-coordinate of the first point</td></tr><tr><td>z2</td><td>the z-coordinate of the second point</td></tr></tbody></table>

```python
    text(round(dist(x1, y1, x2, y2)), 50, 50)
```

```python
  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])
```

<figure><img src="https://768248463-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqbs7pgU3AVBY06Rl9M31%2Fuploads%2FRcm0OPjkS0IeCDk3IMwN%2Fdist()3d.gif?alt=media&#x26;token=62437e04-00de-437c-9c52-fad8c6a9650c" alt=""><figcaption></figcaption></figure>

### Description

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

{% hint style="info" %}
Find these documents helpful? Let the people who made them help your child learn to code at [**Strivemath**](https://www.strivemath.com/)<mark style="color:blue;">**!**</mark>

We'd love to hear your Feedback/Comments [here](https://docs.google.com/forms/d/e/1FAIpQLSeqorBAGTya-YBRI-VFjJxtgQtCz3ucGDI96K96sNyuaGuvdw/viewform?usp=sf_link).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnpython.strivemath.com/p5-python-web/reference/math/dist.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
