-
Help! 2D vector rotate.
Hello.
I’m writing an expression for a 2D vector rotate and it’s not working. It’s driving me nuts!
I know it’s not the simplest way to rotate a point around another one, but this is part of a bigger expression problem I’m trying to solve, writing a lookat function that includes an ‘up’ vector.
I broke the problem down to this really simple thing, and now find that I’m getting a kind of Star Trek badge instead of a circle.
Here’s a picture of the shape it describes…
…and here’s the code.
function doRotate(p, a) { //rotates a point p, angle a around the origin [0,0]
x = p[0];
y = p[1];
x = x*Math.cos(a) - y*Math.sin(a);
y = x*Math.sin(a) + y*Math.cos(a);return([x,y]);
}myPos = [300,100]; // starting position
tCentre = [300,300]; //centre of rotation
myAngle = degreesToRadians(effect("angle")("Slider")); //picks up the slider value and converts to rads.a = doRotate(myPos-tCentre, myAngle); // call rotate function.
a = a + tCentre; //adjust back to centre of rotation.
What am I doing wrong? I was sure the code was right.
Ben.
