Results 1 to 5 of 5

Thread: How to draw regular polygon?

  1. #1
    Guest

    How to draw regular polygon?

    I don't know how to calculate the vertex out in order to draw n side polygon when the user enter a number(ie n)

    please give me some idea
    thanks

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Chicago, IL US
    Posts
    101

    Re: How to draw regular polygon?

    Is it possible to use a for loop around glVertex within a glBegin/End block for what you are doing?

  3. #3
    Guest

    Re: How to draw regular polygon?

    I would like to caculate the vertex of regular polygon

    here is the equation I found

    vi = ( (R cos (2(i-1)/N)), (R sin (2(i-1)/N)) ) for i = 1, 2, ... N.

    but I cannot find any function to implement the pi, sine and cosine function

  4. #4
    Guest

    Re: How to draw regular polygon?

    sorry~~
    I think i ask an stupid question. It should be found in programming language

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to draw regular polygon?

    I wrote a little routine that would produce a list of vertex points, based on the number of sides inputed.


    n = 3 = triangle
    n = 4 = square
    etc.
    With enought points start to look like a circle.


    void buildquad( int sides, Point3F polygon[])
    {
    float angle, xangle;
    float x, y, z;
    float r;
    int i;

    r = 2.0f;
    xangle = 3.1415927f / sides;


    for (i=0; i <= sides; i++)
    {
    angle = xangle * i * 2;
    polygon[i].xyz[0] = r * cos( angle ); // X
    polygon[i].xyz[1] = r * sin( angle ); // Y
    polygon[i].xyz[2] = 0.0f; // Z
    }
    polygon[i] = polygon[0];

    }

Similar Threads

  1. polygon draw
    By ccouto in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-01-2012, 04:21 AM
  2. How to draw a polygon in OpenGL ES ?
    By anime.igala.net in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-18-2009, 08:33 AM
  3. Draw polygon
    By Never in forum OpenGL: General
    Replies: 1
    Last Post: 03-20-2008, 09:37 AM
  4. Draw polygon
    By Never in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-18-2008, 08:00 PM
  5. Replies: 1
    Last Post: 01-23-2002, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean