sphere from parametric equation

Started by
0 comments, last by tidy 16 years, 5 months ago
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
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.

This topic is closed to new replies.

Advertisement