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
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
For a given value of t calculate the position on the curve and the slope (angle) of the tangent.
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)