如何在圆周上旋转物体?

时间:2017-04-06 19:40:27

标签: java opengl jogl

我在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();
    }

1 个答案:

答案 0 :(得分:0)

您只需使用从

计算的位置绘制一个圆圈((cd assets && npm install)

rotateAroundOz()

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) positionOnCircumferenceInDegrees作为新功能的参数。

(这是我第一次回复SO:p希望它可以理解!)