2017-04-06 103 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

你必須使用你從

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) 

計算位置,以便您可以添加positionOnCircumferenceInDegreesdrawnCircle_Radius爲參數,爲您的新功能來畫一個圓(與rotateAroundOz()) 。

(這是我對SO的第一個迴應:希望它能被理解!)