We have created a quadrifolium function, and we may need help to write its tangent. We would like to see the tangent line every time the mouse is on the function, for each point of it

The equation and the parameterization are:

Equation: (x^6)+(3x^4·y^2)+(3x^2·y^4)+(y^6)-(4a^2·x^2·y^2)=0
Parameterization: x=2asin^2tcost and y=2acos^2tsint

The code we have written is:

``````void setup(){
frameRate(30);
size(600,600);
}
void draw(){
background(255,255,255);
stroke(0,0,0);
cross(300,300);
println(frameCount);
stroke(0,0,0);
line(300,100,300,500);
line(100,300,500,300);
}void cross(float x, float y ){
for (int t=0 ; t<2000 ; t=t+1){
point(x-2*200*sin(t)*sin(t)*cos(t),y-2*200*cos(t)*cos(t)*sin(t));
}
}
``````

Hello,

Please format your post as a courtesy to others in the community:
https://discourse.processing.org/faq#format-your-code

Here are some resources for you:

Resources

I encourage you to review the resources available here:

`:)`

Hello,

You are missing most of the plot:

`:)`

1 Like

Welcome to the forum. Is this homework?
Are you a Civil Engineering student?

Before you draw the tangent you need to be able to draw the curve and your code has syntax errors so you can’t see anything. Change the cross method to

``````void cross(float x, float y ) {
for (float t = 0; t < 600; t = t + 0.1) {
point(x-300*sin(t)*sin(t)*cos(t), y-300*cos(t)*cos(t)*sin(t));
}
}
``````

This is impossible to do using the implicit formula
`(x^6)+(3x^4·y^2)+(3x^2·y^4)+(y^6)-(4a^2·x^2·y^2)=0`
so use the two parametric equations
`x = 2*a*sin^2(t)*cos(t)`
`y = 2*a*cos^2(t)*sin(t)`
Split this into two sub problems

1. For a given value of `t` calculate the position on the curve and the slope (angle) of the tangent.
2. Determine the value of `t` when the mouse is very close to the curve

Starting with (1)
If we know `t` then we can use the parametric equations above to find the position `[x, y]` on the curve.
To find the tangent angle you need to differentiate the parametric equations i.e.
`x' = dx/dt = ???` and
`y' = dy/dt = ???`
??? = I leave the calculus to you

Let `dxt = x'` and `dyt = y'`
The tangent angle is given by the formula
angle = atan(-dyt / dxt)

That should be enough to get you started.

1 Like

This calls for a tutorial or blog post…

We are seeing a lot of tangent lines problems just lately. Interesting that there seem to be many different curves. I wonder where the exam is.

1 Like