# Polygon border

This topic is 4478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
Offset vertices along their normals:

newVertex = oldVertex + borderSize*oldNormal;

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 11
• ### Forum Statistics

• Total Topics
634114
• Total Posts
3015593
×