 # Create a hole in a polygon with a distance

Hi everyone,

I have a polygon with n points in a (X,Y) plane (the yellow one) and i’d like to make a hole inside it in a definite distance. The hole is colored in red.

Do you know how to do this transformation ?

Thanks,

Boris

You can probably create a mesh for the outside, clone it, scale it down, apply the transform data with (bakeCurrentTransformIntoVertices), and rely on CSG to substract one from the other.

But as You have all the points, it might be simpler to triangulate manually ?

Couple of things you could try

Irregular Polygons | Babylon.js Documentation which allows polygons with holes. You would have to calculate the vertices of the hole.

An alternative would be to draw a closed line of fixed width Draw a Line With a Set Width | Babylon.js Documentation

1 Like

You’re right @JohnK but the parallel lines example does not work when the lines are closed

this is my playground https://playground.babylonjs.com/#FA2H7X#166

could you help me to solve this problem ?

I was thinking of any of the closed examples from the other three methods.

Ok, i will try to do that. Thanks

You are right sbout the parallel lines not closing correctly. Closing the parallel lines would need a closed option adding to the code for parallel lines as in the other methods.

When I have time I will see about doing it.

I think i’ve found the solution.

the closing point is the intersection of the line (innerData,innerData) and the line (innerData[nbPoints - 2],innerData[nbPoints - 1])

if you define the two lines with equations y=ax+b, you will find the closing point.

and you assume that innerdata = innerdata[nbPoints - 1] = closing point.

The same thinking can be done with the outer points.

3 Likes

This will allow you to close the lines https://playground.babylonjs.com/#FA2H7X#167

3 Likes