# Cylinder arrangements

Hi,

I need to place cylinder in horizontal location i,e hollow spaces of the cylinder is placed on the top side and bottom side.

So that i don’t want to see the hollow spaces of the cylinder on my window.
To do this what coordinates i need to use ?

please sort me from this problem.

Hi anyone,

Is it possible to divide the cylinder surface into Triangular strips.

If possible means How it is ?

Cylinders seem to be all the rage on these forums

Have a read here, a lot of code available to copy/paste :

Hi Sir,

The link which you sent is to help how to draw Cylinder using gluCylinder() function.

Is it possible to draw cylinder Using Triangle strips ?

``````           or
``````

Is it possible to do cylinder surface like triangle strips ?

Yes of course it is possible.

In this picture, quad are used, but with 2 triangles you can easily draw 1 quad.

For the vertex coordinates, some trigonometry is needed, basically create frist vertex, add a vector v, place second vertex, rotate vector by 180-360/sides degres, etc until all sides are created.

Hi Sir,

As i am new to openGL, will you explain how the vectors are added?

will you give idea through Snippet of code.

The trig part is not really an opengl question, it is classic math.
Does this pseudo code helps ?

``````
double x = y = z = 0.0;
double vx = vy = vz = 0.0;
vx = 1;
double theta = (180-360.0/SIDES);
for (int i = 0;i<=SIDES;i++) {
double theta = i * (180-360.0/SIDES);
double tempvx = SLENGTH * (vx*cos(theta) + vy*sin(theta));
double tempvy = SLENGTH * (vy*cos(theta) - vx*sin(theta));
vx = tempvx;
vy = tempvy;
x += vx;
y += vy;
glVertex3d(x,y,z);
}

``````

First make it work to draw a circle with GL_LINES, then adapt this to store yourself each vertex and build a correct tristrip.

Hi Sir,

Thank you so much for reply.

By using the above pseudo code i wrote the code which is shown below :

``````

#include<stdlib.h>

#include<GL/glut.h>

#include<GL/glu.h>

#include<GL/gl.h>

#include<math.h>

int angle=0;

void cylinder()

{

GLint SIDES=20,i;

GLfloat SLENGTH=30.0;
double x, y , z;
x = y = z = 0.0;
double vx,vy,vz;
vx = vy = vz = 0.0;
vx = 1;
double theta = (180-360.0/SIDES);
glBegin(GL_LINES);
for (i = 0;i<=SIDES;i++) {

double theta = i * (180-360.0/SIDES);
double tempvx = SLENGTH * (vx*cos(theta) + vy*sin(theta));
double tempvy = SLENGTH * (vy*cos(theta) - vx*sin(theta));
vx = tempvx;
vy = tempvy;
x += vx;
y += vy;
glVertex3d(x,y,z);
}

glEnd();

}
void display()
{

glClear(GL_COLOR_BUFFER_BIT);

gluLookAt(45.0,45.0,25.0,-45.0,-45.0,-40.0,0.0,0.0,10.0);

cylinder();

glFlush();

angle+=1;

glutSwapBuffers();

}

int main(int argc,char **argv)
{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);

glutInitWindowSize(500,500);

glutInitWindowPosition(100,0);

glutCreateWindow("CYLINDER");

glutDisplayFunc(display);

glMatrixMode(GL_PROJECTION);

glOrtho(-100.0,100.0,-100.0,100.0,-100.0,100.0);

glMatrixMode(GL_MODELVIEW);

glClearColor(1.0,1.0,1.0,1.0);

glutMainLoop();

}

``````

This code is not generating the Cylinder with lines. i am not getting the problem