15,029,990 members
See more:
Can anyone help me how to draw a circle similar to one in the image, such that M is greater than N using open gl v1.5 for android

[IMG]http://i49.tinypic.com/254y5bs.png[/IMG]
Posted
Sandeep Mewara 7-Jul-12 6:05am

What have you tried so far?
Amarnath S 7-Jul-12 9:37am

Though I can't tell you the exact function names in OpenGL, there are basically two functions you'll have to use:
1. Line function (two calls) - to draw two radial lines shown in your figure
2. Arc function - to draw the circular arc in your figure.

One thing still needs clarification - You mention that M is greater than N - this means that their meeting point is not at the centre of the arc. Have you got a mathematical formula for that point?

## Solution 1

Lots of suggestions easy to find[^].

## Solution 2

C#
```int RADIUS = 2;
float DEGREE_TO_RAD = 3.14 / 180;
glBegin( GL_LINE_LOOP );
glVertex2f( 0,0 );
int M_IN_DEGREE = 370;
int N_IN_DEGREE = 100;
for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
{
float fX = sin((float)nR * DEGREE_TO_RAD ) ;
float fY = cos((float)nR * DEGREE_TO_RAD );
glVertex2f( fX, fY );
}
glEnd();
```

With glDrawArrays
C#
```int M_IN_DEGREE = 370;
int N_IN_DEGREE = 100;
int nCount = 1;
float stVertexArray[2*360];

stVertexArray[0] = 0.0;
stVertexArray[1] = 0.0;

for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
{
float fX = sin((float)nR * DEGREE_TO_RAD ) ;
float fY = cos((float)nR * DEGREE_TO_RAD );
stVertexArray[nCount*2] = fX;
stVertexArray[nCount*2 + 1] = fY;
nCount++;
}

glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, 0, stVertexArray );
glDrawArrays( GL_LINE_LOOP, 0, nCount );```
v2
monerajesh 10-Jul-12 9:34am

hi, I cant use the glBegin and glEnd in my code..I draw to the surface view using gl.glDrawArrays and use gl. in every line to usea property in the onDrawFrame(GL10 gl) method..please guide me as to how to draw using the code you gave..I am a beginner in openGL..help is appreciated.
Santhosh G_ 10-Jul-12 12:48pm

Please prepare vertex buffer with fX and fY values, and call it with glDrawArrays. Please try the following code..

int M_IN_DEGREE = 370;
int N_IN_DEGREE = 100;
int nCount = 1;
float stVertexArray[2*360];

stVertexArray[0] = 0.0;
stVertexArray[1] = 0.0;

for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
{
float fX = sin((float)nR * DEGREE_TO_RAD ) ;
float fY = cos((float)nR * DEGREE_TO_RAD );
stVertexArray[nCount*2] = fX;
stVertexArray[nCount*2 + 1] = fY;
nCount++;
}

glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, 0, stVertexArray );
glDrawArrays( GL_LINE_LOOP, 0, nCount );
monerajesh 15-Jul-12 16:39pm

this is how I implemented your code..but the result is a light green colored screen with no circle
int M_IN_DEGREE = 370;
int N_IN_DEGREE = 100;
int nCount = 1;
float[] stVertexArray=new float[2*360];
FloatBuffer sampleBuffer;

stVertexArray[0] = (float) 0.0;
stVertexArray[1] = (float) 0.0;

for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
{
float fX = (float) Math.sin((float)nR * (45*(Math.PI/180)) ) ;
float fY = (float)Math.cos((float)nR * (45*(Math.PI/180)) ) ;
stVertexArray[nCount*2] = fX;
stVertexArray[nCount*2 + 1] = fY;
nCount++;
}
ByteBuffer bBuff = ByteBuffer.allocateDirect(stVertexArray.length * 4);
bBuff.order(ByteOrder.nativeOrder());
sampleBuffer = bBuff.asFloatBuffer();
sampleBuffer.put(stVertexArray);
sampleBuffer.position(0);

gl.glEnableClientState( GL10.GL_VERTEX_ARRAY );
gl.glVertexPointer( 2, GL10.GL_FLOAT, 0, sampleBuffer );
gl.glDrawArrays( GL10.GL_LINE_LOOP, 0, nCount );