# 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.

3 Likes