使用Opengl创建这个半圆弧设计。通过改变θ来创建不同的弧

时间:2014-03-16 11:29:12

标签: opengl

我正在尝试使用OpenGl绘制此设计。我可以用θ从0到3.14绘制半圆弧。我需要知道如何在不同的轴上绘制半圆。我试着尝试theta但我无法获得理想的结果。我还需要一些帮助来理解如何构造不同长度的弧。

enter image description here

void circle(float xc,float yc,float a, float b,float c,float r,float u,float v)
{
  a=rand()%10;
  b=rand()%10;
  c=rand()%10;
  a=(a/100);b=(b/100);c=(c/100);

  int three;
    three=rand()%3;
  if(three==0)
    {
      a=1;
    }
  else if(three==1)
    {
      b=1;
    }
  else
    c=1;

  glColor3f(a,b,c);

  glBegin(GL_POINTS);
  float x,y;
  float theta=0,dtheta;
  dtheta=(1/r);
  for(theta=u;theta<(v);theta=theta+dtheta)
    {
      x=xc+r*cos(theta);
      y=yc+r*sin(theta);
      glVertex2i(x,y);
        glFlush();

    }

  glEnd();
  glFlush();

}

void mydisplay()
{
  float a,b,c;
  srand(time(NULL));
  a=rand()%20;
  b=rand()%20;
  c=rand()%20;
  a=a/100;b=b/100;c=c/100;
  glClearColor(a,b,c,0.0f);
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_POINTS);
  float xc=205.00,x,yc=205.00,y;
  float theta=0,dtheta,r=2;
  dtheta=(3.14/50);

  int three;
  a=rand()%10;
  b=rand()%10;
  c=rand()%10;
  a=(a/100);b=(b/100);c=(c/100);
  three=rand()%3;
  if(three==0)
    {
      a=1;
    }
  else if(three==1)
    {
      b=1;
    }
  else
    c=1;
  for(r=1;r<=100;r=r+5)
    {
      x=xc+r*cos(theta);
      y=yc+r*sin(theta);
      circle(x,y,a,b,c,r,0,3.14);
        glFlush();
    }
  glEnd();

  glFlush();
      sleep(1);
  glutPostRedisplay();

}

1 个答案:

答案 0 :(得分:0)

void circle(float a, float b,float c,float r,float u,float v,float chy,float chx)
{
  a=rand()%10;
  b=rand()%10;
  c=rand()%10;
  a=(a/100);b=(b/100);c=(c/100);

  int three;
    three=rand()%3;
  if(three==0)
    {
      a=1;
    }
  else if(three==1)
    {
      b=1;
    }
  else
    c=1;

  glColor3f(a,b,c);

  glBegin(GL_POINTS);
  float x,y,xc=205+chx,yc=205 + chy;
  float theta=0,dtheta;
  dtheta=(1/r);
  for(theta=u;theta<(v);theta=theta+dtheta)
    {
      x=xc+r*cos(theta);
      y=yc+r*sin(theta);
      glVertex2i(x,y);
        glFlush();

    }

  glEnd();
  glFlush();

}

void mydisplay()
{
  float a,b,c;
  srand(time(NULL));
  a=rand()%20;
  b=rand()%20;
  c=rand()%20;
  a=a/100;b=b/100;c=c/100;
  glClearColor(a,b,c,0.0f);
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_POINTS);
  float xc=205.00,x,yc=205.00,y;
  float theta=0,dtheta,r=2;
  dtheta=(3.14/50);

  int three;
  a=rand()%10;
  b=rand()%10;
  c=rand()%10;
  a=(a/100);b=(b/100);c=(c/100);
  three=rand()%3;
  if(three==0)
    {
      a=1;
    }
  else if(three==1)
    {
      b=1;
    }
  else
    c=1;

  for(r=1;r<=100;r=r+5)
    {
      x=xc+r*cos(theta);
      y=yc+r*sin(theta);
      circle(a,b,c,r,0,3.14,0,r);
        glFlush();
    }
    for(r=1;r<=100;r=r+5)
    {
      x=xc+r*cos(theta);
      y=yc+r*sin(theta);
      circle(a,b,c,r,-3.14/2,-(3.14/2)+3.14,-r,0);
        glFlush();
    }
    for(r=1;r<=100;r=r+5)
    {
      x=xc+r*cos(theta);
      y=yc+r*sin(theta);
      circle(a,b,c,r,3.14/2,(2*3.14)-(3.14/2),r,0);
        glFlush();
    }
    for(r=1;r<=100;r=r+5)
    {
      x=xc+r*cos(theta);
      y=yc+r*sin(theta);
      circle(a,b,c,r,3.14,(2*3.14),0,-r);   
        glFlush();
    }
  glEnd();

  glFlush();
  sleep(1);
  glutPostRedisplay();

}