我有一个矩形左上角点的坐标,以及它的宽度、高度和旋转角度从0到180度和从-0到-180度。
我想要获取实际包围该矩形的框的边界坐标。
有什么简单方法来计算包围框的坐标呢?
- 最小y值、最大y值、最小x值、最大x值吗?
点A不一定在最小y边界上,它可以在任何位置。
如果需要,我可以使用AS3中的矩阵变换工具包。
我有一个矩形左上角点的坐标,以及它的宽度、高度和旋转角度从0到180度和从-0到-180度。
我想要获取实际包围该矩形的框的边界坐标。
有什么简单方法来计算包围框的坐标呢?
点A不一定在最小y边界上,它可以在任何位置。
如果需要,我可以使用AS3中的矩阵变换工具包。
我使用了区域来首先旋转矩形,然后使用旋转后的区域来检测该矩形。
r = new Rectangle(new Point(100, 200), new Size(200, 200));
Color BorderColor = Color.WhiteSmoke;
Color FillColor = Color.FromArgb(66, 85, 67);
int angle = 13;
Point pt = new Point(r.X, r.Y);
PointF rectPt = new PointF(r.Left + (r.Width / 2),
r.Top + (r.Height / 2));
//declare myRegion globally
myRegion = new Region(r);
// Create a transform matrix and set it to have a 13 degree
// rotation.
Matrix transformMatrix = new Matrix();
transformMatrix.RotateAt(angle, pt);
// Apply the transform to the region.
myRegion.Transform(transformMatrix);
g.FillRegion(Brushes.Green, myRegion);
g.ResetTransform();
现在开始检测那个矩形
private void panel_MouseMove(object sender, MouseEventArgs e)
{
Point point = e.Location;
if (myRegion.IsVisible(point, _graphics))
{
// The point is in the region. Use an opaque brush.
this.Cursor = Cursors.Hand;
}
else {
this.Cursor = Cursors.Cross;
}
}