## how to create an outlined polygon with vector3 coordinates?

I have a set of vector3 coordinates and I use them to draw a polygon in another app, my question is: how can I calculate a second set of coordinates to make it look like the line is outlined. in the above picture, the blue dots are the vector3s I have and the red dots are the one I need, can anyone help me with an algorithm or formula to calculate them? thanks

## Solutions/Answers:

### Answer 1:

**1)Find barycentric coordinates**

```
for(int i = 0; i < verticesInPolygon; i++)
{
bary.xyz += vertices[i].xyz;
}
bary.xyz /= verticesInPolygon;
```

**2)Create new vertices using this formula**

```
newVertex.coord = (vertices[desiredVertexInPolygon].coord - bary.coord)*offset+bary.coord;
```

Where `coord`

is a desired coordinate(`x`

, `y`

or `z`

) and `offset`

is a scalar determining how far from the barycenter and how close to the original vertex a new vertex will be, i. e. 0.5 would make it appear right between, making new polygon being a half size of the original.

UPDATE:

So, you need a constant offset to make outline, right?

Here is a way to do it.

**1)Find barycentric coordinates**

We already know how to do this.

**2)Find a unit direction vector from barycenter to the original vertex**

```
dir.xyz = normalize(vertices[desiredVertexInPolygon].xyz - bary.xyz);
```

**3)Create new vertices with a following formula**

```
newVertex.xyz = vertices[desiredVertexInPolygon].xyz + dir.xyz * offset;
```

Where `offset`

is now a real distance rather than scalar.

Note that in your case you should use a negative offset value, because you want outline to be inside the polygon.

## References

- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport