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
Implementation of p5.Vector setHeading() #4767
Comments
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already. |
This commit adds the setHeading() function to the p5.Vector class. There are some remaining issues here. For example, there are no tests.
Hello.
AFAIK: vector is object that have direction and length. By creating vector you already set his rotation that point to direction. Take a look at fromAngle function. I think it doing exactly what you want. Probably this operation may be cheaper (for CPU cycles) when you create new vector and rotate it. Because |
Hi mishazawa The issue with creating a new vector altogether with Perhaps we could copy the code from |
Which ones? Vector has only [x, y, z] properties. let vec = createVector(1, 2, 3);
vec.offset = createVector(2, 2, 2); I highly recommend not to do it. Because vector is designed to store only direction and length (through coordinates). let arrow = {
direction: createVector(1,2,3),
offset: createVector(2, 2, 2),
}
Proper way is to create new vector. I don't see any use cases when you should modify vector instead just re-write it. |
I can see where you're coming from, but often times p5.js is used by beginners, and having to create a new vector using Also just to note, a vector's |
I agree, I think it would be handy to have a |
As per @mishazawa s suggestion, I edited the setHeading() functions implementation to more closely represent the fromAngle() function, but without the need to create a new object. I still think this feature would improve the p5.js library. |
Thanks for the discussions! I'm ok with this being added, can someone else have a look at this proposal and if it's ok, we'll merge it? @lmccart @montoyamoraga @outofambit @stalgiag |
i agree that this will be a good contribution to the library. My only doubt is if this would break any 3D vector? i saw on the docs that vectors can be x,yz too, right? |
I included that this method would only work for 2d vectors in the method documentation. Im not sure if something should prevent a user from rotating a 3d vector...maybe a console warning would be helpful here? |
Implementing p5.Vector setHeading() (Issue #4767)
I am opening a new issue to implement a
setHeading
method for the p5.Vector class. Currently, p5 contains a functionrotate()
, which rotates the vectorby
a certain value, but no such method exists for setting the vector's rotation to an explicit direction. I currently have something working, and am planning to pull request an implementation.An implementation would look as follows:
This is my first time attempting to contribue to open source, so any tips would be greatly appreciated!
The text was updated successfully, but these errors were encountered: