Mathematic function

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

2 Likes

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


// 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);
} 
//
1 Like

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.

1 Like

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

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

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

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.

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

1 Like

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

Do you have a graph how this looks like?


its a 2d hahah

1 Like

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

y = .......................

please?

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

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.

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

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 :smile:

2 Likes

Thanks for explaining!

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.


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).


Further Readings

see also : Math Projects · Kango/MathProjects Wiki · GitHub

and GitHub - Kango/MathProjects: Math Projects in Processing

Further Readings on Cartesian coordinate system

see Cartesian coordinate system - Wikipedia

see Cartesian coordinate system - Wikipedia

This could be a nice tutorial.

Chrisir

1 Like

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 :smile:

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.

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 and using EJML 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.

3 Likes

A challenging polynomial.

:)

1 Like