Jump to content
• Advertisement

# Any point on a sphere

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hi, could somone point me in the right direction to calculating any point on a sphere, given the radius of the sphere. Im wanting to "plot" a sphere by looping through each point on the sphere. Regards Asheh

#### Share this post

##### Share on other sites
Advertisement
Do you mean: random point on a sphere?

Or do you want to generate a sequence of points of a sphere in some uniform manner?

#### Share this post

##### Share on other sites
P=C+D*r where P is a point on the sphere, D is a random direction (normalized), r is the radius of the sphere and C is the center of your sphere.

#### Share this post

##### Share on other sites
Quote:
 could somone point me in the right direction to calculating any point on a sphere, given the radius of the sphere.Im wanting to "plot" a sphere by looping through each point on the sphere.

Some clarity please, a sphere has <insert very very large number here> of points which lie on its surface. It sounds like you are asking how to find all the points and then plot them.

A point lies on the surface of a sphere if the magnitude of the vector between the point and the center of the sphere is equal to the spheres radius.

#### Share this post

##### Share on other sites
Quote:
 Original post by defferDo you mean: random point on a sphere?Or do you want to generate a sequence of points of a sphere in some uniform manner?

the latter, yes

#### Share this post

##### Share on other sites
Quote:
Original post by Asheh
Quote:
 Original post by defferDo you mean: random point on a sphere?Or do you want to generate a sequence of points of a sphere in some uniform manner?

the latter, yes

As I can see, you don't seek for plotting points, but to build a sphere from triangles. From then, you can plot only points of the triangles, or draw full-blown sphere.
A search for "sphere triangulation" gives this thread, for example.

#### Share this post

##### Share on other sites
hmm not really, im plotting a set of objects, in the shape of a sphere, they arent to be joined

#### Share this post

##### Share on other sites
Let's first look at approximating a circle with some points: (In C++, though you could probably figure out any other language from this)

for(int i = 0; i < MAX_POINTS; i++){    float angle = i/MAX_POINTS * 2 * PI;    //Calculates the point's position    float x = cos(angle)*RADIUS;    float y = sin(angle)*RADIUS;    AddPoint(x,y);//Adds the point to your list, or plots it, or does whatever you want to do with the point}

Okay, that's pretty simple. It just loops through MAX_POINTS number of angles in a circle and plots point RADIUS away from the origin.

Now, for a sphere, we'll start with the same code as before. However, now we have to make a new circle every loop instead of a circle. We'll achieve this with two nested loops:

for(int i = 0; i < MAX_POINTS; i++){    //The angle around the equator:    float xAngle = i/MAX_POINTS * PI;//Note: No longer multiply by 2    //Now create a circle that intersects     for(int j = 0; j <  MAX_POINTS; j++)    {        float zAngle = j/MAX_POINTS * 2 * PI;        //Calculates the point's position        float x = cos(xAngle)*RADIUS*cos(yAngle);        float y = sin(xAngle)*RADIUS*cos(yAngle);        float z = cos(xAngle)*RADIUS*sin(yAngle);        AddPoint(x,y,z);    }}

Notice how the first loop only loops to PI, not to 2 PI. This is because a circle also covers the part of the circle opposite from the first point, hence we only have to go half-way around. Also, I haven't tested this, and actually just 'guessed' the last half.

Hope that helps (and works)!

[Edit: changed ints to floats.]

#### Share this post

##### Share on other sites
Quote:
 //Calculates the point's position float x = cos(xAngle)*RADIUS*cos(yAngle); float y = sin(xAngle)*RADIUS*cos(yAngle); float z = cos(xAngle)*RADIUS*sin(yAngle);

That should read:
float z = RADIUS*sin(yAngle);

#### Share this post

##### Share on other sites
note that the method suggest is NOT uniform. You need to find any (rectangular) equal area projection of the sphere and generate coordinates on the map.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5
• Advertisement

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631759
• Total Posts
3002138
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!