Simple Trig With ActionScript

angle conversion:

var angle_deg = angle_rad * 180/Math.PI;
var angle_rad = angle_deg * Math.PI/180;

find (x,y) from angle and radius:

var x = radius * cos( angle_rad );
var y = radius * sin( angle_rad );

a minor issue you will come across in ActionScript is that all of trigonometry functions in Math are based on the angle in radians, and a MovieClip’s _rotation property is based on the angle in degrees (this is not a bug or a flaw, but rather a design decision).

so a bit of simple algebra…

using a ratio:

angle_in_degrees/degrees_in_a_rotation = angle_in_radians/radians_in_a_rotation

one full rotation from origin to origin is 360 degrees or 2π radians:

plugged into the ratio:

angle_in_degrees/360 = angle_in_radians/2π

and solving for either variable:

angle_in_degrees/360 = angle_in_radians/2π

( angle_in_degrees/360 ) * 360 = ( angle_in_radians/2π ) * 360

angle_in_degrees = ( angle_in_radians * 360 ) /2π

angle_in_degrees = ( angle_in_radians * 180 ) /π

angle_in_degrees = angle_in_radians*180/π

and

angle_in_radians/2π = angle_in_degrees/360

( angle_in_radians/2π ) * 2π = ( angle_in_degrees/360 ) * 2π

angle_in_radians = ( angle_in_degrees/360 ) * 2π

angle_in_radians = ( angle_in_degrees/180 ) * π

angle_in_radians = angle_in_degrees*π/180

Leave a comment

  • Tags

  • Categories

  • Need Code Written?

  • Need a Coding Job?

  • Archives