For example, if we consider a shape in 2D like a circle at center $(x_0,y_0)$ with radius R so the equation would be:


now the normal on the surface is $${\bf \hat n}=\frac{\nabla f}{\|\nabla f\|}=\frac{(x-x_0,y-y_0)}{\sqrt{(x-x_0)^2+(y-y_0)^2}}$$ In this problem, I don't know the point on the circle to compute the normal. I have a point outside of the circle and I would like to find the normal vector from that point to the circle.

One idea is consider the point on the surface as a parametric form $$x=x_0+R\cos t,\\ y=y_0+R\sin t$$ then consider the normal vector as a function of $t$ and then find $t$. In this way, I have to solve fourth order equation, which makes my algorithm very expensive. I was wondering if there is an easier method which doesn't need to solve an equation.

  • $\begingroup$ I think you are missing a $^{2}$ in $f(x, y)$ ! $\endgroup$ – zxcvber Feb 26 '18 at 15:25
  • $\begingroup$ If we're talking about surfaces, and normals to surfaces, we are pretty much required to be in three dimensions, but your notation looks like two dimensions. It's a bit confusing. Can you clarify? Are you really talking about vectors that are perpendicular to a surface, or are you talking about vectors in a plane that are normal to a curve in that plane? $\endgroup$ – Adrian Keister Feb 26 '18 at 15:27
  • $\begingroup$ Implicit surface $(x - x_0)^2 + (y - y_0)^2 - R^2 = 0$ is not a circle in three dimensions; it is a right circular cylinder of radius $R$, with axis parallel to the $z$ axis. $\endgroup$ – Nominal Animal Feb 26 '18 at 15:33
  • 1
    $\begingroup$ I'm not sure what definitions you're using, but the normal of a surface is only defined at a point of that surface, it doesn't make sense to consider a normal (vector) at points outside the surface. It seems like you're looking for lines/half-lines/rays that go through a point outside the surface, and that are normal to the surface. And in general, such rays are non-unique. $\endgroup$ – N.Bach Feb 26 '18 at 15:39
  • 1
    $\begingroup$ @JoeHofstrand: Not $a^2$, a $\; ^2$. You've forgotten to square the difference in the $y$ coordinates. You have $(y - y_0)$, and it should be $(y - y_0)^2$. $\endgroup$ – Nominal Animal Feb 26 '18 at 15:39

Given a curve a $c$ and with normal $n_0$ at $P_0$ and $P$ outside, the condition is given by

$$P_0\subseteq \{(P+\vec n_o\cdot t) \cap c\}$$

For the circle it suffices that the line is through the center of the circle.

In general, for a generic curve $c$, the problem is hard to solve.


In 2D, you can calculate curve normals using the curve tangent, by rotating the tangent 90 degrees.

For example, if you have a curve $$\vec{v}(t) = \bigl( x(t) ,\, y(t) \bigr)$$ then $\vec{r}(t)$ is perpendicular to $\vec{v}(t)$: $$\vec{r}(t) = \left( -\frac{\partial\,y(t)}{\partial\,t}, \frac{\partial\,x(t)}{\partial\,t} \right)$$

An example. Let's say you have a circle of radius $R$ centered at $(x_0 , y_0)$: $$\vec{v}(t) = \begin{cases} x(t) = x_0 + R \cos t \\ y(t) = y_0 + R \sin t \end{cases}$$ Then, $$\vec{r}(t) = \begin{cases} \displaystyle -\frac{\partial\,y(t)}{\partial\,t} = -R \sin t \\ \displaystyle \frac{\partial\,x(t)}{\partial\,t} = R \cos t \end{cases}$$ If you want the unit normal $\hat{r}(t)$, you need to normalize the result: $$\hat{r}(t) = \frac{\vec{r}(t)}{\lVert\vec{r}(t)\rVert} = \frac{\vec{r}(t)}{\sqrt{\vec{r}(t) \cdot \vec{r}(t)}} = \left ( -\sin t ,\, \cos t \right )$$

