How can i detect if two rotated guiObjects are touching?

So I’ve made something that tells me if two non-rotated guiObjects are touching each other or not but i do not know how i can make it work for rotated frames. Here is the code

local s=script.Parent.small
local b=script.Parent.big
s:GetPropertyChangedSignal('Position'):Connect(function()
local biggerv=math.max(s.AbsolutePosition.X,b.AbsolutePosition.X)==s.AbsolutePosition.X and s or b
local smallerv=math.min(s.AbsolutePosition.X,b.AbsolutePosition.X)==s.AbsolutePosition.X and s or b
local biggervY=math.max(s.AbsolutePosition.Y,b.AbsolutePosition.Y)==s.AbsolutePosition.Y and s or b
local smallervY=math.min(s.AbsolutePosition.Y,b.AbsolutePosition.Y)==s.AbsolutePosition.Y and s or b
local resX=smallerv.AbsolutePosition.X+smallerv.AbsoluteSize.X<=biggerv.AbsolutePosition.X+biggerv.AbsoluteSize.X and smallerv.AbsolutePosition.X+smallerv.AbsoluteSize.X>=biggerv.AbsolutePosition.X or biggerv.AbsoluteSize.X<=smallerv.AbsoluteSize.X and smallerv.AbsolutePosition.X<=biggerv.AbsolutePosition.X and biggerv.AbsolutePosition.X+biggerv.AbsoluteSize.X<=smallerv.AbsolutePosition.X+smallerv.AbsoluteSize.X
local resY=smallervY.AbsolutePosition.Y+smallervY.AbsoluteSize.Y<=biggervY.AbsolutePosition.Y+biggervY.AbsoluteSize.Y and smallervY.AbsolutePosition.Y+smallervY.AbsoluteSize.Y>=biggervY.AbsolutePosition.Y or biggervY.AbsoluteSize.Y<=smallervY.AbsoluteSize.Y and smallervY.AbsolutePosition.Y<=biggervY.AbsolutePosition.Y and biggervY.AbsolutePosition.Y+biggervY.AbsoluteSize.Y<=smallervY.AbsolutePosition.Y+smallervY.AbsoluteSize.Y
if resX and resY then
	s.Position=UDim2.fromScale(0,s.Position.Y.Scale)
	game:GetService('TweenService'):Create(s,TweenInfo.new(10,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,false,0),{Position=UDim2.fromScale(1,s.Position.Y.Scale)}):Play()
end
end)
game:GetService('TweenService'):Create(s,TweenInfo.new(10,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,false,0),{Position=UDim2.fromScale(1,s.Position.Y.Scale)}):Play()

Unfortunately, I don’t know the math well enough to explain in this answer, but there is a nice resource on stack overflow that goes over the problem. They also provide the source code and illustration for how it works.

Thank you for replying! I’ll read it as soon as possible!