# Mathematic function

**URL:** <https://discourse.processing.org/t/mathematic-function/19535>\
**Category:** Coding Questions\
**Created:** [April 8, 2020, 9:13am UTC](https://discourse.processing.org/t/mathematic-function/19535 "2020-04-08T09:13:15Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcaaaalvo](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@mcaaaalvo](https://discourse.processing.org/u/mcaaaalvo)\
**Post date:** [April 8, 2020, 9:13am UTC](https://discourse.processing.org/t/mathematic-function/19535/1 "2020-04-08T09:13:15Z")

</div>

Hello, Does any body how to represent a curve in Processing, I have the equation of the curve but I don’t know how to represent it. If somebody could help me and telling me how to draw it I would thank it a lot

---

<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:** [April 8, 2020, 9:28am UTC](https://discourse.processing.org/t/mathematic-function/19535/2 "2020-04-08T09:28:13Z")

</div>

Hello,

and welcome to the forum!

Great to have you here!

Here is a medium advanced graph. Not by me but from the forum.

I hope this helps!

Warm regards,

Chrisir

```auto

// the max x for our test
int maxX = 100; // (in neg and pos direction)

// ---------------------------------------------------------------

void setup() {
  // init
  size(900, 600);
  background(111);

  drawCoordSystem(); 

  // draw graph
  float y; 
  for (float x= -maxX; x < maxX; x+=.01) { // from - maxX to + maxX with step 0.01 (very fine)
    // formulas: 
    // y = x*x;
    y = (3*(x*x))+(2*x)-1; 
    // apply to screen coordinate system
    PVector getScreenCoords = matchToScreenCoordinates(x, y); 
    // draw point 
    pointPVector(getScreenCoords);
  }//for
} // func 

void draw() { 
  // text box upper left corner 
  fill(111);
  noStroke();
  rect (0, 0, 100, 100);
  fill(255);
  text(" Plot Graph.", 30, 30);
} // func 

// ---------------------------------------------------------------

void drawCoordSystem() {

  // draw coord system in white 

  // (apply to screen coordinate system) 
  PVector getScreenCoord1 = matchToScreenCoordinates(-maxX, 0);
  PVector getScreenCoord2 = matchToScreenCoordinates(maxX, 0);
  linePVectors(getScreenCoord1, getScreenCoord2);

  getScreenCoord1 = matchToScreenCoordinates(0, height);
  getScreenCoord2 = matchToScreenCoordinates(0, -height);
  linePVectors(getScreenCoord1, getScreenCoord2);

  for (int x = -10; x<10; x++) {
    getScreenCoord1 = matchToScreenCoordinates(x, -.3);
    getScreenCoord2 = matchToScreenCoordinates(x, .3);
    linePVectors(getScreenCoord1, getScreenCoord2);
  }//for

  for (int y = -10; y<10; y++) {
    getScreenCoord1 = matchToScreenCoordinates( -.3, y);
    getScreenCoord2 = matchToScreenCoordinates( .3, y);
    linePVectors(getScreenCoord1, getScreenCoord2);
  }//for
}//func 

// -------------------------------------------------------------------
// convert the data from formula to screen appropriate format

PVector matchToScreenCoordinates (float x, float y) {
  // convert to screen coordinate system

  x*=40.0;
  y*=40.0; //y=y*0.019; 
  return new PVector (x+width/2, height/2-y-30);
}

// -------------------------------------------------------------------
// PVector functions 

void pointPVector(PVector pv) {
  // draw point at pv
  stroke(255, 2, 2); // red 
  point(pv.x, pv.y);
}

void linePVectors(PVector pv1, PVector pv2) {
  // draw line from pv1 to pv2
  stroke(255); // white 
  line(pv1.x, pv1.y, 
    pv2.x, pv2.y);
} 
//

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 8, 2020, 11:22am UTC](https://discourse.processing.org/t/mathematic-function/19535/3 "2020-04-08T11:22:52Z")

</div>

Show us the equation here.

You could also try one either the QScript or Jasmine libraries to evaluate the equation and graphica to plot it.

---

<div class="post-metadata">

**Author:** ![mcaaaalvo](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@mcaaaalvo](https://discourse.processing.org/u/mcaaaalvo)\
**Post date:** [April 8, 2020, 11:34am UTC](https://discourse.processing.org/t/mathematic-function/19535/4 "2020-04-08T11:34:05Z")

</div>

> [@quark](#):
>
> QScrip

How can I do this??  
could you text me in whatts app and help me please??  
+34 667307423  
THANK YOU SO MUCH

---

<div class="post-metadata">

**Author:** ![mcaaaalvo](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@mcaaaalvo](https://discourse.processing.org/u/mcaaaalvo)\
**Post date:** [April 8, 2020, 11:35am UTC](https://discourse.processing.org/t/mathematic-function/19535/5 "2020-04-08T11:35:41Z")

</div>

Thank you so much, but I triet to descifrate what it puts but I didn’t discovered anything hahaha

---

<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:** [April 8, 2020, 11:40am UTC](https://discourse.processing.org/t/mathematic-function/19535/6 "2020-04-08T11:40:14Z")

</div>

> [@Chrisir](#):
>
> point(pv.x, pv.y);

Instead of this you can also use ellipse

Not sure what you mean though

Did the program run?

What did you see?

The red dots are small, look closely

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 8, 2020, 12:05pm UTC](https://discourse.processing.org/t/mathematic-function/19535/7 "2020-04-08T12:05:50Z")

</div>

Need to know what the equation looks like.

The libraries I mentioned are all available through the Contributions Manager (Use the Sketch \> Add Library menu option) and they all include examples for you to look at.

---

<div class="post-metadata">

**Author:** ![mcaaaalvo](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@mcaaaalvo](https://discourse.processing.org/u/mcaaaalvo)\
**Post date:** [April 8, 2020, 12:17pm UTC](https://discourse.processing.org/t/mathematic-function/19535/8 "2020-04-08T12:17:17Z")

</div>

The equation is x^4+y^3-((x^2)\*y) = 0

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 8, 2020, 12:39pm UTC](https://discourse.processing.org/t/mathematic-function/19535/9 "2020-04-08T12:39:19Z")

</div>

- [Forum.Processing.org/two/discussion/7147/some-simple-pulse-equations-using-trig-#Item\_8](http://Forum.Processing.org/two/discussion/7147/some-simple-pulse-equations-using-trig-#Item_8)

---

<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:** [April 8, 2020, 1:49pm UTC](https://discourse.processing.org/t/mathematic-function/19535/10 "2020-04-08T13:49:31Z")

</div>

> [@mcaaaalvo](#):
>
> x^4+y^3-((x^2)\*y) = 0

I’d say this is a 3D formula, not a 2D formula ?

Do you have a graph how this looks like?

---

<div class="post-metadata">

**Author:** ![mcaaaalvo](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@mcaaaalvo](https://discourse.processing.org/u/mcaaaalvo)\
**Post date:** [April 8, 2020, 2:02pm UTC](https://discourse.processing.org/t/mathematic-function/19535/11 "2020-04-08T14:02:14Z")

</div>

![Screenshot 2020-04-08 at 16.01.43](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/226c417aca2c6bb7ae26a00a5ebe7138a73d1f79.jpeg)  
its a 2d hahah

---

<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:** [April 8, 2020, 2:15pm UTC](https://discourse.processing.org/t/mathematic-function/19535/12 "2020-04-08T14:15:21Z")

</div>

can you transform your formula in a way that instead of `......= 0` we have

`y = .......................`

please?

---

<div class="post-metadata">

**Author:** ![mcaaaalvo](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@mcaaaalvo](https://discourse.processing.org/u/mcaaaalvo)\
**Post date:** [April 8, 2020, 2:29pm UTC](https://discourse.processing.org/t/mathematic-function/19535/13 "2020-04-08T14:29:46Z")

</div>

I have this:  
x=t-(t^3)  
y=(t^2)-t^4)  
what is the parameterized function

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 8, 2020, 3:41pm UTC](https://discourse.processing.org/t/mathematic-function/19535/14 "2020-04-08T15:41:50Z")

</div>

> [@mcaaaalvo](#):
>
> x^4+y^3-((x^2)\*y) = 0

This formulae cannot be plotted as a simple function because it would have to be rearranged as a function i.e. `y = f(x)` where the function `f(x)` only has 1 unknown `x` and that is not a trivial task.

> [@mcaaaalvo](#):
>
> x=t-(t^3)  
> y=(t^2)-t^4)

This is a pair of _parametric equations_ where the two unknowns `x` and `y` are both functions of a shared variable `t` (the parametric variable) i.e.  
`x = f(t) = t - t^2` and  
`y = g(t) = t^2 - t^4`

Since you want to plot this parametric function I recommend Jasmine over QScript as it’s faster.

The sketch below uses the Jasmine library evaluate your parametric equations over a user defined range of `t` giving this output.

```
t x y 
-50.0 -2550.0 -6247500.0
-40.0 -1640.0 -2558400.0
-30.0 -930.0 -809100.0
-20.0 -420.0 -159600.0
-10.0 -110.0 -9900.0
  0.0 0.0 0.0
 10.0 -90.0 -9900.0
 20.0 -380.0 -159600.0
 30.0 -870.0 -809100.0
 40.0 -1560.0 -2558400.0
 50.0 -2450.0 -6247500.0
```

The sketch code

```auto
import org.quark.jasmine.*;

String xt_expr, yt_expr;
Expression x_expr, y_expr;

void setup() {
  xt_expr = "t - t^2";
  yt_expr = "t^2 - t^4";
  x_expr = Compile.expression(xt_expr, false);
  y_expr = Compile.expression(yt_expr, false);
  float minT = -50, maxT = 50, deltaT = (maxT - minT) / 10;
  float t = minT;
  System.out.println("t \t\tx\t\ty = ");
  while(t <= maxT){
    float x = x_expr.eval(t).answer().toFloat();
    float y = y_expr.eval(t).answer().toFloat();
    println(t + "\t\t" + x + "\t\t" + y);
    t += deltaT;
  }
}

```

Bezier curves are probably the most famous types of parametric equations 😄

---

<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:** [April 8, 2020, 3:58pm UTC](https://discourse.processing.org/t/mathematic-function/19535/15 "2020-04-08T15:58:00Z")

</div>

Thanks for explaining!

> [@mcaaaalvo](#):
>
> x^4+y^3-((x^2)\*y) = 0

What are those functions called?

* * *

**2D functions**

2D functions receive one parameter x and the result is y. In a 2D coordinate system enter the two values as one point x,y.

 ![g2D](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/aac8c5f9ecd87b8929709f0b10af5b11323f4846.png)

* * *

**3D functions**

3D functions receive two parameters x and y and the result is z. Think of a grid where x,y gives you a cell and z is the value (the height) of this cell (above the cell in 3D space).

 ![g3D](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8f6988ba5669efc0c3dcfeda665f334f3cbbbdc6.jpeg)

* * *

**Further Readings**

see also : [Math Projects · Kango/MathProjects Wiki · GitHub](https://github.com/Kango/MathProjects/wiki/Math-Projects)

and [GitHub - Kango/MathProjects: Math Projects in Processing](https://github.com/Kango/MathProjects)

**Further Readings on Cartesian coordinate system**

see [Cartesian coordinate system - Wikipedia](https://en.wikipedia.org/wiki/Cartesian_coordinate_system#Two_dimensions)

see [Cartesian coordinate system - Wikipedia](https://en.wikipedia.org/wiki/Cartesian_coordinate_system#Three_dimensions)

This could be a nice tutorial.

Chrisir

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 8, 2020, 4:29pm UTC](https://discourse.processing.org/t/mathematic-function/19535/16 "2020-04-08T16:29:32Z")

</div>

I should point out that I finished studying maths at 18 so I am not a qualified mathematician . Although I am quite good at maths and do find the subject interesting I do have my limits 😄

> [@mcaaaalvo](#):
>
> x^4+y^3-((x^2)\*y) = 0

I don’t know if there is a technical / mathematical name for this type of equation, I generally just call them _bastards_ LOL

I am also not sure if there is such a thing as a “3D formulae” in mathematics, but it appears to be a big thing in spreadsheets, according to [google](https://www.google.com/search?q=what+is+a+3d+formula&newwindow=1&safe=strict&client=firefox-b-d&sxsrf=ALeKk02XDX-2cWNLf-RWtSzP6bK8cMO7Sg:1586361670531&ei=RvWNXuGIINSh8gKq75vwCw&start=10&sa=N&ved=2ahUKEwjhw-3emdnoAhXUkFwKHar3Br4Q8NMDegQIDhA_&biw=2020&bih=1205).

As I said Bezier curves are parametric curves and are great fun and very useful in computing.

I am currently working on a Bezier library based on this [primer](https://pomax.github.io/bezierinfo/) and using [EJML](http://ejml.org/wiki/index.php?title=Main_Page) to do some of the maths.

Although we are familiar with seeing 2D Bezier curves where `x = f(t)` and `y = g(t)` we can have 3D Beziers by adding a third expression for `z` where `z = h(t)`

If you want more detail on parametric curves and Bezier curves in particular here is a lot of information on the internet.

---

<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:** [April 8, 2020, 5:34pm UTC](https://discourse.processing.org/t/mathematic-function/19535/17 "2020-04-08T17:34:41Z")

</div>

> [@quark](#):
>
> I don’t know if there is a technical / mathematical name for this type of equation

A challenging polynomial.

`:)`
