# sphere from parametric equation

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

## Recommended Posts

Hi i am trying to draw a sphere from scratch. I am using the parametric equation of the sphere. x = sqrt( r*r - u*u ) cos angle; y = sqrt( r*r - u*u ) sin angle; z = u where u = -r to r angle = 0 to 2*PI r = radius I am not using the glusphere function as eventually i need to show lines piercing into the sphere and passing throug the center. And for that i need points which lie on the surface on the sphere(which would act as origin of the line) which i think i cannot get from glusphere. I am unable to produce a sphere from the above code. Some weird stuff coming up.
for(float i = -radius, theta = 0; i <= radius, theta <= 360; i += 0.01, theta += 5)
{

tempSpherePt[2] = i;

mpApp->spherePoints.push_back(tempSpherePt);

}

Could you please tell me the problem with the code or any other way i could implement the funcionality i need to implement ? Utk

##### Share on other sites
I think you may be stepping theta in degrees, but the sin & cos functions expect angles in radians.

Also your single for loop looks a little odd - it may be easier to follow if you split it into 2 nested loops, 1 which steps theta and one which steps i.

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009399
• ### Who's Online (See full list)

There are no registered users currently online

×