draw Arc OpenGL - Java 2D Graphics

Java examples for 2D Graphics:Arc

Description

draw Arc OpenGL

Demo Code


import javax.media.opengl.GL2;

public class Main{
    public static void drawArc(GL2 gl2, double x, double y, double z,
            double r1, double r2, double start, double end, int seg,
            int step) {
        double ang;
        if (start <= end)
            ang = (end - start) / (double) seg;
        else/*  w  w w .  j a  v  a2 s.c  o  m*/
            ang = (360 - (start - end)) / (double) seg;

        gl2.glBegin(GL2.GL_TRIANGLE_STRIP);
        for (int i = 0; i <= seg; i += step) {
            double rx = r1 * Math.cos((start + ang * i) * Math.PI / 180.0);
            double ry = r1 * Math.sin((start + ang * i) * Math.PI / 180.0);
            gl2.glVertex3d(x + rx, y + ry, z);

            double rx2 = r2 * Math.cos((start + ang * i) * Math.PI / 180.0);
            double ry2 = r2 * Math.sin((start + ang * i) * Math.PI / 180.0);
            gl2.glVertex3d(x + rx2, y + ry2, z);
        }
        gl2.glEnd();
    }
    public static void drawArc(GL2 gl2, double x, double y, double z,
            double r1, double r2, double start, double end, int seg) {
        drawArc(gl2, x, y, z, r1, r2, start, end, seg, 1);
    }
}

Related Tutorials