检查点是在一个旋转矩形(C#) [英] Check if a point is in a rotated rectangle (C#)
问题描述
我在C#(Windows窗体)一个程序,它利用了一个PictureBox一些矩形。他们可以在太(旋转)的角度得出。
I have a program in C# (Windows Forms) which draws some rectangles on a picturebox. They can be drawn at an angle too (rotated).
我知道每个矩形起点(左上角),它们的尺寸(宽+高)和他们的角度。由于转动的,开始点是不necessarely的左上角,但是,这并不在这里重要。
然后当我点击PictureBox的,我需要检查其中的矩形(如果有的话)我已经点击了。
I know each of the rectangles' start point (upper-left corner), their size(width+height) and their angle. Because of the rotation, the start point is not necessarely the upper-left corner, but that does not matter here. Then when I click the picturebox, I need to check in which rectangle (if any) I have clicked.
所以,我需要检查,如果以某种方式点是在一个矩形,但我还需要考虑到每个矩形的旋转。
是否有人知道的方式做到这一点在C#?
So I need some way of checking if a point is in a rectangle, but I also need to take into account the rotation of each rectangle. Does anybody know of a way to do this in C#?
推荐答案
是否有可能将施加同样的旋转以矩形反向点?
Is it possible to apply the same rotation applied to the rectangle to the point in reverse?
例如,矩形A从它的起源(左上角)顺时针旋转45度,你会那么只需旋转b点同样出身顺时针旋转45度左右COUNTER,然后检查,看它是否属于在矩形中的预旋转
For example, Rectangle A is rotated 45 degrees clockwise from its origin (upper left corner), you would then just rotate point B around the same origin 45 degrees COUNTER clockwise, then check to see if it falls within Rectangle A pre-rotation
这篇关于检查点是在一个旋转矩形(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!