如何获取矩形从枢轴点旋转后的方向(角度)
当从中心旋转矩形时,我通常只使用 setRotate(double value) 和 getRotate() 。假设一个矩形朝北,如果 getRotate() 为 0,并且我试图获取它的方向,我只需获取 getRotate() 的负值并从 360 中获取其余数(如果为负值,我添加 360)。这意味着 0 度的角度面向北,顺时针旋转 1 度就会变成 359 度(同样,逆时针旋转 1 度就会变成 1 度)。
public double angle(){
double angle = -rectangle.getRotate();
if(angle<0){ angle += 360; }
return angle%360;
}
然而,我现在的问题是我需要不是从其中心而是从枢轴点旋转矩形。我不能再使用 setRotate(double value) 和 getRotate() ,所以我必须使用 getTransforms().add(new Rotate(double angle, doubleivotX, doubleivotY))。
现在,我的问题是我想知道矩形面向的方向的角度,但我不能再使用 getRotate()。即使我使用旋转中的 getAngle() ,我仍然不知道如何获取它所面对的方向,因为它没有从中心旋转。
I normally just use setRotate(double value) and getRotate() when rotating a rectangle from its center. Suppose a rectangle is facing North if the getRotate() is 0 and I'm trying to get its direction, I simply get the negative of the getRotate() and get its remainder from 360 (if it's negative, I add 360). Which means that an angle of 0 degrees faces North, and rotating it clockwise by a degree makes it 359 degrees (likewise, rotating it counter-clockwise by a degree makes it 1 degree).
public double angle(){
double angle = -rectangle.getRotate();
if(angle<0){ angle += 360; }
return angle%360;
}
However, my problem now is that I need to rotate the rectangle not from its center but from a pivot point. I can't use setRotate(double value) and getRotate() anymore so I have to use getTransforms().add(new Rotate(double angle, double pivotX, double pivotY)).
Now, my problem is that I want to know the angle of the direction where the rectangle faces but I can no longer use getRotate(). And even if I use the getAngle() from the Rotate, I still don't know how to get the direction it faces because it wasn't rotated from the center.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑到您的矩形只有一个旋转变换,您可以从变换中获取信息:
Considering you have only one rotate transform for your rectangle you can just get info from transform: