Function Angle.BetweenTwoPoints().degrees()

Hi,

The angle between vector (1, 0) and vector (0, 1) should be 90 degree as shown in below:

image

But why when I logged out BABYLON.Angle.BetweenTwoPoints(new BABYLON.Vector2(1, 0), new BABYLON.Vector2(0, 1).degrees()), it gives me 135?

1 Like

BABYLON.Angle.BetweenTwoPoints(a, b) is getting the angle between the x axis and b-a vector, so in your case (-1, 1), which is indeed 135°.

In your case, you should take the dot product to calculate the angle:

dot(a,b)=norm(a)*norm(b)*cos(ab)

Dot can be found in static BABYLON.Vector2 and norm is the length() function of the vector.

5 Likes

Ah I see, thanks a lot!

why is it calculate (-1,1) in this case? can you explain more? do we have any playground for this?

In the example, B=(0,1) and A=(1,0), so B-A=(0-1,1-0)=(-1,1)

1 Like

The expression BetweenTwoPoints is bit of a misnomer since this function

const angle = BABYLON.Angle.BetweenTwoPoints(a, b);

finds the gradient angle of the vector2 b - a

see Angle | Babylon.js Documentation

1 Like