# comp.graphics.algorithms

## Subject: Re: common point of two planes

> Because the intersection is a line, v can be selected arbitrarily: an
> easy selection is v = 0, or you might try a different selection
> criteria. One that pops into mind is minimizing the distance of the
> solved point to some other point (for example, origin).
>
> After choosing v, substitute u back into the first equation and you have
> got rid of the (u, v) parameters and thus the parameteric form! Like
> said, the solution is objective, independent of the solving technique.

To even more show the objectiveness, I'll further describe choosing the
v such that the distance to some point O is minimized, to complement the
answer of Gino showing two solutions of the same problem with different
solving strategies.

We computed:

P(v) := Pa + [(dot(Pb - Pa, Nb) - v * dot(Va, Nb)) / dot(Ua, Nb)] * Ua
+ v * Va

Rearrange to separate v:

P(v) = Pa + [dot(Pb - Pa, Nb) / dot(Ua, Nb)] * Ua
+ v * (Va - [dot(Va, Nb) / dot(Ua, Nb)] * Ua)

To shorten notation let:
Q := Pa + [dot(Pb - Pa, Nb) / dot(Ua, Nb)] * Ua
R := Va - [dot(Va, Nb) / dot(Ua, Nb)] * Ua

Then:

P(v) = Q + v * R

We wish to minimize the distance from some point O to P(v). Define a
distance function D as:

D(v) := ||P(v) - O||

Because D(v) is always non-negative, the minimization of D(v)^2 yields
the same answer. So we define:

E(v) := D(v)^2 = ||P(v) - O||^2 = dot(P(v) - O, P(v) - O)
= dot((Q - O) + v * R, (Q - O) + v * R)

By bilinearity:

E(v) = dot(Q - O, Q - O) + 2 * v * dot(Q - O, R) + v^2 * dot(R, R)

We minimize this function by finding the v for which the derivative
E'(v) = 0.

E'(v) = 2 * v * dot(R, R) + 2 * dot(Q - O, R) = 0
=>
v = -dot(Q - O, R) / dot(R, R)

Here we have assumed that dot(R, R) != 0. To see that v is actually a
minimum we calculate the second derivative E''(v):

E''(v) = 2 * dot(R, R) > 0

Finally, we get:

P = Q - [dot(Q - O, R) / dot(R, R)] * R

Note we have used coordinate free notations everywhere. Thus this
solution is independent of the dimension n of the space you are working
in! This works for all dimensions n >= 3.

The geometric interpretation of dot(R, R) = 0 is left as an exercise:)

--
Kalle Rutanen
http://kaba.hilvi.org