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
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))
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):
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.