Sam Borov
Sam Borov

Reputation: 37

OpenGL semicircular rotation and quarter circle

The following code will create a new semicircular using openGL:

    glPointSize(2);
    glBegin(GL_POINTS);
    for (float i = p; i <= (2 * p); i += 0.001) {
        x = 50.0 * cos(i) + 20;
        y = 50.0 * sin(i) + 20;
        glVertex2f(x, y);
    }
    glEnd();

Now I want to know how to change this code and create a quarter circle using this format? Also, is this possible to rotate the shape using this format and without of using GLrotateEF?

Upvotes: 1

Views: 232

Answers (1)

orlp
orlp

Reputation: 117731

Here i is the angle in radians. The loop goes from π to 2π—this is a semicircle (but the second half of it - a bit ill-defined).

To turn it into a quarter circle loop from 0 to π/2. To rotate the circle by x degrees, convert it to radians and add to the angle.

Alternatively you can draw a portion of a circle by simply defining where it should start, and where it should stop, in angles:

double start_angle = 30;
double stop_angle = 30 + 180;
for (double a = start_angle; a <= stop_angle; a += 0.001) {
    double a_rad = a / 180.0 * p;
    x = 50.0 * cos(a_rad) + 20;
    y = 50.0 * sin(a_rad) + 20;
    glVertex2f(x, y);
}

Upvotes: 2

Related Questions