Personal License


  • Perpetual license (does not expire)
  • 1 site, unlimited servers
  • No distribution (hosted use only)
  • Commercial use allowed
Free Read License

14 Day money-back guarantee

Full refund within 14 days of purchase date.

You need to log-in or create an account
  • Create an account
  • Log-in

Please use your real name.

Activation link will be sent to this address.

Minimum 8 characters

Enter your password again

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

  • Released: Apr 28, 2011
    Last Update: May 25, 2011
  • Language: ActionScript

MathUtilities

MathUtilities
Developed by Stijn Van den Bogaert, Released Apr 28, 2011

A small math-class which can convert degrees to radials and vice versa. It also can calculate the distance between two objects.

ActionScript

Tags: as3 , math , mathutilities , utilities

First link the "libs"-folder as swc-folder to your project and add the "math"-package. (In the libs-folder you'll find a file named greensock.swc, this file can be downloaded for free on http://www.greensock.com/tweenlite/)

To convert degrees to radials, do it like this:

trace("45degrees = " + MathUtilities.degreesToRadius(45) + "rad");

To convert radials to degrees, do it like this:

trace("1rad = " + MathUtilities.radiusToDegrees(1) + "degrees");

Here's an example of how to create moving circles and calculate the distance between them with this package (view demo to see how it works):

package{
    import math.Circle;
    import math.MathUtilities;

    import com.greensock.TweenLite;
    import com.greensock.TweenMax;

    import flash.display.Sprite;

    public class Main extends Sprite{

        private var circle1:Circle;
        private var circle2:Circle;

        public function Main(){
            drawCircles();
        }

        public function drawCircles():void{
            circle1 = new Circle( 50, 0xff0000 );
            circle2 = new Circle( 10, 0x00ffff );

            circle1.x = 0;
            circle2.x = stage.stageWidth;

            circle1.y = circle2.y = 100;

            TweenLite.to( circle1, 5, {x:stage.stageWidth, onUpdate:checkDistance} );
            TweenLite.to( circle2, 5, {x:0, onUpdate:checkDistance} );

            addChild( circle1 );
            addChild( circle2 );
        }

        public function checkDistance():void{
            var distance:Number = MathUtilities.checkDistance( circle1, circle2);
            var hitzone:Number = (circle1.width + circle2.width) /2;

            if( (distance - hitzone) <=0  ){
                trace("HIT");
                TweenMax.killAll();
            }

            trace(distance - hitzone);
        }
    }
}

User Reviews

No reviews have been submitted yet.

Questions & Comments


Or enter your name and Email
No comments have been posted yet.
You must be logged-in to vote. Log-in to your account or register now.