Most appropriate sub-area of p5.js?
p5.js version
2.3.0
Web browser and version
Brave 1.90.122
Operating system
Linux Mint 22.1
Steps to reproduce this
Steps:
- Create two vectors with more than three dimensions
- Use Vector.cross() to compute their cross product
- Observe no errors and a (meaningless) 3D result
Snippet:
function setup() {
let v1 = createVector(1, 0, 0, 2);
let v2 = createVector(0, 0, 1, -1);
let cp = v1.cross(v2);
print(cp.toString());
}
Discussion
The vector cross product is only defined for 3D vectors. I think Vector.cross() should give an error if either vector is not 3D.
Perhaps an special case should be made for 2D vectors, setting their "z" value to zero for the cross product computation. This is in fact what is currently done since the code uses Vector.z, which returns 0 for 2D vectors. Also, the cross() documentation, after stating "This method should only be used with 3D vectors", uses 2D vectors in the examples! Those examples would break if a strict check for three dimensions is implemented. So would the current implementations of angleBetween() and slerp().
This issue applies to both the instance and static methods.
Most appropriate sub-area of p5.js?
p5.js version
2.3.0
Web browser and version
Brave 1.90.122
Operating system
Linux Mint 22.1
Steps to reproduce this
Steps:
Snippet:
Discussion
The vector cross product is only defined for 3D vectors. I think Vector.cross() should give an error if either vector is not 3D.
Perhaps an special case should be made for 2D vectors, setting their "z" value to zero for the cross product computation. This is in fact what is currently done since the code uses Vector.z, which returns 0 for 2D vectors. Also, the cross() documentation, after stating "This method should only be used with 3D vectors", uses 2D vectors in the examples! Those examples would break if a strict check for three dimensions is implemented. So would the current implementations of
angleBetween()andslerp().This issue applies to both the instance and static methods.