Skip to content

Instantly share code, notes, and snippets.

@gaymeowing
Created July 24, 2025 19:33
Show Gist options
  • Save gaymeowing/283b7cca080e5c7b540471315360f2e3 to your computer and use it in GitHub Desktop.
Save gaymeowing/283b7cca080e5c7b540471315360f2e3 to your computer and use it in GitHub Desktop.
--!native
local CFRAME_FROM_MATRIX = CFrame.fromMatrix
local WEDGE = Instance.new("Part")
local INSTANCE_CLONE = WEDGE.Clone
local function create_3d_triangle(
a: vector, b: vector, c: vector,
parent: Instance?, part_1: Part?, part_2: Part?
): (Part, Part)
local ab, ac, bc = b - a, c - a, c - b
local abd, acd, bcd = vector.dot(ab, ab), vector.dot(ac, ac), vector.dot(bc, 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 = vector.normalize(vector.cross(ac, ab))
local up = vector.normalize(vector.cross(bc, right))
local back = vector.normalize(bc)
local height = math.abs(vector.dot(ab, up))
if not part_1 then
part_1 = INSTANCE_CLONE(WEDGE)
end
part_1.Size = vector.create(0, height, math.abs(vector.dot(ab, back)))
part_1.CFrame = CFRAME_FROM_MATRIX((a + b) / 2, right, up, back)
if not part_2 then
part_2 = INSTANCE_CLONE(WEDGE)
end
part_2.Size = vector.create(0, height, math.abs(vector.dot(ac, back)))
part_2.CFrame = CFRAME_FROM_MATRIX((a + c) / 2, -right, up, -back)
if parent then
part_1.Parent = parent
part_2.Parent = parent
end
return part_1, part_2
end
do
WEDGE.BottomSurface = Enum.SurfaceType.Smooth
WEDGE.TopSurface = Enum.SurfaceType.Smooth
WEDGE.Shape = Enum.PartType.Wedge
WEDGE.Anchored = true
end
return create_3d_triangle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment