Calculating normal to any arbitary surface

Hello,

I am looking to calculate normal (pointing outwards) at each point of a curve. I want to know if there is any Julia package to perform this action.I am using the Forward gradient package to calculate the gradient at each point. I have a vector of many vectors as the input and would like to calculate the normal at each input vector.
Please let me know if there is any package.

Thank you in advance for the help.
Jyoti.

I am not sure this problem can be solved so generally. For example, if your points are all on a straight line, there is no unique normal vector at each point.

1 Like

For a general curve you can compute the Frenet triad. But not necessarily unique, as pointed out by someone above.

2 Likes

It’s an easy calculus exercise to get a normal from the gradient.

If you have a surface defined implicitly by f(\vec{x}) = 0, then the gradient \nabla f is a normal vector if you evaluate it for any point on the surface.

If you have a 2d surface z = f(x,y) in 3d, then this is equivalent to f(x,y) - z=0 and so the normal vector is \nabla_{xyz} (f - z) = \begin{pmatrix} \partial f / \partial x \\ \partial f / \partial y \\ -1\end{pmatrix}.

If you have a 1d curve y = f(x) in 2d, then applying the same thing to f(x) - y yields the normal vector \begin{pmatrix} \partial f / \partial x \\ -1\end{pmatrix}.

If you have a 1d curve in n > 2 dimensions \vec{x} = \vec{f}(t) \in \mathbb{R}^n, then the normal vector is not uniquely defined — it could be any vector orthogonal to the tangent d\vec{f}/dt. You need to supply more information about which normal vector you want.

Just figure out the formula at each point, and then apply it to as many vectors as you want.

There is no need in Julia to search for “vectorized” or “built-in” functions — user code is fast, and loops are fast, as long as you follow the performance tips.

4 Likes

Thank you for your response.
My points lie on a circle or an arbitrary closed curve in 2D.

Thank you for your response.
Right, I only need a normal pointing outwards from the 2D surface.

Thank you for your detailed response.
In my case, I want to evaluate a normal at every point located on a circle first.
Later, I want to extend this to any curve (2D). I am interested in a normal vector pointing outwards from the surface.

Computing a normal vector from the derivative is easy from the derivative, as I mentioned. Computing the outward normal vector is more difficult, and may be impossible to define if the curve is self intersecting. See this stackoverflow discussion.