A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Trigonometry

Hybrid View

  1. #1

    Trigonometry

    How does the trigonometry in this function work?? Math.cosD() and Math.sinD() are custom functions that return angles in degrees. Vector is a class with x and y properties.

    Vector.prototype.rotate=function(angle){
    var ca=Math.cosD(angle);
    var sa=Math.sinD(angle);
    with(this){
    var rx=x*ca-y*sa;
    var ry=x*sa+y*ca;
    x=rx;
    y=ry;
    }
    };

  2. #2
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    It just uses the standard formulae for rotating a point about the origin by an amount of "angle" degrees.

    the formulas that actually do the rotating are the

    var rx=x*ca-y*sa; and
    var ry=x*sa+y*ca;

    bits. Then it changes the old (x,y) of the vector to the new rotated ones. Did you want proof of the formula?
    jonmack
    flash racer blog - advanced arcade racer development blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center