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

Do not use angleBetween() for angle calculation in _orbit() inside orbtiControl(). #6154

Merged
merged 2 commits into from May 23, 2023
Merged

Do not use angleBetween() for angle calculation in _orbit() inside orbtiControl(). #6154

merged 2 commits into from May 23, 2023

Conversation

inaridarkfox4231
Copy link
Contributor

@inaridarkfox4231 inaridarkfox4231 commented May 23, 2023

Since angleBetween() can return negative numbers, modify it so that it only returns positive numbers.
This function is not used because it is inconvenient to be affected by the specification change of angleBetween().

Resolves #6153

Changes:

before:

  // Find the angle between the "up" and the "front", add dPhi to that.
  const camPhi = front.angleBetween(up) + dPhi;

after:

  // Find the angle between the "up" and the "front", add dPhi to that.
  const camPhi =
    Math.acos(Math.max(-1, Math.min(1, p5.Vector.dot(front, up)))) + dPhi;

PR Checklist

Since angleBetween() can return negative numbers, modify it so that it only returns positive numbers.
This function is not used because it is inconvenient to be affected by the specification change of angleBetween().
@inaridarkfox4231
Copy link
Contributor Author

The idea of ​​executing angleBetween() with abs cannot be adopted.
This is because functions that are signed or unsigned for unreasonable reasons cannot be trusted.

@@ -1746,7 +1746,8 @@ p5.Camera.prototype._orbit = function(dTheta, dPhi, dRadius) {

// calculate updated camera angle
// Find the angle between the "up" and the "front", add dPhi to that.
const camPhi = front.angleBetween(up) + dPhi;
const camPhi =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, can we add a comment explaining what this does differently from angleBetween for context for future readers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Since the specifications of angleBetween() are subject to change due to version updates, a calculation method that directly obtains the angle between two vectors is used here."
How about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I mention the possibility of getting negative numbers?
"angleBetween() can return negative numbers. Since this specification is subject to change due to version updates, it cannot be adopted, so here we calculate using a method that directly obtains the absolute value."
Is this better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think mentioning negative numbers is good, since that's main motivation and the bit that would cause a bug (and using a separate implementation instead of abs() just makes it a bit more efficient and less likely to break in the future.) Your text looks good!

add explanation of not using angleBetween()
@inaridarkfox4231
Copy link
Contributor Author

Perhaps it would be more reliable to enclose acos with abs, but it would be complicated and I don't think the javascript specification will change so much, so I think this is fine.

@davepagurek davepagurek merged commit 914d637 into processing:main May 23, 2023
5 checks passed
@inaridarkfox4231 inaridarkfox4231 deleted the orbitControl_angleBetween_BUG branch May 23, 2023 12:33
@inaridarkfox4231
Copy link
Contributor Author

Thanks so much! ('ω')

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

Successfully merging this pull request may close these issues.

orbitControl() uses angleBetween() which returns negative value
2 participants