答案 0 :(得分:1)
[cos(a) -sin(a)]
[sin(a) cos(a)]
因此x,y
旋转的是:
rx = x*cos(a) + y*sin(a);
ry = -x*sin(a) + y*cos(a);
因为另一条线是90度,所以评估为:
rx = y;
ry = -x;
所以:
(x1,x2,y1,y2) => (y1,y2,-x1,-x2)
我会使用Point
类来存储它并将其放在一个方法中:
public static Point Rotate90(Point point){
return new Point(point.y, -point.x);
}
现在关于原点的轮换,如果你的线需要触摸另一条线,那么你需要在前后翻译。
p = x,y
pr = centre of rotation
关于p
:
pr
Rotate90(p - pr) + pr
在方法中:
public static Point Rotate90(Point point, Point about){
Point translated = new Point(point.x - about.x, point.y - about.y);
Point rotated = Rotate90(translated);
return new Point(rotated.x + about.x, rotated.y + about.y);
}