# How can I calculate the new vector of an object trying to push into (move along) the ground?

Say I have a sphere (planet). If I have object on the surface, I want to limit movement so that it can only travel in directions along or above the surface.

Imagine a coin on a table. If I were to push the coin from up above at an angle, the table would cancel out any downward vector component and the coin would move in 2 dimensions across the table. This is what I would like to achieve.

In the case of a planet (sphere) then I can calculate the cancelling vector to some extent (this is just the line from the centre of the sphere to the point on the surface).

Now I struggle - how do I calculate the magnitude of the opposing vector such that it is sufficient to stop the object falling through the surface but not too big that it starts to launch the object away from the surface?

This is called a "normal force" because it acts along the surface's normal (perpendicular) direction.

If you know the net forces acting on the object $\vec F_{Net}$, and have a unit (length = 1) normal vector $\vec n$ pointing out of the surface, then...

$$\vec F_{Normal} = max\left( 0, -\vec F_{Net} \cdot \vec n \right) \cdot \vec n$$

or in pseudo-code:

F_normal = max(0f, -Dot(F_net, n)) * n


This gives a vector pointing out from the surface with exactly enough length to cancel out the component of the net force pushing into the surface (or zero, if the net force is pushing parallel/outward from the surface)

• Thank you for this - are the dots in the above equation matrix dot products in both cases? For example, would I get the dot product of -Fnet x n, then get the dot product of that result and n? Do you know of any "vector cookbook" books or sites? – SparkyNZ Apr 1 '18 at 1:12
• The one inside the parentheses is a scalar product of two vectors (a dot product). The one outside the parentheses is a vector being multiplied by a scalar. – DMGregory Apr 1 '18 at 1:15
• Its been 28 years since I did this - time for revison on scalars, dot products and cross products I think, – SparkyNZ Apr 1 '18 at 1:18
• Sorry I don't understand. Outside the parenthesis we are multiplying by 'n' but 'n' itself is a vector isn't it? (I thought a scalar was just a constant). So wouldn't the outer operation be a cross product? – SparkyNZ Apr 1 '18 at 1:33
• The result of the dot product is a scalar. Then we take the max of that scalar and zero, which is also a scalar. So we have a scalar output from the max function on the left, and a vector on the right, so we're just scaling that unit vector to a new length. – DMGregory Apr 1 '18 at 1:35