Why do people substract y2 with y1 and x2 with x1 while using math.atan2

When i was first learning about math.atan2 the person in which i was learning it from
substracted y2 with y1 and x2 with x1 which does the same thing as when i don’t substract them .

Gif without substracting:
https://gyazo.com/f50ebaf648d80d2c5171fd7578cbe8e1
Gif with substracting:
https://gyazo.com/68e9862ec9a3ab199442356936b9db63
Script without substracting:

local Angle = 1
local Radius = 50
function Upd()
	local x = math.cos(Angle)*Radius
	local y = math.sin(Angle)*Radius
	
	
	script.Parent.P2.Position = script.Parent.P1.Position+UDim2.new(0,x,0,y)
	script.Parent.P1.Rotation = math.deg(math.atan2(y,x))
end






while true do
	if Angle == 360 then
		Angle = 1
	else
		Angle = Angle+.1
	end
	Upd()
	wait()
end

Script With substracting:

local Angle = 1
local Radius = 50
function Upd()
	local x = math.cos(Angle)*Radius
	local y = math.sin(Angle)*Radius
	
	
	script.Parent.P2.Position = script.Parent.P1.Position+UDim2.new(0,x,0,y)
	script.Parent.P1.Rotation = math.deg(math.atan2(y-script.Parent.P1.Position.Y.Offset ,x-script.Parent.P1.Position.X.Offset ))
end






while true do
	if Angle == 360 then
		Angle = 1
	else
		Angle = Angle+.1
	end
	Upd()
	wait()
end

i’d like to know why he substracted y2 with y1 and x2 with x1 please and thank you.

I am sorry but can you add the code or something, I do not understand the question.

I believe that math.atan() only allow calculations on quadrants I and IV, while math.atan2() allows calculations on all quadrants.

I’m not even in Calculus yet…

okay i understand but that has nothing to do with my question

can you check again? i added the scripts

atan2 returns an angle of a ray to a point. What they are doing is accounting for the point not being at the origin (0,0).

2 Likes