2017-04-06 12 views
0

oepnGL java에서 원을 그리기위한 함수를 만들었으며 원의 원주에서 다른 원을 회전시키고 싶습니다.원의 원주에서 객체를 회전하는 방법은 무엇입니까?

내 원을 그리는 함수입니다. 둘레를 원으로 그리려면 어떻게해야합니까?

예를 들어 첫 번째 원에서 중심 좌표 점으로 새 원을 만드시겠습니까?

private void rotateAroundOz(GL2 gl, int r, double cx, double cy) { 
     int step = 1; 

     gl.glLineWidth(5); 
     gl.glBegin(GL.GL_LINE_LOOP); 
      for (int i=0; i<360; i+=step) { 
       gl.glColor3d(1, 0, 0); 
       gl.glVertex2d(cx + r * Math.cos(Math.toRadians(i)), cy + r * Math.sin(Math.toRadians(i))); 
      } 
     gl.glEnd(); 
    } 

답변

0
당신은 너무 당신의 새로운 기능에 대한 매개 변수로 positionOnCircumferenceInDegreesdrawnCircle_Radius을 추가 할 수 있습니다 당신이

cx + r * Math.cos(Math.toRadians(i)), cy + r * Math.sin(Math.toRadians(i))

// This is the attributes of the invisible circle: "PositionCircle" 
//that will gives you the circumference 
float positionCircle_Radius = 1.0; 
float positionCircle_CenterX = 0.0; 
float positionCircle_CenterY = 0.0; 

// This is actually the circle that you want to draw from the 
// "PositionCircle" 
int positionOnCircumferenceInDegrees = 90; 
float drawnCircle_Radius = 2.0; 
float drawnCircle_CenterX = positionCircle_CenterX + positionCircle_Radius * Math.cos(Math.toRadians(positionOnCircumferenceInDegrees)); 
float drawnCircle_CenterY = positionCircle_CenterY + positionCircle_Radius * Math.sin(Math.toRadians(positionOnCircumferenceInDegrees)); 

rotateAroundOz(gl, drawnCircle_Radius, drawnCircle_CenterX, drawnCircle_CenterY) 

에서 계산 위치를 사용하여 (rotateAroundOz() 포함) 원을 그립니다해야

.

(내 첫 번째 답변은 다음과 같습니다. 이해할 수 있기를 바랍니다.)