Drawing triangle not working properly

I would like to Draw a triangle to three positions like this:

But I’m getting this:

I am not familiar with CFrame Matrix

Here is the code if you are wondering

local X, Z = 15, 15

local wedge = workspace.MeshPart;
wedge.Anchored = true;

local function draw3dTriangle(a, b, c)
	local ab, ac, bc = b - a, c - a, c - b;
	local abd, acd, bcd = ab:Dot(ab), ac:Dot(ac), bc:Dot(bc);

	if (abd > acd and abd > bcd) then
		c, a = a, c;
	elseif (acd > bcd and acd > abd) then
		a, b = b, a;
	end

	ab, ac, bc = b - a, c - a, c - b;

	local right = ac:Cross(ab).unit;
	local up = bc:Cross(right).unit;
	local back = bc.unit;

	local height = math.abs(ab:Dot(up));

	local w1 = wedge:Clone();
	w1.Size = Vector3.new(0, height, math.abs(ab:Dot(back)));
	w1.CFrame = CFrame.fromMatrix((a + b)/2, right, up, back);
	w1.Parent = workspace;

	local w2 = wedge:Clone();
	w2.Size = Vector3.new(0, height, math.abs(ac:Dot(back)));
	w2.CFrame = CFrame.fromMatrix((a + c)/2, -right, up, -back);
	w2.Parent = workspace;

	return w1, w2;
end

draw3dTriangle(workspace.A.Position,workspace.B.Position,workspace.C.Position)

note(I am not using robloxs wedge model as that has too many triangles in it, so I am using a mesh with only one triangle)

I think you just need to rotate the wedges

From what I see it’s only a rotational issue, you can try rotating each angle one by one by 180 degrees(for the result) until you get what you want. Then after you find which axes need to be rotated(X, Y, Z) rotate it using code instead.

Another option is to rotate and update the wedge mesh if you have direct access to it.

I will see what I can do to update the mesh as I’ve tried to find where to rotate the triangles in the script

Rotate the triangles by 180 degrees (math.pi / 2 in radians), in some axis. Can’t tell which with the image, but it’s probably the Y axis.

I can’t seem to figure it out but I will try to see what I can do

Finally found the solution, I just used

w1:PivotTo(w1:GetPivot()*CFrame.Angles(0,0 , math.rad(90)));

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