我有一个组成二维多边形的位置顶点数组。
Vector2[] _chassisConcaveVertices =
{
new Vector2(5.122f, 0.572f),
new Vector2(3.518f, 0.572f),
new Vector2(3.458f, 0.169f),
new Vector2(2.553f, 0.169f),
new Vector2(2.013f, 0.414f),
new Vector2(0.992f, 0.769f),
new Vector2(0.992f, 1.363f),
new Vector2(5.122f, 1.363f),
};
我可以使用什么算法来修改位置以便翻转生成的多边形?我需要水平和垂直翻转多边形。
最佳答案
如果你在点(0.0f,0.0f)周围翻转,你只需要对这些值求反所以你的形状是:
Vector2[] _chassisConcaveVertices =
{
new Vector2(-5.122f, -0.572f),
new Vector2(-3.518f, -0.572f),
new Vector2(-3.458f, -0.169f),
new Vector2(-2.553f, -0.169f),
new Vector2(-2.013f, -0.414f),
new Vector2(-0.992f, -0.769f),
new Vector2(-0.992f, -1.363f),
new Vector2(-5.122f, -1.363f),
};
如果围绕一个点(x,y)翻转,则每个点对于x值为(x-(p.x-x))或(2*x-p.x),对于y值为(y-(p.y-y))或(2*y-p.y)。
这说明:
. 是你想要翻转的点
*是你想要翻转的点
O是你想结束的一点
x axis
^
|
. -
| | <-
| | <- Let this be distance a
* -
| | <-
| | <- This should be equal to a
O -
|
|
-------> y axis
假设x值为*O分别为t、m、b(上、中、下)如你所见,距离a=t-m,b=m-a,因此b=m-(t-m)=m-t+m=m*2-t
然后,您可以使用这个原理来编写一个算法,将所有的点围绕一个不同的点翻转,这将给您翻转的多边形!
关于c# - 翻转顶点数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5336160/