What we need is the tangent to the ellipse at a given angle. I knew this should be straight forward, but it took a while for my brain to slip back to A-Level maths mode and remember how to do this. Too much time writing Tools code I guess. Anyway, Calculus to the rescue!
So if P is the point on the ellipse that we defined in the previous post, we are looking for T the tangent on the line.
P = m_h * cos(t) * m_up + m_l * sin(t) * m_along + m_centre;
To find the tangent we want the derivative of this equation, that is the rate of change of P with respect to t ( the angle around the ellipse ). So we can simply differentiate w.r.t. t which is simple if you know that the differential of sin(t) is cos(t) and the differential of cos(t) is -sin(t). Giving us
T = - m_h * sin(t) * m_up + m_l * cos(t) * m_along;
Note, that we've lost m_centre, because that is a constant.
And that is it, here is the full method
Vector3 TangentAt(float t) const
{
float c = cos(t);
float s = sin(t);
return - m_h * s * m_up + m_l * c * m_along;
}
0 comments:
Post a Comment