# Closest Point on a 3D Quadratic Surface

• February 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 $ax^2+by^2+cz^2+d=0$ and a point in space defined by the position vector $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 $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.
• February 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!!!
• February 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 $ax^2+by^2+cz^2+d=0$ and a point in space defined by the position vector $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 $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 $(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 $\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, $(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:

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

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

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

Since you don't really need to know $\lambda$, I recommend dividing one equation by another to eliminate $\lambda$.
For example, dividing $2ax= \lambda(x- px)$ by $2by= \lambda(y- py)$ gives $\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 $2cz= \lambda(z- pz)$ gives $\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.
• February 15th 2010, 08:06 AM
davesymm
Thanks for the help :)

I've rearranged the equations in the form $ax/by=(x-px)/(y-py)$ and get $y=axpy/((a-b)x+ypx)$ (and similar for $z$). However, when I come to substitute this into $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.