Skip to content

PVector.angleBetween() returns 0 for 3D vectors whenever x and y are both 0 #2045

@sebhunt

Description

@sebhunt

PVector.angleBetween(PVector, PVector) returns 0 for 3D vectors whenever the x and y components of a parameter are both 0. For example:

PVector.angleBetween(new PVector(0,0,1), new PVector(1,0,0))

returns 0 instead of PI/2.

Looking at the source code, it seems clear what is wrong:

// We get NaN if we pass in a zero vector which can cause problems
// Zero seems like a reasonable angle between a (0,0) vector and something else
if (v1.x == 0 && v1.y == 0) return 0.0f;
if (v2.x == 0 && v2.y == 0) return 0.0f;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions