javascriptmathpixi.jspi

Angles in javascript


Why aren't angles in js like the angles we've learnt about? I'm trying to make spinner wheel in js, and noticed that using

    for(i<sides)  
    const angle = (360 / sides) * i;

isn't quite enough.

Why is that?

Later I found out that you have to do it like this

const sides = 3;
const angle = (i / sides) * (Math.PI * 2) - Math.PI / 2;                
const x = Math.cos(angle) * radius + startingX;


Solution

  • So i solved it like this:

    const sides = 3;
    const angle = (i / sides) * (Math.PI * 2) - 
    Math.PI / 2;                
    const x = Math.cos(angle) * radius + startingX;
    

    Math.cos e sin use radians as params not °