[英]Rotating Rectangle and calculating corner
我正在旋轉一個矩形,現在想要計算左上角的新位置。
我目前的計算是:
Point upLeft = new Point(
// x-coordinate
(int) Math.round((oldx * Math.cos(objectAngleRad))
- (oldy * Math.sin(objectAngleRad))),
// y-coordinate
(int) Math.round((oldx * Math.sin(objectAngleRad))
+ (oldy * Math.cos(objectAngleRad))));
計算不起作用。 有人能看到錯誤嗎?
您需要在旋轉之前減去矩形的中點,然后再將其添加回來,否則您將圍繞原點旋轉角點(0,0)
Point upLeft = new Point(
// x-coordinate
(int) Math.round(midx + ((oldx-midx) * Math.cos(objectAngleRad))
- ((oldy-midy) * Math.sin(objectAngleRad))),
// y-coordinate
(int) Math.round(midy + ((oldx-midx) * Math.sin(objectAngleRad))
+ ((oldy-midy) * Math.cos(objectAngleRad))));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.