calculate angle between 2 vectors return value in degrees between 0 and 360

Viewed 2230

Hey I have the following code that calculates the angle in degrees:

var angleDeg = Math.atan2(mouse.y - base.y, mouse.x - base.x) * 180 / Math.PI;
console.log(angleDeg);

but at the moment i get the angle between 0 and 180 degrees positive and negative. with 0 deg at the right see image. But i want the returned angles to be between 0 and 360 all positive. with the 0 deg at the top. see image.

enter image description here

How do i update my function so this works? I write this in javascript. So in the end i want the angle values to be returned as the pink in the image. Any help is greatly appreciated!!!

hopefully this is clear if not pls let me know so i can update my question.

2 Answers
Related