• 12
• 9
• 9
• 13
• 10

# Any point on a sphere

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

## 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 on other sites
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 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 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 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 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 on other sites
hmm not really, im plotting a set of objects, in the shape of a sphere, they arent to be joined

##### 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 on other sites
Quote:

float z = RADIUS*sin(yAngle);