-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Vector2: Added angleTo() #22209
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
Vector2: Added angleTo() #22209
Conversation
const x = new THREE.Vector2( 1, 0 );
const y = new THREE.Vector2( 0, - 1 );
console.log( y.angle() ); // 4.71238898038469
console.log( x.angleTo( y ) ); // -1.5707963267948966 |
Is this the result you want? |
|
Your first implementation returned a positive result -- presumably the smallest of the two angles. That is the result I would expect in three.js. The second implementation returns a signed result. That method likely requires a different name and proper documentation. What is your use case for needing this method? |
|
I am studying linear algebra recently. |
|
We usually do not enhance the API without a compelling use case. Just because |
That is what I expected. There has been no demand for this in three.js. This is a 3D library. Also, there are many use cases: clockwise, counter-clockwise, smallest-angle, [0-2pi], [-pi, pi], signed angle, unsigned angle. // One option is to do what you did initially, and add the method that returns the shortest angle, unsigned. The other option is to do nothing since there has been no demand for it. |
|
Okay, I get it, thanks. I will close this PR. |
|
I'm working on controls for a vehicle that only moves on a flat plane, and |
|
I think the method is so tiny that is probably worth adding it 👍 |
|
Unfortunately I can't reopen the PR... |
|
As mentioned in #22209 (comment) the method can be implemented differently and not every implementation fits all use cases. I agree with @WestLangley that @jespertheend Would the method still helpful to you if it returns the shortest unsinged angle between two vectors? I could imagine a signed angle is more useful for what you want to implement... |
|
Yeah I think a signed angle would probably be more useful. I also frequently run across this case with 3d vectors: const up = new Vector3(0, 1, 0);
let angle = direction.angleTo(up);
const cross = direction.cross(up);
if (cross.z < 0) {
angle *= -1;
}From a quick search in my current (4 week) three.js project I ran across this 7 times. In Renda I have these four functions: I personally think all of these could be useful, but ultimately it's a trade-off of how much you want to include. |
|
Considering #22209 (comment) and your implementations, @mrdoob If you are fine with this commit, I'll restore the PR based on that version. |
|
hmmm...
There are many options for implementing this. Very little demand. |
Yes, this will only be a matter of time. But still I feel it's okay to add
Lately, I frequently get complains that |
Let's cross that bridge when we come to it 🙂 |
Related issue: #null
Description
Vector2 added
.angleTo(), just likeVector3.angleTo().