I have 2D polygons, with their vertices positioned in local polygon-space. I'm trying to calculate new vertices that would form a uniform length edge around the inside of the polygon.
Currently to calculate the edge, I'm basically shrinking the original vertices. For each polygon vertex I calculate the negated unit vector and multiply this by a constant edge length factor. Then I add this to the original polygon vertex.
Pseudocode:
const float edgeLength = 0.5;
for each vertex v
vec2 n = -v.unit();
vec2 edgeVertex = v + n * edgeLength;
The result work开发者_开发问答s fine on regular polygons:
screenshot 1However, on other polygons, such as rectangles, the edge lengths are not uniform:
screenshot 2I've tried many different attempts, but nothing seems to work so far, any help would be greatly appreciated, thanks! (Please ignore that the polygons are rendered in 3D, the actual polygon data is 2D).
Move each edge a fixed distance, in a direction perpendicular to the edge (all to the left, if the edges run counterclockwise). Then calculate the intersections of the new edges-- these are the new vertices.
精彩评论