Triangle module giving really odd looking triangles

Hello reader.

So today I basically felt like doing something with triangles.

The module I made is not completely my own coding since I can’t do this
kind of math very well, so I did have to look at other scripts to replicate it.

But now I have a problem.
My triangles look very misshapen for some reason.


I tried looking at the code to see where it went wrong or what I didn’t replicate correctly but couldn’t find it.

Here is the code:

local mod = {}
local v3 = Vector3.new
local cf = CFrame.new
local abs = math.abs
local cross = v3().Cross
local dot = v3().Dot

local clone = workspace.Clone


local function fromaxes(p, x, y, z)
	return cf(
		p.x, p.y, p.z,
		x.x, x.y, x.z,
		y.x, y.y, y.z,
		z.x, z.y, z.z
		)
end

mod.newtri = function(a, b, c, ta, tb)
	
	local ab, ac, bc = b - a, c - a, c - b
	
	local abm, acm, bcm = ab.magnitude, ac.magnitude, bc.magnitude
	
	if abm > bcm and abm > acm then
		c, a = a, c
	elseif acm > bcm and acm > abm then
		a, b = b, a
	end
	
	ab, ac, bc = b - a, c - a, c - b
	local out = cross(ac, ab).unit
	
	local bidir = cross(bc, out).unit
	local bilen = abs(dot(ab, bidir))
	local mag = bc.magnitude
	
	---------------------------------------
	ta.Size = v3(0, abs(dot(ab, bc))/mag, bilen)
	tb.Size = v3(0, bilen, abs(dot(ac, bc))/mag)
	
	bc = -bc.unit
	
	ta.CFrame = fromaxes((a + b)/2, -out, bc, -bidir)
	tb.CFrame = fromaxes((a + c)/2, -out, bidir, bc)
	---------------------------------------
end
--


return mod

And here is the script executing the module.

local mod = require(script.Parent)

local w1, w2 = workspace.w1, workspace.w2


while wait(0.2) do
	mod.newtri(workspace.A.Position, workspace.B.Position, workspace.C.Position, w1, w2)
end

If someone could explain to me how triangle math works I would appreciate it.

This is a bit above the kind of math I’m currently capable of.

I basically just want my own triangle module written in my own style.
I’ve tried that first, didn’t work,
looked again at the other script to see what went wrong but somehow just can’t spot it, even after directly copying the math/calculations it still gave the same results.

It all resulted in those weird misshapen triangles posted above.

And I’m not sure for what I will use this module yet, I just want to experiment around a bit and see what I can use it for pretty much.

The module is not for anything specific or so, so I try to make the coding a bit “general” so I can use it for anything I wish.