• Advertisement
Sign in to follow this  

sphere from parametric equation

This topic is 3735 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 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[0] = gmtl::Math::sqrt( (radius*radius) - (i * i) ) * gmtl::Math::cos(theta);

tempSpherePt[1] = gmtl::Math::sqrt( (radius*radius) - (i * i) ) * gmtl::Math::sin(theta);

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement