# What does the 'sqrt' equation mean?

**URL:** <https://discourse.processing.org/t/what-does-the-sqrt-equation-mean/32875>\
**Category:** Beginners\
**Created:** [October 17, 2021, 1:41am UTC](https://discourse.processing.org/t/what-does-the-sqrt-equation-mean/32875 "2021-10-17T01:41:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![blopplop](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@blopplop](https://discourse.processing.org/u/blopplop)\
**Post date:** [October 17, 2021, 1:41am UTC](https://discourse.processing.org/t/what-does-the-sqrt-equation-mean/32875/1 "2021-10-17T01:41:45Z")

</div>

What does the sqrt equation mean?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 17, 2021, 6:21am UTC](https://discourse.processing.org/t/what-does-the-sqrt-equation-mean/32875/2 "2021-10-17T06:21:17Z")

</div>

Hi and welcome

This might explain how to us it

> [@Terrain Generation](https://discourse.processing.org/t/terrain-generation/28740):
>
> hi all how to make this shape if any one can help [1-norm] i found this equation : centerpoint (x1, y1) and a radius r, the height of the hill at the point (x2, y2) is equivalent to: [equation] how to use it to form this terrain can and how if i can using it in this code // Daniel Shiffman // http://codingtra.in // http://patreon.com/codingtrain // Code for: https://youtu.be/IKB1hWWedMk int cols, rows; int scl = 20; int w = 2000; int h = 1600; float flying = 0; float[][] terrain; voi…

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 17, 2021, 6:26am UTC](https://discourse.processing.org/t/what-does-the-sqrt-equation-mean/32875/3 "2021-10-17T06:26:37Z")

</div>

From the same link above

```auto
int cols, rows;
int scl =15;
int w = 2000;
int h = 1600;

float flying = 0;

float[][] terrain;
import peasy.PeasyCam;

PeasyCam cam;
void setup() {
  size(800, 800, P3D);
  cam = new PeasyCam(this, 400);
  cols = w / scl;
  rows = h/ scl;
  terrain = new float[cols][rows];
}

void draw() {

  flying -= 0.1;

  float yoff = flying;
  for (int y = 0; y < rows; y++) {
    float xoff = 0;
    for (int x = 0; x < cols; x++) {
 if (2222 - ((x- 53) * (x - 53) + (y- 53) * (y - 53)) > 0) {
   terrain[x][y] = sqrt(2222 - ((x- 53) * (x - 53) + (y- 53) * (y - 53)))*12;
   
      
      
} 
     // terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100);
      xoff += 0.2;
    }
    yoff += 0.2;
  }

  background(0,222,1);
 // stroke(2,5,255);
 stroke(5);
 strokeWeight(7);
  noFill();
scale(.2);
  translate(width/2, height/2+50);
  rotateX(PI/3);
  translate(-w/2, -h/2);
  for (int y = 0; y < rows-1; y++) {
    beginShape(TRIANGLE_STRIP);
    for (int x = 0; x < cols; x++) {
      vertex(x*scl, y*scl, terrain[x][y]);
      vertex(x*scl, (y+1)*scl, terrain[x][y+1]);
      //rect(x*scl, y*scl, scl, scl);
    }
    endShape();
  }
}

```

Eidt this code based on @jb4x help thanks for him

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [October 17, 2021, 8:58am UTC](https://discourse.processing.org/t/what-does-the-sqrt-equation-mean/32875/4 "2021-10-17T08:58:01Z")

</div>

Hi @blopplop,

`sqrt()` is a function that take the square root of a number. You will often find it to compute the distance between 2 points: it comes from the pythagoras theorem.

Go have a look at this link to get more insight: [Distance Between 2 Points](https://www.mathsisfun.com/algebra/distance-2-points.html)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 17, 2021, 10:33am UTC](https://discourse.processing.org/t/what-does-the-sqrt-equation-mean/32875/5 "2021-10-17T10:33:48Z")

</div>

also want to mention that there is a special processing dist() command for the distance between two points:

so:

```auto
float distMy = dist (rectX, rectY, quadX, quadY);

```

Also PVector (see reference [Reference / Processing.org](https://processing.org/reference/#math)) has a dist() function.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 17, 2021, 11:13am UTC](https://discourse.processing.org/t/what-does-the-sqrt-equation-mean/32875/6 "2021-10-17T11:13:47Z")

</div>

quote=“blopplop, post:1, topic:32875, full:true”]  
What does the sqrt equation mean?  
[/quote]

The `sqrt()` _function_:  
[https://processing.org/reference/sqrt\_.html](https://processing.org/reference/sqrt_.html)

It is used by the `dist()` _function_:  
[https://processing.org/reference/dist\_.html](https://processing.org/reference/dist_.html)  
The `sqrt()` function is used “behind the scenes” in the source code for Processing.

Advanced below… but good to know. It may come in handy one day.

If you take a look at source code for Processing you will find both the `sqrt()` and `dist()` functions here in PApplet.java

Direct link (takes a moment to open and go to line) to` dist()` function in PApplet.java:

> <https://github.com/processing/processing4/blob/master/core/src/processing/core/PApplet.java#L4763>

Note:  
You edited your original question and this changes the context of your question.

`:)`
