 # What does the 'sqrt' equation mean?

What does the sqrt equation mean?

Hi and welcome

This might explain how to us it

``````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

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

1 Like

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

so:

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

Also PVector (see reference Reference / Processing.org) has a dist() function.

1 Like

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

The `sqrt()` function:
https://processing.org/reference/sqrt_.html

It is used by the `dist()` function:
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:

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

`:)`