Tangent to parametric curve

I have to create a program, that when I put the mouse on any point of the curve, it draws its tangent line, and writes to me in a corner the value of the slope of this line. The drawing have to include the cartesian axis. The equation and the parameterization are:
BOW CURVE: (x^4)+(y^3)-((x^2)*y)=0

PARAMETERIZATION: x=t-t^3 and y=t^2-t^4

The code I have right now is this:

float a=300;
float angle=((-4*pow(mouseX,2)+2*mouseX*mouseY)/((3*pow(mouseY,2)-pow(mouseX,2))));
float w=300;

void setup(){
  size(750,750);
}
void draw(){
  background(255);
  //AXIS(height,width);
  translate(width/2,height/2);
  
  
  for(float t=0; t<2*PI; t=t+0.001){
    stroke(255,128,0);
    strokeWeight(1.25);
    point(a*(t-pow(t,3)),-a*(pow(t,2)-pow(t,4)));
    point(-a*(t-pow(t,3)),-a*(pow(t,2)-pow(t,4)));
  }
{
angle=atan(((-4*pow(mouseX,2)+2*mouseX*mouseY)/((3*pow(mouseY,2)-pow(mouseX,2)))));

pushMatrix();
translate(mouseX-width/2,mouseY-height/2);
rotate(((-4*pow(mouseX,2)+2*mouseX*mouseY)/((3*pow(mouseY,2)-pow(mouseX,2)))));
line(-w,0,w,0);
popMatrix();
  
}

}

There is something wrong with the code, if anyone could help me please.

The implicit derivative of the curve is this:
Screenshot 2020-04-15 at 00.07.58

Please hit ctrl-t in processing prior to posting

When posting mark your code as code using <> Symbol in the command bar of the forum

Idon’t know how to do it, could you help me with my code??

what is this exactly?

Make a function dependin on x and y, which they depend on t
Do you know how to fix it??

when you mean the slope of this line, it’s rather the slope of the section of this line, right?

Or is it the same everywhere?

So the function must know where the mouse is on the graph?

maybe I can help you later

what is this exactly? The slope?

what is wrong exactly?

I think the slope is the same everywhere.
Yes please, hahah i have to hand on the homework before the April 18, And I have to fix that problem hahaha
Thanks!!!

Parametrization , also spelled parameterization , parametrisation or parameterisation , is the process of defining or choosing parameters.

can you please answer this?

I really don’t think so …

:wink:

what is wrong exactly?

thw implicit derivative is just the derivative of the function, and what is wrong is that the tangent line doesn’t fit with the drawing

Maybe that hahaScreenshot 2020-04-15 at 11.58.22

At the moment, we see the slope throughout from the mouse. I don’t like it.

Are you into OOP?

If I were you I made a class PointOfGraph which stores the points and also the
implicit derivative/ slope for this point.

Fill it in setup() with this:

  for (float t=0; t<2*PI; t=t+0.001) {
    stroke(255, 128, 0);
    strokeWeight(1.25);
    point(a*(t-pow(t, 3)), -a*(pow(t, 2)-pow(t, 4)));
    point(-a*(t-pow(t, 3)), -a*(pow(t, 2)-pow(t, 4)));   
  }

Display it in draw():

Now, check if mouse is on a point and then display the slope.

Below is another idea, an example that displays slope tangent line only when the mouse is on a point of a graph. It doesn’t work. When the implicit derivative of the curve is correct in your code, maybe the usage of atan is wrong?

I can’t help you no more.

Chrisir


float a=300;
float angle=0; // =((-4*pow(mouseX, 2)+2*mouseX*mouseY)/((3*pow(mouseY, 2)-pow(mouseX, 2))));
float w=300;

void setup() {
  size(750, 750);
}

void draw() {
  //
  background(255);
  //AXIS(height,width);
  translate(width/2, height/2);


  for (float t=0; t<2*PI; t=t+0.001) {
    stroke(255, 128, 0);
    strokeWeight(1.25);
    point(a*(t-pow(t, 3)), -a*(pow(t, 2)-pow(t, 4)));
    point(-a*(t-pow(t, 3)), -a*(pow(t, 2)-pow(t, 4)));

     // only for THE FIRST POINT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    if (dist(mouseX-width/2, mouseY-height/2, 
      a*(t-pow(t, 3)), -a*(pow(t, 2)-pow(t, 4)) ) < 8) 
    {
      angle=atan(((-4*pow((mouseX-width/2), 2)+2*(mouseX-width/2)*(mouseY-height/2))
        /
        ((3*pow((mouseY-height/2), 2)-pow((mouseX-width/2), 2)))));

      pushMatrix();
      translate(mouseX-width/2, mouseY-height/2);
      rotate(angle); 
      line(-w, 0, 
        w, 0);
      popMatrix();
    }
  }//for
}

Is this what you hope to achieve :smile:

2 Likes

Thank you so much for your work, don’t worry, i’ll continue trying new things basing on he code you fixed.
Thank you so much

I don’t understand - I have not provided any other code related to this discussion on tangents. I simply posted the video to confirm what is expected so I don’t waste time explaining the wrong solution.

1 Like

And you could fix my code? or telling me what’s wrong?

I can explain what you need to do to make behave like the video. I will not provide the actual code since it is homework.

Do you want me to do that???