PDA

Click to See Complete Forum and Search --> : Trigonometry



timhlu
01-07-2003, 06:01 PM
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;
}
};

jonmack
01-08-2003, 03:32 PM
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?