Trigonometry in Flash

Trigonometry is an easily overlooked topic until you want to create interactive interface solutions relying on spacial relationships. In theory, the concept of trigonometry doesn’t require much to grasp yet still requires enough specialized and simple formulas which are better served as reference material.

So like any interaction developer, I’ll need a trig toolbox, and this will be it.

Note: This is currently a work in progress

Trigonometry Inspiration

Trigonometry Books

Trigonometry Tutorials

The Flash Cartesian coordinate system is slightly different than a normal Cartesian system in that the y axis is flipped. A normal coordinate x=2, y=2 would be x=2, y=-2 in Flash. This is because the visible Stage area starts in the upper left of the screen and continues to the bottom right, therefore you want to work top down.

It’s important to note movieClips in flash use degrees for _rotation, but most of the math involves radians.

360 degrees is equal to PI*2 or 6.28… radians
180 degrees is equal to PI or 3.14… radians
90 degrees is equal to PI/2 or 1.57… radians

Ok, So now on the to the nitty gritty. Before you can begin to calculate distance and angles you you’ll need the kit of parts for conversions and formulas.

Flash Class Methods

Formulas

Examples

»     » del.icio.us     » Digg It!

Tags: , , , , , , , , , , , , , , ,

9 Comments »

  1. jgraup said,

    April 19, 2007 @ 5:46 pm

    Couple of notes so far.

    1. return { prop: func() }is slower thanvar prop = func();
      return {prop:prop}
    2. /2 is faster than *.5 - dividing is faster than multiplying to divide
    3. my perpoint function is based on scrollbar math, probably just a hack, and my brother points out you should use normalize: pX = somePoint + normalize(p1-p2) * someDistance;.
  2. jgraup said,

    April 19, 2007 @ 5:47 pm

    http://www.ogre3d.org/docs/api/html/OgreVector2_8h-source.html

  3. jgraup said,

    April 22, 2007 @ 2:43 pm

    http://www.geocities.com/SiliconValley/2151/math2d.html

  4. jgraup said,

    April 23, 2007 @ 10:11 am

    http://www.gaffer.org/

  5. jgraup said,

    April 23, 2007 @ 10:12 am

    http://www.sodaplay.com/index.htm

  6. jgraup said,

    April 23, 2007 @ 10:15 am

    http://www.krazydad.com/bestiary/circle.swf

  7. jgraup said,

    May 23, 2007 @ 9:38 am

    Flash 9 - Drawing lines using Circle-Circle Intersection
    http://www.nocircleno.com/experiments/circle_intercepts/index.html

    Circle-Circle Intersection
    http://mathworld.wolfram.com/Circle-CircleIntersection.html

  8. jgraup said,

    May 31, 2007 @ 2:51 pm

    http://www.kirupa.com/developer/actionscript/trigonometry.htm

    http://www.senocular.com/flash/source.php?id=0.114

    http://www.actionscript.org/resources/articles/155/1/trigonometry-and-flash/Page1.html

    http://www.peachpit.com/articles/article.asp?p=30617&seqNum=5&rl=1

  9. jgraup said,

    December 17, 2007 @ 1:23 pm

    // DIRECTION
    var b:Number = 0;
    addEventListener ( Event.ENTER_FRAME, loop );
    function loop ( e:Event )
    {
    b-= 3

    var rad:Number = b * Math.PI / 180;
    var sin:Number = Math.sin ( rad );
    var cos:Number = Math.cos( rad );
    var d:String = ( ( sin > 0 && cos > 0 ) || ( cos > 0 && sin < 0 ) ) ? "r" : "l";
    trace( d+ " : " + (b)+ " > ” + cos + ” > ” +sin)
    }

RSS feed for comments on this post · TrackBack URI

Leave a Comment

You must be logged in to post a comment.

best kansas city bookstore pirodr! 666