I have an array of position vertices that make up a 2D polygon.
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),
};
What algorithm can I use to modify the positions so the resultant polygon is flipped? I need to flip the polygon both horizontally and vertically.
If you’re flipping around the point (0.0f,0.0f) you simply need to negate the values. So your shape would be:
If you are flipping around a point (x,y) then each point will be (x – (p.x – x)) or (2*x-p.x) for the x value and (y – (p.y – y)) or (2*y-p.y) for the y value.
This explains:
. is the point you want to flip
* is the point you want to flip around
O is the point you want to end up with
Let’s say the x values of . * and O are t, m and b respectively (top, middle and bottom). As you can see, the distance a = t-m and the b = m-a. Therefore b = m-(t-m) = m-t+m = m*2-t
You can then use this principle to write an algorithm to flip all the points around a different point and this will give you your flipped polygon!