Polygon triangulation

Hello! I have an array of Vector2 points and a function to draw triangle. But I can’t find any working scripts to triangulate polygon. How can I do this?
Here is my code and I can’t implement any algorithms in it because all of them doesn’t seem do be working:

local points = {...}

local function drawTriangle(a: Vector2, b: Vector2, c: Vector2, color: Color3, zindex: number, parent: GuiObject)
    ...
end

for i, point in points do
    -- I want to triangulate these points here
end

Thank you!

What do you mean “triangulate these points”? Do you want to draw a triangle between them?

I mean triangulate the polygon.

I have used this lua library before for polygon triangulation for a 2D height map which worked for me:

	local pointsArray = {}

			local currentPoint = Point(currentVector3.X,currentVector3.Z) --Insert as many X, Y points for the polygon
			table.insert(pointsArray,currentPoint)


	local triangles = Delaunay.triangulate(unpack(pointsArray))

1 Like

Thank you, but there is too much code. Which functions I need?

All you need is the Point function to create a Vector2 point specifically for the module (Since its made for Lua and not for Roblox Luau which has Vector2):

And the triangulation function:

1 Like

Thanks, but this module uses “id”. I can’t assign the “id” property of Roblox’s Vector2. Do I have to create my own Point class? :slightly_frowning_face:

The problem is my path have the same start and end points: {(0, 0); (1, 0); (1, 1); (0; 0)} is a triangle, {(0, 0); (1, 0); (1, 1); (0, 1); (0; 0)} is a rect. The function just crashes.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.