How to get angle between 3 points?

?

You can solve this by using trigonometry. I’ll try my best but I am no expert.

Let’s start of by labelling the points you gave me as A, B and C, with B being the vertex of the angle you’re trying to find

Image Diagram

image

We then need to determine the coordinates of the three points A, B, and C. Since you haven’t given the coordinates in the post, we can just call them A, B and C.

Next, we need to form the vectors AB and BC by subtracting the coordinates:

image

We then need to use the dot product formula to caluclate the Dot Product:

image

We can then compute the magnitudes of AB and BC by using these equations:

image

We can get the cosine of the angle by using a cos function.

image

As per usual trigonometery, to find an angle we need to use the inverse function (arccos / acos):

image

This leaves us with the your angle.

1 Like

I do not know why, but my function always returns 360 degrees.

local function GetAngle(A: Vector3, B:Vector3, C: Vector3): number
 local AB = (B - C)
 local BC = (C - B)
 
 local dotProduct = AB:Dot(BC)
 
 local magnitudeAB = AB.Magnitude
 local magnitudeBC = BC.Magnitude
 
 local cosine = dotProduct / (magnitudeAB * magnitudeBC)
 
 return math.acos(cosine)
end

local AB = B - C? :sweat_smile:

I think this should do it or am i missing something?

local A = workspace.A.Position
local B = workspace.B.Position
local C = workspace.C.Position

local ab = (B - A).Unit
local ac = (C - A).Unit

local angle = math.acos(ab:Dot(ac))
print(math.deg(angle))

Yeah, I think you used the exact same method they were talking about above, I’ve already stated why their code didn’t work for their implementation though.

Take your result and divide by 1/2π to convert from radians to degrees

please atleast quickly read over the thread before bumping this post continuously; the original poster specifically states it is ALWAYS returning 2 pi/360 degrees; conversion is not the issue here, and the reply 2 messages above yours already mentions conversion too

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.