# 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

• It is offset @Ocelot, could you explain a little more, sorry Oct 16 '16 at 6:20
• Oh, god. Nevermind, I was wrong. Oct 16 '16 at 7:04
• oh, :(, I was testing that. @Ocelot Oct 16 '16 at 7:08
• Don't loose hope, I think I figured it out. x) Oct 16 '16 at 7:09
• Do you need outline to keep constant width irregardless of viewpoint and polygon shape (including concave) ? Oct 16 '16 at 9:05

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.

• lets say I need the distance between the original vertex and the new vertex to be 0.2f, what should the offset be? Oct 16 '16 at 7:23
• @TheFallen 1.0 - 0.2 = 0.8? Oct 16 '16 at 7:25
• well the problem with this is that based on the distance of the original point from the center, the distance of the new point from the original point varys, so the distance of the two lines are not the same across all of the shape, is there a way to fix it. sorry for the truble Oct 16 '16 at 7:58
• sorry but can you help me finish it? Oct 16 '16 at 8:10
• @TheFallen I'm wrong again. The correct way to do this is not trivial. The one method for this is using a Straight skeleton. en.wikipedia.org/wiki/Straight_skeleton Oct 16 '16 at 9:24