# The dist() function creates unexpected values

**URL:** <https://discourse.processing.org/t/the-dist-function-creates-unexpected-values/40577>\
**Category:** Coding Questions\
**Created:** [January 13, 2023, 9:45pm UTC](https://discourse.processing.org/t/the-dist-function-creates-unexpected-values/40577 "2023-01-13T21:45:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jamone/32/17811_2.png) [@JamOne](https://discourse.processing.org/u/JamOne)\
**Post date:** [January 13, 2023, 9:45pm UTC](https://discourse.processing.org/t/the-dist-function-creates-unexpected-values/40577/1 "2023-01-13T21:45:47Z")

</div>

Hello, I struggle with this code. I even tried to talk to the ChatGBT but didn’t help.

For some reason, “dist” creates big dips in its values and therefore bigger ellipses on the path where they should not be. See image.  
How can I get rid of the big circles and just have the smooth line?  
Can somebody help? Thank you.  
 ![Bildschirmfoto 2023-01-13 um 22.40.27](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/0/0/00219742bc0d3d6aad96c4da52f2fa1823fb5ef4.png)

```auto
import processing.pdf.*;
import java.util.*;

PVector loc;
PVector old;

float angle, noiseZ, radiusN;

float radius = 100;
float ellipseSize;

float oldX, oldY, oldDist;
float alpha, size;

      float maxDist;
      
void setup() {
  size(800, 800);
  pixelDensity(displayDensity());
  noiseSeed(145000);
  noiseDetail(1, 0.9);

  background(255);
  smooth(10);

  loc = new PVector(width/2, height/2);
  old = new PVector(0, 0);
  
maxDist = 1;
noiseZ = 0.0;
}

void draw() {

  noStroke();

  translate(width/2, height/2);

    radiusN = radius + (1.0-sqrt(noise(noiseZ))) * 340; // SUPER
    
    float n = map(noise(noiseZ/2), 0. , 1.0 , -PI, PI);
    loc.x = cos(angle + n) * radiusN;
    loc.y = sin(angle + n) * radiusN;

 float dist = loc.dist(old);
  old = loc.copy();
    
 
    if (frameCount > 6) {
        
     fill(dist*50,0,0.0, map(dist, 0., 4, 5, 30));

     ellipseSize = map(dist, 0.0, 4., 50., 5.);
     
     ellipse(loc.x, loc.y, ellipseSize, ellipseSize);
 
  }
  angle += 0.005 ;
  noiseZ += 0.01;

 }

```

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [January 15, 2023, 7:55am UTC](https://discourse.processing.org/t/the-dist-function-creates-unexpected-values/40577/2 "2023-01-15T07:55:40Z")

</div>

Hi @JamOne,

Guess everything is ok with dist function.  
Maybe you should check the doc about

> **[map() / Reference](https://processing.org/reference/map_.html)**
>
> Re-maps a number from one range to another. In the first example above, the number 25 is converted from a value in the range of 0 to 100 into a value that ranges from the left edge of the…

Always it would be an idea to trace your values by ie. println to the console and check if they are as expected.

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![JamOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jamone/32/17811_2.png) [@JamOne](https://discourse.processing.org/u/JamOne)\
**Post date:** [January 15, 2023, 7:43pm UTC](https://discourse.processing.org/t/the-dist-function-creates-unexpected-values/40577/3 "2023-01-15T19:43:04Z")

</div>

Hey mnse,  
thank you very much. I did trace the values with println(), that’s how I found the dist dips.  
The map() function works excactly like it should be.

So maybe, there is a different way to implement noise() or another more elaborated noise() library somebody could recomend?