Let's say you have a point $\vec{p} = ( x , y )$, and you want to find the point $\vec{v}(t)$ on the curve where a line perpendicular to the curve passes through the point $\vec{p}$. In other words, $$\vec{p} = \vec{v}(t) + L \vec{r}(t)$$ This is actually a system of two equations, $$\bbox[#fffff7, 0.5em]{\begin{cases} \displaystyle x = x(t) - L \frac{\partial y(t)}{\partial t} \\ \displaystyle y = y(t) + L \frac{\partial x(t)}{\partial t} \end{cases}}$$ that you need to solve for $t$, and optionally for $L$. $L$ is the distance from the curve (in units of the length of the perpendicular vector $\vec{r}(t)$).

For the above curve, we have $$\begin{cases} x = x_0 + R \cos t - L R \sin t \\ y = y_0 + R \sin t + L R \cos t \\ \end{cases}$$ There are two solutions, $$L = \pm \frac{\sqrt{(x - x_0)^2 + (y - y_0)^2 - R^2}}{R}$$ $$t = \operatorname{atan2}\left( \frac{(y - y_0) R \mp (x - x_0)\sqrt{(x - x_0)^2 + (y - y_0)^2 - R^2}}{(x - x_0)^2 + (y - y_0)^2} ,\;\; \frac{(x - x_0) R \pm (y - y_0)\sqrt{(x - x_0)^2 + (y - y_0)^2 - R^2}}{(x - x_0)^2 + (y - y_0)^2} \right)$$ where you choose either all upper signs, or all lower signs. $\operatorname{atan2}(\delta_y ,\, \delta_x)$ is essentially the same as $\arctan(\delta_y / \delta_x)$, except that $\operatorname{atan2}$ yields the correct quadrant also.

If we have a parametrized surface in 3D, for example $$\vec{s}(u, v) = \bigl( x(u,v) ,\, y(u,v) ,\, z(u,v) \bigr)$$ then we have two tangent vectors: $$\begin{aligned} \vec{s}_u(u, v) &= \left( \frac{\partial x(u,v)}{\partial u} ,\, \frac{\partial y(u,v)}{\partial u} ,\, \frac{\partial z(u,v)}{\partial u} \right) \\ \vec{s}_v(u, v) &= \left( \frac{\partial x(u,v)}{\partial v} ,\, \frac{\partial y(u,v)}{\partial v} ,\, \frac{\partial z(u,v)}{\partial v} \right) \end{aligned}$$ and the normal to the surface at $\vec{s}(u, v)$ is perpendicular to both tangents, and easy to obtain via cross product: $$\vec{r}(u, v) = \vec{s}_u(u, v) \times \vec{s}_v(u, v)$$ ie. $$\vec{r}(u, v) = \left [ \begin{array}{c} \left(\frac{\partial y(u,v)}{\partial u}\right)\left(\frac{\partial z(u,v)}{\partial v}\right) - \left(\frac{\partial z(u,v)}{\partial u}\right)\left(\frac{\partial y(u,v)}{\partial v}\right) \\ \left(\frac{\partial z(u,v)}{\partial u}\right)\left(\frac{\partial x(u,v)}{\partial v}\right) - \left(\frac{\partial x(u,v)}{\partial u}\right)\left(\frac{\partial z(u,v)}{\partial v}\right) \\ \left(\frac{\partial x(u,v)}{\partial u}\right)\left(\frac{\partial y(u,v)}{\partial v}\right) - \left(\frac{\partial y(u,v)}{\partial u}\right)\left(\frac{\partial x(u,v)}{\partial v}\right) \\ \end{array} \right ]$$

  • $\begingroup$ Thank you. To compute the vector $(-\sin t, \cos t)$ I need the value of $t$ $\endgroup$ – Joe Hofstrand Feb 26 '18 at 18:54
  • $\begingroup$ @JoeHofstrand: In 2D, that involves solving a system of two equations in two variables ($t$ and $L$). I've highlighted the formula for all 2D parametric curves. For 3D, you have a similar system of three equations in three variables ($u$, $v$, and $L$). In general, there are two solutions for circles, ellipsoids, and similar shapes; shapes with no corners may have more than two; and shapes with corners may not have any solutions. Consider e.g. a rectangle. The normals are perpendicular to the sides, so if you go off a corner, there are no normals there. $\endgroup$ – Nominal Animal Feb 26 '18 at 20:12
  • $\begingroup$ I think $\hat{r}(t)=(-\cos t,-\sin t)$ @NominalAnimal $\endgroup$ – Joe Hofstrand Feb 27 '18 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.