Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8996515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:45:53+00:00 2026-06-15T23:45:53+00:00

I am trying to create a solid cylinder using triangle fan. What I’ve done

  • 0

I am trying to create a solid cylinder using triangle fan.
What I’ve done so far is this:

float base = 0.5;
float height = 20;
float radius = 2.0f;
glBegin(GL_TRIANGLE_FAN);
for(float j=0; j<=height; j+=0.1)
{
    glVertex3f(0,j,0);
    for(int i=0; i<360; i++)
    {
        glVertex3f(radius*sin((float)i),j, radius*cos((float)i));
    }   
}
glEnd();
glPopMatrix();

The problem appears in these 3 screenshots:

enter image description here
As you see in all 3 screenshots there appears to be some space and not a solid cylinder.
Is that ok?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:45:54+00:00Added an answer on June 15, 2026 at 11:45 pm

    First thing you should pay attention to (Edit: I slightly misread your code. You are doing fine with the triangle fan) is that a triangle fan works like this:

    glVertex: Center point
    for each outer point p
        glVertex: p
    

    For example:

                      p2__
                     /|   ---___p1
                    /  |         /
                   /    |       /
                p3/      |     /
                  |\      |   /
                  |   \    | /
                   |     \_O   Center
                   | __---
                   p4
    

    Second thing is that a cylinder consists of three parts:

                   __
                  /  \
                  \__/        <---- circle on top (facing up)
                  |  |
                  |  |
                  |  |
                  |  |        <---- tube in the middle
                  |  |
                  |  |
                  |  |
                  \__/        <---- circle on the bottom (facing down)
    

    So the algorithm you need is:

    /* top triangle */
    glBegin(GL_TRIANGLE_FAN);
        glVertex3f(0, height, 0);  /* center */
        for (i = 0; i <= 2 * PI; i += resolution)
            glVertex3f(radius * cos(i), height, radius * sin(i));
    glEnd();
    
    /* bottom triangle: note: for is in reverse order */
    glBegin(GL_TRIANGLE_FAN);
        glVertex3f(0, 0, 0);  /* center */
        for (i = 2 * PI; i >= 0; i -= resolution)
            glVertex3f(radius * cos(i), 0, radius * sin(i));
        /* close the loop back to 0 degrees */
        glVertex3f(radius, height, 0);
    glEnd();
    
    /* middle tube */
    glBegin(GL_QUAD_STRIP);
        for (i = 0; i <= 2 * PI; i += resolution)
        {
            glVertex3f(radius * cos(i), 0, radius * sin(i));
            glVertex3f(radius * cos(i), height, radius * sin(i));
        }
        /* close the loop back to zero degrees */
        glVertex3f(radius, 0, 0);
        glVertex3f(radius, height, 0);
    glEnd();
    

    The way you were trying to do is first, not correct, since you are not actually making a cylinder, but stacking many circles, and second is inefficient since you are filling in space that is mostly invisible (the inside of the cylinder).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a mouseover animation using this code: var menu = {
I'm trying to create a pointy button like this: So far, I was only
I'm trying to create a dialog window using JQuery. I'm making progress so far,
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create a background-image slideshow and am getting this error... This is the
I'm trying to create a pure CSS triangle for a tooltip. All browsers looks
I need help on this. I'm trying to create a simple progress bar based
I'm using the JQuery Draggable plugin . I'm trying to create an Image Editing
I am trying to create a live wallpaper using opengl (<2.0). I imported and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.