- Home /

# How to project a point on to a sphere?

If i have a point (x,y,z) how to project it on to a sphere(x0,y0,z0,radius) (on its surface). My input will be the coordinates of point and sphere. The output should be the coordinates of the projected point on sphere.

I found an answer! :D

```
public Vector3 ProjectOnSphere(Vector3 OriginalPosition, Vector3 SpherePosition, float radius)
{
Vector3 p = OriginalPosition - SpherePosition;
float pLenght = Mathf.Sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
Vector3 q = (radius / Mathf.Abs(pLenght)) * p;
Vector3 pointOnSphere = q + cameraPosition;
return pointOnSphere;
}
```

**Answer** by elenzil
·
Aug 23, 2018 at 07:22 PM

another answer would be

```
Vector3 projectedPoint = (pointPos - spherePos).normalized * sphereRadius + spherePos;
```

.. actually, now that i see that 'cameraPosition' should have been 'OriginalPosition', these are the same.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.