Any point on a sphere

Started by
15 comments, last by Fred304 17 years, 5 months ago
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
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?
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.
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.

Quote:Original post by deffer
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?


the latter, yes
Quote:Original post by Asheh
Quote:Original post by deffer
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?


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.
hmm not really, im plotting a set of objects, in the shape of a sphere, they arent to be joined
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.]
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);

We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
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.

This topic is closed to new replies.

Advertisement