How to find corner positions

Just wondering if and how i can find the corner positions for
stuff like this
image

and something like this
image
(2 corners would attach here to loop it basically)

If you already have a variable or something for these parts, and these parts are all rectangular prisms, then it’s possible to find each corner. I want to preface my code by saying the one that the script I wrote only works if no rotations have been done to the rectangular prisms, but it is possible. I also want to tell you that there definitely is a better way than me being lazy and basically spamming variations of the same line 8 times, so don’t let it scare you, but I generated each corner with the following code:

image

local part = workspace:WaitForChild("Part");

local cornerPositions = {
	Vector3.new(part.Position.X+0.5*part.Size.X,part.Position.Y+0.5*part.Size.Y,part.Position.Z+0.5*part.Size.Z),
	Vector3.new(part.Position.X+0.5*part.Size.X,part.Position.Y+0.5*part.Size.Y,part.Position.Z-0.5*part.Size.Z),
	Vector3.new(part.Position.X+0.5*part.Size.X,part.Position.Y-0.5*part.Size.Y,part.Position.Z+0.5*part.Size.Z),
	Vector3.new(part.Position.X+0.5*part.Size.X,part.Position.Y-0.5*part.Size.Y,part.Position.Z-0.5*part.Size.Z),
	Vector3.new(part.Position.X-0.5*part.Size.X,part.Position.Y+0.5*part.Size.Y,part.Position.Z+0.5*part.Size.Z),
	Vector3.new(part.Position.X-0.5*part.Size.X,part.Position.Y+0.5*part.Size.Y,part.Position.Z-0.5*part.Size.Z),
	Vector3.new(part.Position.X-0.5*part.Size.X,part.Position.Y-0.5*part.Size.Y,part.Position.Z+0.5*part.Size.Z),
	Vector3.new(part.Position.X-0.5*part.Size.X,part.Position.Y-0.5*part.Size.Y,part.Position.Z-0.5*part.Size.Z),
}

for _, v in ipairs(cornerPositions) do
	local attachment = Instance.new("Attachment", part);
	attachment.Visible = true;
	attachment.WorldPosition = v;
end

I know im 21 days late to this but
im talkin like a way to figure out if a corner would need to be placed in a area that doesnt have one
like the first image
image

Im trying to figure out if there is a open corner to see if i need to place a corner part to cover it off

I hope this makes sense because its kinda hard for me to explain it