As I have said before, some of my friends took the very wise decision to go back to school (that is, university) and, accordingly, they’re doing all the undergrad maths courses. As I try to help them whenever I can, I decided to ask them to solve a simple puzzle… or so I thought.
So the problem is as follows:
You have a circle of center , radius and some point , with . Find the projection of point against the circle with center and radius . The method should work whether is inside or outside the circle.
So I ask Ethan (that’s not his real name, but he’ll recognize himself) to solve this problem. So he thinks about this a few seconds and sets to solve the two equations, two unknowns system:
which is non-linear. Of course, I stopped him right there to spare him the pain of solving it, because that’s not the solution I was thinking of. But for you, let’s work out the solution anyways; you’ll see why.
Since we have terms here and there, let us change the system to:
So we can rewrite the first as either:
Let us use the first variant. We can rewrite the second eq. as:
and let us observe that the right hand side of the equation is constant, as it doesn’t have terms in , for which we are trying to solve. Let us put and . We can rewrite the equation as:
let us simplify:
Wow. That was a lot to find just . So we use (*) to solve for :
And we’re done. We can quickly check that it’s the right answer (it always helps):
The and cancel out:
So it’s the right solution. Plotting the point does land on the circumference of the circle (as shown in the illustration above).
OK, that’s an insane amount of work for the actual complexity of the problem. Let us now solve it again, but using vectors. Let:
and again, is a scalar, the radius of the circle. The vector is parallel (and points in the same direction) to the vector , being the point we want to solve for. We know that , the length of is . And points in the same direction as . So let us scale to length :
Which is the right answer as well. That’s the solution I was looking for when I submitted this ‘puzzle’ to my friends.
So The second solution is much better than the first one. First, it doesn’t require that nor . Second, it doesn’t require solving an equation system. The most (computationally) complex step is to compute the length of which is only the euclidean distance between points and , given by
in 2D. Also, the solution is more general than the first one. Replace ‘circle’ by sphere, and 2D points by 3D points, and the expression for the solution remains the same. It remains the same regardless of the number of dimensions (except zero), actually.
The morale of this is that, sometimes, we must take a step back and look at the problem with a broader view, and use all of our knowledge to find the best possible solution, not just use the tools we are mentally more used to. For Ethan, solving the equation system was the natural way of proceeding, because that’s what he understood best. For me, it was the vector approach, because the formulation was, from the start, a vector-type problem: points, projection, etc. In many cases, the formulation of the problem will influence the way we will try to solve it and that’s why it’s so hard to come up with paradigm-shifting ideas; the mind-set for a problem can be so deeply set into one paradigm that it seems impossible to reformulate it in another and, once that it’s done, solve with more ease it using the other paradigm.
I think it applies to all sorts of problems, not only math problems. Algorithms. Programming. Life in general.