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

I am trying to make a good deflection effect in the little physics engine that I made. Now it deviates perfectly from the normal to the edge of the polygon. But instead of making a polygon with 100 edges in order to get a smooth “rounded deflection” effect, I decided that instead of calculating the ellipse, I could calculate the normal deviation.

So, I really liked the function that takes a point P on a line segment and returns normal N on the circle of an imaginary ellipse (w, h). See the attached image for some details.

A picture of the problem

To get a point on the circumference of an ellipse, I am sure this is:

x=P.x+Math.sin()*w y=P.y+Math.cos()*h 

but how can I get normal from this?


Here's a fiddle trying to execute Dr BDO Adams answer.

+4
source share
2 answers

Ellipse Point Equation

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

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

When you know t you can determine the tangent direction: dx/dt,dy/dt :

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

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

 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 
+4
source

First use the atan2 function to get the angle from the normal, and get a vector from this

 theta = atan2(2y/semiminorradius, x/semimajorradius) ny = semiminorradius * sin(theta) nx = semimajorradius * cos(theta) 

Do you need a normal vector to normalize? (unit length) if so

 r = sqrt(tx^2+ty^2) nny = ny/r nnx = nx/r 

As you drew it, the point is actually (ny, nx)

0
source

Source: https://habr.com/ru/post/1447926/


All Articles