# Closest Point on a 3D Quadratic Surface

• Feb 8th 2010, 08:22 AM
davesymm
Closest Point on a 3D Quadratic Surface
Hi All, first post, hope I'm obeying all the rules :)

If I have a 3d quadratic surface defined by $\displaystyle ax^2+by^2+cz^2+d=0$ and a point in space defined by the position vector $\displaystyle p={px,py,pz}$ , how can I determine the closest point on the surface to p?

I suspect the solution lies down the path of minimising the value of the difference between the points, or finding the values of x, y and z that minimise $\displaystyle apx^2+bpy^2+cpz^2-ax^2-by^2-cz^2$, but my maths is rusty and I have a feeling that if this is possible it would involve implicit differentiation or one of the other techniques I never quite mastered the first time around.

Any help or even a pointer to a different (easier) approach would be much appreciated.

Thanks,
Dave.
• Feb 9th 2010, 09:26 PM
Pulock2009
the closest point will obviously be the point which lies perpendicular to the surface ie. at an angle of 90 degrees. i did this problem somewhere but i forgot the technique. u can assume a point O(x,y,z) on the surface and then carry out calculations keeping in mind the facts:OP is perpendicular to the surface and O satisfies the surface equation. there is also a shortcut involving dot product and cross product which i dont remember well. hope this helps!!!
• Feb 10th 2010, 07:03 AM
HallsofIvy
Quote:

Originally Posted by davesymm
Hi All, first post, hope I'm obeying all the rules :)

If I have a 3d quadratic surface defined by $\displaystyle ax^2+by^2+cz^2+d=0$ and a point in space defined by the position vector $\displaystyle p={px,py,pz}$ , how can I determine the closest point on the surface to p?

I suspect the solution lies down the path of minimising the value of the difference between the points, or finding the values of x, y and z that minimise $\displaystyle apx^2+bpy^2+cpz^2-ax^2-by^2-cz^2$, but my maths is rusty and I have a feeling that if this is possible it would involve implicit differentiation or one of the other techniques I never quite mastered the first time around.

Any help or even a pointer to a different (easier) approach would be much appreciated.

Thanks,
Dave.

One way to do this is to take as the function to be minimized $\displaystyle (x- px)^2+ (y- py)^2+ (z- pz)^2$ (that's actually the square of the distance but minimizing it is the same as minimizing distance and this avoids the square root). You then have the additional condition, ax^2+ by^2+ cz^2+ d= 0.

Use the geometric argument that Pulock2009 suggests with a little analysis: the gradient vector $\displaystyle \nabla (ax^2+ by^2+ cz^2+ d)= (2ax)\vec{i}+ (2by)\vec{j}+ (2cz)\vec{k}$ is always perpendicular to the surface and (x, y, z) will be closest to (px,py,pz) when the vector directly from one to the other, $\displaystyle (x- px)\vec{i}+ (y- py)\vec{j}+ (z- pz)\vec{k}$ (which, notice, is 1/2 the gradient of the "distance squared" function) is pointing perpendicular to the surface- that is the two vectors must be parallel which means one is a multiple of the other:

$\displaystyle (2ax)\vec{i}+ (2by)\vec{j}+ (2cz)\vec{k}= \lambda((x- px)\vec{i}+ (y- py)\vec{j}+ (z- pz)\vec{k})$.

where $\displaystyle \lambda$ is the multiple. (It is, technically, the "Lagrange multiplier".)

That gives you four equations, $\displaystyle 2ax= \lambda(x- px)$, $\displaystyle 2by= \lambda(y- py)$, $\displaystyle 2cz= \lambda(z- pz)$, and the equation of the surface, $\displaystyle ax^2+by^2+cz^2+d=0$, to solve for x, y, z, and $\displaystyle \lambda$.

Since you don't really need to know $\displaystyle \lambda$, I recommend dividing one equation by another to eliminate $\displaystyle \lambda$.
For example, dividing $\displaystyle 2ax= \lambda(x- px)$ by $\displaystyle 2by= \lambda(y- py)$ gives $\displaystyle \frac{ax}{by}= \frac{x- px}{y- py}$ which we could solve for y as a function of x. Similarly, dividing [/tex]2ax= \lambda(x- px)[/tex] by $\displaystyle 2cz= \lambda(z- pz)$ gives $\displaystyle \frac{ax}{cz}= \frac{x- px}{z- pz}$ which you could solve for z as a function of x. Putting those into the equation of the surface gives one equation to solve for x.
• Feb 15th 2010, 08:06 AM
davesymm
Thanks for the help :)

I've rearranged the equations in the form $\displaystyle ax/by=(x-px)/(y-py)$ and get $\displaystyle y=axpy/((a-b)x+ypx)$ (and similar for $\displaystyle z$). However, when I come to substitute this into $\displaystyle ax^2+by^2+cz^2+d=0$ it gets a little complicated, and I'm not sure I can solve it using the general quadratic equation.

Am I missing a glaringly simple solution? Otherwise I may have to abandon this path of thought as it is in a computationally sensitive piece of code and I'm not sure I can afford the increasing mathematical load.

Thanks again for all the help.