Algorithm (Cylinder):
Step 1: Start
Step 2: Let (h, k) be the central axis of cylinder.
Step 3: Let ‘r’ be the radius of cylinder.
Step 4: For each pair (h, k), find all the points on the circle with (h, k) as center.
Step 5: Display these points which make a circle.
Step 6: Increment the y-coordinate by some constant to draw the next adjacent circle.
Step 7: Repeat Step 6
Step 8: Stop
Algorithm (parallelepiped)
Step 1: Start
Step 2: Let (x1, y1), (x2, y1), (x1, y2), (x2, y2) be the four vertices of a rectangle.
Step 3: Draw a rectangle with these values using a line loop primitive.
Step 4: Increment all the eight values by some constant value to draw next adjacent rectangle.
Step 5: RepeatStep 4
Step 6: Stop
#include
#include
#include
GLint xc,yc,r,i,n=50,num_segments=50;
GLint a,b,c,d;
void DrawCircle(float cx, float cy, float r, int num_segments)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
for(int ii = 0; ii < num_segments; ii++)
{
float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle
float x = r * cos(theta);//calculate the x component
float y = r * sin(theta);//calculate the y component
glVertex2f(x + cx, y + cy);//output vertex
}
glEnd();
}
void cylinder_draw()
{
for(i=0;i
