Polygon border

Started by
3 comments, last by andy82 17 years, 6 months ago
Hi, does someone know what is the usual way to create a border of size "bordersize" around a polygon? For example, I want to calculate the black polygon from the vertices of the red polygon: I tried to scale the red arrow polygon by 2*bordersize in both x/y directions but that doesn't do the job for most polygons. Thanks for your help. Andy
Advertisement
Offset vertices along their normals:

newVertex = oldVertex + borderSize*oldNormal;
Ok, but how do I calculate the normals for my polygon? Sorry, I'm not so much into mathematics... I try to look it up using google but it all seems to be working with 3D vectors but my polygon is just 2D with only x,y vertices.
The normal of an edge is orthogonal to that edge and pointing out from the polygon's interior. The normal of a vertex is the normalized average of the normals of its two adjoining edges.

This approach, however, is imprecise (the border will not be perfect). You may need to compute a per-vertex vector that is not the normal, but rather a vector with properties similar to those of the normal, which determines the intersection of the edges of the border.

Ok, but how do I calculate the normal from a vertex? From the snippet posted above (newVertex = oldVertex + oldNormal * bordersize) I'd assume that the normal is always 1,-1 or 0. But how do I calculate it? I guess the vertices surrounding the vertex the normal of which I want to calculate have to be taken into account, too, but how?

Btw: I do not need the perfect algorithm because I'm only doing this with simple forms like the arrow above.

This topic is closed to new replies.

Advertisement