# Direction to get to Point on Sphere

This topic is 4931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

OKay here is the problem: I have a sphere and an ant landed on top of it Collision keeps the ant from moving into the sphere I want the ant to go towards a point on the sphere I can get the direction vector, but unless it's close the ant just trys to go though the sphere. So how do I take this direction vector and make it a tanget vector on the sphere using the sphere normal?

##### Share on other sites
Well there might be an easier way, but the way I'd do it:

You can get the tangent plane at the point on the sphere where the ant is at by using the sphere normal as the plane normal and then the ant position as the point (plane is defined by a point and a normal)

Now, calculate the point on this plane closest to the desired point.

The new direction vector for the ant can be calculated by subtracting the ant position from this point and normalizing

##### Share on other sites
The easiest way to go about this is simply use the vector from the sphere's center to the point of collision as the normal.

This is easiest of your sphere is centered at (0, 0, 0).

So, if the radius is 1 for example, then you have x^2 + y^2 + z^2 = 1^2 = 1.

So if the point of collision is (a, b, c), it obviously satisfies a^2 + b^2 + c^2 = 1. Now, the normal would be the vector (a, b, c), so the plane would be:

ax + by + cz = d, and you can get d easily since a = x, b = y, and c = z.
x^2 + y^2 + z^2 = d, so d happens to be the radius of the sphere squared.

Now, any vector on that plane will be tangent to the sphere. You can find the two direction vectors that define the plane by substituting two values of z, y and z, and finding the third. Obviously, if you have any zero coefficients, you would substitue their associated variables first to ensure the plane you're finding exists. Finally, knowing the first direction vector of the tangent plane (call it u), take u X (a, b, c) to find the second direction vector (v).

Any linear combinations of u and v, when added to the vector (a, b, c) will be on the plane tangent to sphere at point (a, b, c). Knowing that, you can move around the sphere, recalculating direction often, and any way you choose relative to the plane.

##### Share on other sites
ahh just what i needed, much thanks!

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633654
• Total Posts
3013171
×