旋转后的线位置 - 摆动

Line position after a rotation - Swing

我需要计算直线方向向量的笛卡尔方程。用户可以像这样自由旋转视角


观点


观点2


如果我知道直线的两个点就容易了,但是点旋转后我找不到正确的位置,似乎直线的位置保持不变,我不太明白Graphics2D是如何实现的rotate works.Here 是一段代码。

g3.rotate(Math.toRadians(Double.valueOf(getJtfRotationAngle().getText()))
        ,eye.getEyePos().getX_pos()
        ,eye.getEyePos().getY_pos());

g3.setColor(Color.BLACK);

g3.draw(new Line2D.Double(eye.getEyePos().getX_pos(),eye.getEyePos().getY_pos()
        ,eye.getEyePos().getX_pos()+25,eye.getEyePos().getY_pos()));
g3.draw(new Line2D.Double(eye.getEyePos().getX_pos(),eye.getEyePos().getY_pos()
        ,eye.getEyePos().getX_pos(),eye.getEyePos().getY_pos()+25));

//This line is the orientation vector
g3.draw(new Line2D.Double(eye.getEyePos().getX_pos()
        ,eye.getEyePos().getY_pos()
        ,eye.getEyePos().getX_pos()+25
        ,eye.getEyePos().getY_pos()+25));

g3.drawOval((int)eye.getEyePos().getX_pos(),(int)eye.getEyePos().getY_pos(),10,10);
g3.fillOval((int)eye.getEyePos().getX_pos(),(int)eye.getEyePos().getY_pos(),10,10);

eye.setEyeTruePos(new Point(eye.getEyePos().getX_pos()-x_pos/2,eye.getEyePos().getY_pos()-y_pos/2));

提前感谢您的answer/explanation。

Graphics2D 的旋转是这样的:

translate(x, y);
rotate(theta);
translate(-x, -y);

因此,您对原始线应用相同的转换以获得两个新点:

tx=px+x;
ty=py+y;
rx=tx*Math.cos(a)-ty*Math.sin(a);
ry=.....
pnewx=rx-x;
pnewy=ry-y;

另一个点(px, py)也一样。