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
Vec2.rotate(degrees), Vec2.angle, Vec2.angleTo methods #5622
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rotate should take an angle in degrees, like all public facing functionality in math.
And the radians
should be get angle
that returns the angle in degrees as well.
Good point. I've updated the PR and added additional method: |
Also, please update the PR's title. |
Could you add a |
@slimbuck, not sure where would |
It would go like this: rotate(degrees, src = this) {
const angle = Math.atan2(src.x, src.y) + (degrees * math.DEG_TO_RAD);
const len = Math.sqrt(src.x * src.x + src.y * src.y);
this.x = Math.sin(angle) * len;
this.y = Math.cos(angle) * len;
return this;
} You're right rotate could be considered closer to |
Sure, shall then this be left as is, to ensure consistency. And if |
Sure :) |
* // Outputs 90.. | ||
* console.log("The angle of the vector is: " + angle); | ||
*/ | ||
angle() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: should this be a function or a getter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it should be a function, to stay consistent with similar methods, such as: length()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good and fair point. But I'm wondering whether length, for example, should also be a getter these days. If we do decide to leverage getters in the math API, that's for another PR... 😄
Co-authored-by: Will Eastcott <will@playcanvas.com>
Co-authored-by: Will Eastcott <will@playcanvas.com>
Co-authored-by: Will Eastcott <will@playcanvas.com>
Co-authored-by: Will Eastcott <will@playcanvas.com>
Co-authored-by: Will Eastcott <will@playcanvas.com>
Co-authored-by: Will Eastcott <will@playcanvas.com>
Adds two methods to Vec2 to help with converting to radians and rotating it.
New APIs:
I confirm I have read the contributing guidelines and signed the Contributor License Agreement.