# Tangent to parametric curve

**URL:** https://discourse.processing.org/t/tangent-to-parametric-curve/19788
**Category:** Coding Questions
**Tags:** homework
**Created:** [April 14, 2020, 10:12pm UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788 "2020-04-14T22:12:15Z")
**Posts on this page:** 20
**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 14, 2020, 10:12pm UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/1 "2020-04-14T22:12:15Z")

</div>

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:

```auto
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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/95800ad78da30e003e8fe5983ffaa1f7aa725faf.png)

---

<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 14, 2020, 10:34pm UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/2 "2020-04-14T22:34:01Z")

</div>

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

---

<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 14, 2020, 10:41pm UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/3 "2020-04-14T22:41:59Z")

</div>

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

---

<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 15, 2020, 8:32am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/4 "2020-04-15T08:32:43Z")

</div>

> [@mcaaaalvo](#):
>
> PARAMETERIZATION

what is this exactly?

---

<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 15, 2020, 8:43am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/5 "2020-04-15T08:43:55Z")

</div>

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

---

<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 15, 2020, 9:16am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/6 "2020-04-15T09:16:32Z")

</div>

> [@mcaaaalvo](#):
>
> 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.

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

---

<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 15, 2020, 9:26am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/7 "2020-04-15T09:26:57Z")

</div>

> [@mcaaaalvo](#):
>
> implicit derivative

what is this exactly? The slope?

---

<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 15, 2020, 9:28am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/8 "2020-04-15T09:28:00Z")

</div>

> [@mcaaaalvo](#):
>
> There is something wrong with the code

what is wrong exactly?

---

<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 15, 2020, 9:28am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/9 "2020-04-15T09:28:45Z")

</div>

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!!!

---

<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 15, 2020, 9:30am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/10 "2020-04-15T09:30:43Z")

</div>

**Parametrization** , also spelled **parameterization** , **parametrisation** or **parameterisation** , is the process of defining or choosing [parameters](https://en.wikipedia.org/wiki/Parameter).

> **[Parametrization](https://en.wikipedia.org/wiki/Parametrization)**
>
> Parametrization, also spelled 
> parameterization,
> parametrisation or 
> parameterisation,
> is the process of defining or choosing parameters. 
> Parametrization may refer more specifically to:
> Parameter (disambiguation)
> .mw-parser-output table.dmbox{clear:both;margin:0.9em 1em;border-top:1px solid #ccc;border-bottom:1px solid #ccc;background-color:transparent}

---

<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 15, 2020, 9:32am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/11 "2020-04-15T09:32:52Z")

</div>

> [@Chrisir](#):
>
> > [@mcaaaalvo](#):
> >
> > implicit derivative
> 
> what is this exactly? The slope?

can you please answer this?

---

<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 15, 2020, 9:34am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/12 "2020-04-15T09:34:44Z")

</div>

> [@mcaaaalvo](#):
>
> I think the slope is the same everywhere.

I really don’t think so …

😉

> [@Chrisir](#):
>
> what is wrong exactly?

what is wrong exactly?

---

<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 15, 2020, 9:44am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/13 "2020-04-15T09:44:38Z")

</div>

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

---

<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 15, 2020, 9:58am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/14 "2020-04-15T09:58:37Z")

</div>

Maybe that haha ![Screenshot 2020-04-15 at 11.58.22](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f06527f90ecf1ea8dacdaf13ea9942d6e9ef37b5.png)

---

<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 15, 2020, 10:29am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/15 "2020-04-15T10:29:55Z")

</div>

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:

```auto
  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

```auto

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
}

```

---

<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 15, 2020, 10:51am UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/16 "2020-04-15T10:51:46Z")

</div>

Is this what you hope to achieve 😄

[![](https://img.youtube.com/vi/McB7iK3o-tI/hqdefault.jpg "Tangent to a parametric curve") ](https://www.youtube.com/watch?v=McB7iK3o-tI)

---

<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 15, 2020, 5:35pm UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/17 "2020-04-15T17:35:58Z")

</div>

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

---

<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 15, 2020, 5:45pm UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/18 "2020-04-15T17:45:33Z")

</div>

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.

---

<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 15, 2020, 5:46pm UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/19 "2020-04-15T17:46:06Z")

</div>

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

---

<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 15, 2020, 5:52pm UTC](https://discourse.processing.org/t/tangent-to-parametric-curve/19788/20 "2020-04-15T17:52:51Z")

</div>

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???

[Next page](https://discourse.processing.org/t/tangent-to-parametric-curve/19788.md?page=2)
