# Curve - control points settings for gauss curve behavior

**URL:** https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911
**Category:** Coding Questions
**Created:** [February 18, 2021, 4:20pm UTC](https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911 "2021-02-18T16:20:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![xbix](https://avatars.discourse-cdn.com/v4/letter/x/ec9cab/32.png) [@xbix](https://discourse.processing.org/u/xbix)
#### Post date: [February 18, 2021, 4:20pm UTC](https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911/1 "2021-02-18T16:20:01Z")

</div>

I am just trying to understand the control points from a curve. The curve should behave like a Gaussian curve.

![gaussian](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d1c24c65e4eddab7bac1c449b39bef472f281002.jpeg)

Unfortunately, I don’t really understand how to handle the control points.  
Can someone please help me?

My current sketch for testing:

```auto
int []points = new int[12];

void setup() {
  size(800, 800);
  strokeWeight(2);
  for (int i =0; i<12; i++)
    points[i] = int(random(400));
}

void draw() {
  background(220);
  translate(width/4, height/4);
  float xDist = 30;
  for (int i =0; i<11; i++) {
    // xy position
    float x = i*xDist;
    float x2 = (i+1)*xDist;
    float y = points[i];
    float y2 = points[i+1];
    
    //control points
    float cp1, cp2, cp3, cp4;
    cp1 = x;
    cp2 = y;
    cp3 = x2;
    cp4 = y2;
    
    noFill();
    curve(cp1, cp2, x, y, x2, y2, cp3, cp4);
    fill(255);
    circle(x, y, 10);
  }
}

```

Thanks in advance!

---

<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: [February 18, 2021, 8:15pm UTC](https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911/2 "2021-02-18T20:15:38Z")

</div>

I think you can just draw simple curve.

For complex curve you can connect several curves: [curve() \ Language (API) \ Processing 3+](https://www.processing.org/reference/curve_.html)

or you look at curveVertex, see [Language Reference (API) \ Processing 3+](https://www.processing.org/reference/)

```auto

int []points = new int[12];

void setup() {
  size(1800, 800);
  strokeWeight(2);
  for (int i =0; i<12; i++)
    points[i] = int(random(400));
}

void draw() {
  background(220);
  translate(width/4, height/4);
  float xDist = 30;
  // for (int i =0; i<11; i++) {
  // xy position
  int i=10;

  float x = 300;
  float y = 100;

  float x2 = 500;
  float y2 = 100;

  //control points
  float cp1, cp2, cp3, cp4;
  cp1 = x-200;
  cp2 = y+400;

  cp3 = x2+200;
  cp4 = y2+400;

  noFill();
  curve(cp1, cp2, x, y, x2, y2, cp3, cp4);
  fill(255, 2, 2);
  ellipse(x, y, 10, 10);
  ellipse(x2, y2, 10, 10);

  fill(255, 2, 222);
  ellipse(cp1, cp2, 10, 10);
  ellipse(cp3, cp4, 10, 10);
  // }
  noLoop();
}

```

---

<div class="post-metadata">

### Author: ![xbix](https://avatars.discourse-cdn.com/v4/letter/x/ec9cab/32.png) [@xbix](https://discourse.processing.org/u/xbix)
#### Post date: [February 18, 2021, 9:18pm UTC](https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911/3 "2021-02-18T21:18:18Z")

</div>

Thank you very much.

But I want to connect several curves and always map the exponential gaus curve between the curves.

My question could also be expressed differently:

how can I calculate the control points to get an up and down movement between the points, what would be the right math?

---

<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: [February 19, 2021, 10:45am UTC](https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911/4 "2021-02-19T10:45:33Z")

</div>

> [@xbix](#):
>
> exponential gaus curve

You mean Gauss or Gaussian function, with two s

> **[Gaussian function](https://en.wikipedia.org/wiki/Gaussian_function)**
>
> In mathematics, a Gaussian function, often simply referred to as a Gaussian, is a function of the base form
> Gaussian functions are often used to represent the probability density function of a normally distributed random variable with expected value μ = b and variance σ2 = c2. In this case, the Gaussian is of the form
> Gaussian functions are widely used in statistics to describe the normal distributions, in signal processing to define Gaussian filters, in image processing where two-dimensional ...

> [@xbix](#):
>
> how can I calculate the control points to get an up and down movement between the points,

You would have to connect approx. 4 curves with different control points.

Seems complicate. As I said consider curveVertex.

What is your goal with the curve or is that the entire project?

Because when you want to work with the points you can just make a graph of points.

---

<div class="post-metadata">

### Author: ![xbix](https://avatars.discourse-cdn.com/v4/letter/x/ec9cab/32.png) [@xbix](https://discourse.processing.org/u/xbix)
#### Post date: [February 19, 2021, 11:10am UTC](https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911/5 "2021-02-19T11:10:12Z")

</div>

I mean a Gaussian function.

I have looked at curvevertex, but have not really understood how to calculate the guide points correctly either.

My goal is to make my data chart more visually pleasing by representing exponential movements in the curves rather than linear connections.

Thanks again for your time!

---

<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: [February 19, 2021, 12:47pm UTC](https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911/6 "2021-02-19T12:47:49Z")

</div>

I don’t know if this helps you.

here you can drag the points.

- Drag with mouse, pos is shown. Println with key s

```auto

PVector[] points = new PVector[4];
boolean hold=false; 
int pvCurrent=-1; 

void setup() {
  size(1800, 800);
  strokeWeight(2);
  for (int i =0; i<points.length; i++) {
    points[i] = new PVector(0, 0);
  }

  float xDist = 30;
  // for (int i =0; i<11; i++) {
  // xy position
  int i=10;

  float x = 300;
  float y = 100;

  float x2 = 500;
  float y2 = 100;

  //control points
  float cp1, cp2, cp3, cp4;
  cp1 = x-200;
  cp2 = y+400;

  cp3 = x2+200;
  cp4 = y2+400;

  points[0].set(x, y); 
  points[1].set(x2, y2); 
  points[2].set(cp1, cp2); 
  points[3].set(cp3, cp4);
}//func 

void draw() {
  background(220);
  //translate(width/4, height/4);

  fill(0);
  text("Drag with mouse, pos is shown. Println with key s", 15, 15); 

  noFill();
  curve(
    points[2].x, points[2].y, 
    points[0].x, points[0].y, 
    points[1].x, points[1].y, 
    points[3].x, points[3].y);

  fill(255, 2, 2);
  ellipse(points[0].x, points[0].y, 10, 10);
  ellipse(points[1].x, points[1].y, 10, 10);

  fill(255, 2, 222);
  ellipse(points[2].x, points[2].y, 10, 10);
  ellipse(points[3].x, points[3].y, 10, 10);
  // }

  if (hold) {
    if (pvCurrent>-1)
      points[pvCurrent].set(mouseX, mouseY);

    fill(0);
    text(mouseX+","+mouseY, 400, 400);
  }//if
}//func 

void mousePressed() {
  hold=true; 
  for (int i = 0; i<points.length; i++) {
    if (dist(points[i].x, points[i].y, mouseX, mouseY ) < 63) {
      pvCurrent = i;
      return;//leave
    }
  }//for
}

void mouseReleased() {
  hold=false;
}

void keyPressed() {
  if (key=='s') {
    println("---------------------------");
    for (int i = 0; i<points.length; i++) {
      println( "points["+i+"].set("+ points[i].x+", "+ points[i].y + ");");
    }
  }
}
//

```

---

<div class="post-metadata">

### Author: ![xbix](https://avatars.discourse-cdn.com/v4/letter/x/ec9cab/32.png) [@xbix](https://discourse.processing.org/u/xbix)
#### Post date: [February 24, 2021, 9:35am UTC](https://discourse.processing.org/t/curve-control-points-settings-for-gauss-curve-behavior/27911/7 "2021-02-24T09:35:46Z")

</div>

Thanks Chrisir,  
this could be quite helpful to improve the math.
