I hit a road block. I have been trying to find a way to get the normal to an Ellipse at a given point of intersection.
What I am aware of:
With the 2D ellipse equation being (x/a)^2 + (y/b)^2 = 1 taking the first derivative of this equation will give you the slope of the tangent line.
This must be where I am going wrong. You see I figured out that dy/dx = -((b^2 * x)/(a^2 * y)). (I'[color=#FF0000]m thinking this is wrong)
I know that once I have the slope of the tangent line I simply take the negative reciprocal (perpendicular) of that slope and I have my normal.
When using this dy/dx in my code to determine the slope I get an incorrect result:
public Vector2 GetNormalAt(Point intersection)
{
//First derivative of (X/A)^2 + (Y/B)^2 = 1
//This gives the slope of the Tangent line at the given point.
float dx = (Major * Major) * intersection.Y;
float dy = -(Minor * Minor) * intersection.X;
//Take negative reciprocal to get perpendicular slope for that of the normal
Vector2 normal = new Vector2(-dy, dx);
normal.Normalize();
return normal;
}
Unfortunately I seem to be getting nearly the same normal regardless of it's intersection point.
If I have:
A Line at: P0 = 459, 434 and P1 = 449, 454 therefore a slope of dx = -10 and dy = 20
An Ellipse at: Center = 449, 472 with a Major radius = 32 and a Minor Radius = 16
I get an intersection point = 449, 453
When I try to get the normal at this position I get <0.238, 0,971>
Now if I move the line so that the intersection point = 490, 458
My normal is now <0.249, 0.969> which definitely does nto seem right to me.
My only guess is that I did something wrong taking the first derivative yet I can't seem to find where I went wrong. Obviously math is not my strong point.
Does anyone have a suggestion for me that I could use or a sample snippet of code that actually properly calculates the normal to an ellipse at a given intersection point?
Thanks in advance,
Jonathan