How to make half circle in opengl

I use this method, which works great to draw a full circle (there may be typos in the text of the code I wrote from memory):

drawCircle(GLAutodrawble drawble){ GL gl = drawble.getGL(); gl.glTranslatef(0.0f,0.0f,-7.0f); gl.glBeginf(GL_LINE_LOOP); gl.glColorf(0.0f,0.0f,0.0); final dobule PI = 3.141592654; double angle = 0.0; int points = 100; for(int i =0; i < points;i++){ angle = 2 * PI * i / points; gl.glVertexf((float)Math.cos(angle),(float)Math.sin(angle)); } gl.glScalef(1.0f,1.0f,0.0f); gl.glEnd(); } 

I want to use the same prefixes to make a method to make half a circle, I don’t understand what I have to do with cos sin material. Can someone take a look and help me.

Thanks to everyone who looks at the problem!

+4
source share
3 answers

Replace:

 angle = 2 * PI * i / points; 

Via:

 angle = PI * i / points; 

Note. I removed the factor of 2 since 2 * PI is 360 (in degrees), which is a full circle. PI (180 degrees) - half circle

+5
source

Change this line:

 angle = 2 * PI * i / points; 

:

 angle = 1 * PI * i / points; 
+2
source

The drawing cycle is similar to drawing lines connecting them. And the points should be too close together to create a smooth curve. you can use the following code to draw a semicircle in opengl.

  float PI = 3.14 float step=5.0;// How far is the next point ie it should be small value glBegin(GL_LINE_STRIP) for(float angle=0.0f,angle<=180; angle+=step) { float rad = PI*angle/180; x = centerX+radius*cos(rad); y = centerY+radius*sin(rad); glVertex(x,y,0.0f); } glEnd(); 
0
source

Source: https://habr.com/ru/post/1412231/


All Articles