Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

".rotate(angle)" and ".rotateBy(rotation)", their feature have been swapped! #25

Open
724Cheers opened this issue Dec 11, 2015 · 4 comments

Comments

@724Cheers
Copy link

//theoretically, console should print (0, 100)
var vec = new Victor(0, 100);
vec.rotate(Math.PI / 2);
console.log(vec);
//(-100, 0)
//theoretically, console should print (-100, 0)
var vec = new Victor(0, 100);
vec.rotateBy(Math.PI / 2);
console.log(vec);
//(0, -100), rotate by this.angle() + PI / 2
@724Cheers
Copy link
Author

solution:

Victor.prototype.rotateBy = function (rotation) {
    var nx = (this.x * Math.cos(rotation)) - (this.y * Math.sin(rotation));
    var ny = (this.x * Math.sin(rotation)) + (this.y * Math.cos(rotation));

    this.x = nx;
    this.y = ny;

    return this;
};
Victor.prototype.rotate = function (angle) {
    var rotation = angle - this.angle();

    return this.rotateBy(rotation);
};

@DrLightman
Copy link

I confirm the erratic behaviour of native rotate and rotateBy.

I confirm the fixes of 724Cheers work, thank you 724Cheers.

@DrLightman
Copy link

rotateTo also needs a fix.

@724Cheers 724Cheers changed the title .rotate(angle) and .rotateBy(rotation), their feature had been swop! ".rotate(angle)" and ".rotateBy(rotation)", their feature have been swapped! Mar 23, 2016
@OzzieOrca
Copy link

@maxkueng If I made a PR, could it be merged? Seems like there hasn't been a lot of activity lately with this repo...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants