Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Commit

Permalink
Update angleTo implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruesc committed May 1, 2020
1 parent cedf444 commit bbf7dff
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,10 @@ export class Vector3 {

angleTo(v) {

const theta = this.dot(v) / (Math.sqrt(this.lengthSquared() * v.lengthSquared()));
const denominator = Math.sqrt(this.lengthSquared() * v.lengthSquared());

// Clamp to avoid numerical problems.
return Math.acos(Math.min(Math.max(theta, -1), 1));
return (denominator === 0.0) ? (Math.PI * 0.5) :
Math.acos(Math.min(Math.max(this.dot(v) / denominator, -1), 1));

}

Expand Down

0 comments on commit bbf7dff

Please sign in to comment.