Home » Archive

Articles in the Math Category

AS3, Game, Math, flash »

[2 Jun 2009 | No Comment | ]

That’s it, the following code finds for you the shortest rotation angle from a given angle to another:

var diffAngle:Number = Math.atan2(Math.sin(angleTo - currentAngle), Math.cos(angleTo - currentAngle));

The code was given on this forum. You’ll also find a way to do it with vectors.

AS3, Game, General game programming, Math, Useful links »

[4 Mar 2009 | 2 Comments | ]

There are many ways to calculate the surface of a polygon. It all depends on what kind of data you have to deal with. If you have only vertices (points) or if you have the segments associated to them as well.
The most evident solution would be to divide the polygon in triangles and calculate the surface of them. But this can quickly become complicated as you will have to test every segment of every triangle and check if they are intersecting with a current polygon’s segment or if it goes …

AS3, Math »

[30 Jul 2008 | No Comment | ]

var dx:Number = x1 - x2;
var dy:Number = y1 - y2;

rotation = Math.atan2( dy , dx ) * ( 180 / 3.141592653589793 ) ;