Quadrifolium curve

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(){
void draw(){
}void cross(float x, float y ){
  for (int t=0 ; t<2000 ; t=t+1){


Please format your post as a courtesy to others in the community:

Here are some resources for you:


I encourage you to review the resources available here:



You are missing most of the plot:


1 Like

Welcome to the forum. :smile:

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