从枢轴点旋转矩形后如何获得矩形的方向(角度) [英] How to get the direction (angle) of rectangle after rotating it from a pivot point
问题描述
当从矩形中心旋转矩形时,通常只使用setRotate(double value)和getRotate()即可.假设如果getRotate()为0且我正试图获取其方向,则矩形朝北,我只是得到getRotate()的负数,并从360中获取其余数(如果为负数,则添加360).这意味着0度的角度面向北,然后将其顺时针旋转一个角度使其变为359度(同样,将其逆时针旋转一个角度将使其变为1度).
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;
}
但是,我现在的问题是我需要不从矩形的中心而是从枢轴点旋转矩形.我再也不能使用setRotate(double value)和getRotate()了,所以我不得不使用getTransforms().add(new Rotate(double angle,double axisX,double shaftY)).
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)).
现在,我的问题是我想知道矩形所面对的方向的角度,但是我不能再使用getRotate()了.即使我使用Rotate中的getAngle(),我仍然不知道如何获得其面向的方向,因为它没有从中心旋转.
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.
推荐答案
考虑到矩形只有一个旋转变换,您可以从变换中获取信息:
Considering you have only one rotate transform for your rectangle you can just get info from transform:
for (Transform transform : rectangle.getTransforms()) {
if (transform instanceof Rotate) {
return ((Rotate)transform).getAngle();
}
}
这篇关于从枢轴点旋转矩形后如何获得矩形的方向(角度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!