开发者

Polygon edge algorithm problem

开发者 https://www.devze.com 2023-03-12 19:52 出处:网络
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.

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 1

However, on other polygons, such as rectangles, the edge lengths are not uniform:

screenshot 2

I'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号