Problems with corners in pathbuilding script

Hello. I have a pathmaking script that uses waypoints to create paths.
As you can see, it does not create a desirable result on the corners:

The pathbuilding uses this formula for the orientation: (modified to work with Cframe EulerAngles)
atan2(Δx, -Δz)
atan2(Δy, √(Δx^2+Δz^2))

The pathbuilding also uses the 3D Distance Formula and 3D Midpoint Formula.

Code so you don’t have to type all of it out:

local w1 = game.Workspace.waypoint1namehere -- Waypoint #1
local w2 = game.Workspace.waypoint2namehere -- Waypoint #2
local yaw = math.atan2(-(w2.Position.X - w1.Position.X), -(w2.Position.Z - w1.Position.Z))
local pitch = math.atan2((w2.Position.Y - w1.Position.Y), math.sqrt((w2.Position.X - w1.Position.X)^2 + (w2.Position.Z - w1.Position.Z)^2))

Maybe the formulas doesn’t matter in the final solution? I’m thinking it could calculate each corner after the paths have been laid out.

The goal is to make the corners like this (the empty area will be filled with another wedge)

this might sound dumb but you could potentially have an easier time with that math if you make an editablemesh path builder, but that of course has its own caveats and downsides

I prefer it to be fully primitives,

Oh yeah, to make it more clear:

I do know Archimedes knows how to get around this issue, but i’m not sure exactly how. You could try reading the plugin code to learn about it. (Of course i don’t advocate for direct plagiarism, but when it’s for learning like this i think it’s fine)