Polygon skew algorithm
What algorithm can I use to skew a polygon?
Like skewing the following: ____
| _|
|__|
To bottom right will yield
____
| \
| \
\ _|
\__|
its like a shadow cast. I thought about taking every line and making a parallelogram with it and its corresponding line in the skewed position and then union all of these, but that look开发者_JAVA技巧s a bit brute to do and will take a lot of time.
Is there a better algorithm for this? I already have code for all polygon boolean operations if its needed.I think this algorithm I just thought up will do it:
Classify every line in the polygon as to whether it is more facing-top-left or facing-bottom-right (or exactly along the skew-direction line).
Then, for each vertex:
- If it joins two top-left lines or a top-left line and an exactly-aligned line, then leave it be.
- If it joins two bottom-right lines or a bottom-right line and an exactly-aligned line, then move it by the skew distance.
If it joins a top-left and bottom-right line, then split it into two vertices, one moved and one not.
This step may cause a self-intersection (such as if the vertex was concave and facing bottom left), in which case discard the two vertices and join the two existing lines with a vertex at their intersection point.
精彩评论