Find the normal "N" on an ellipses through a point on a cross section

ellipse, geometry, normals

Solution

Equation of an ellipse point is

x=x_centre+a*cos(t)
y=y_centre+b*sin(t)

For each point of ellipse you can find `t` as `atan2( (y-y_centre)/b , (x-x_centre)/a )`

When you know `t` tangent direction can be determined: `dx/dt,dy/dt`:

dx=-a*sin(t)
dy=b*cos(t)

When you know tangent direction, just rotate it by 90 degrees and you have a normal:

nx=b*cos(t)
ny=a*sin(t)

And to avoid calculating `t` we can combine it with the first two formulas:

nx=(x-x_centre)*b/a
ny=(y-y_centre)*a/b

Problem

I'm trying to make a nice deflection effect in a little physics engine I've made. Right now it deflects nicely off the normal of a polygon edge. But instead of making a polygon with 100 edges to get a smooth effect of a "rounded deflection" I figured I could calculate the deflection normal using an ellipse instead. So, what I'd really like is a function that takes a point P on a line segment and returns the normal N on the circumference of an imaginary ellipse(w,h). See the attached picture for some details. To get a point on the circumference of an ellipse I'm pretty sure it's: ``` x=P.x+Math.sin()*w y=P.y+Math.cos()*h ``` but how can I get the normal from that? Here's a fiddle with an attempt to implement the answer by Dr BDO Adams.

Original source