2
trace(Math.cos(45));
//0.5253219888177297

trace(Math.cos(30));
//0.15425144988758405

trace(Math.cos(35.264));
//-0.7606511017750149

I'm confused. Do I need to lean Math at the Middle School?

shanethehat
  • 15,460
  • 11
  • 57
  • 87
webnoon
  • 945
  • 3
  • 9
  • 18

1 Answers1

4

Because you're passing degrees and Math.cos() wants radians:

trace(Math.cos(toRad(45)));
//0.7071067811865476

trace(Math.cos(toRad(30)));
//0.8660254037844387

trace(Math.cos(toRad(35.264)));
//0.8165005076106897

function toRad($deg:Number):Number 
{
    return ($deg/180)*Math.PI;
}

Degree - Radian conversion

shanethehat
  • 15,460
  • 11
  • 57
  • 87