Most appropriate sub-area of p5.js?
p5.js version
2.3.1
Web browser and version
Chrome
Operating system
Windows
Steps to reproduce this
Steps:
- create q0 = new p5.Quat(1,2,3,4);
- create q1 = new p5.Quat(3,1,4,8);
- create q2 = q0.multiply(q1);
- q2.w is incorrect.
Snippet:
function setup() {
createCanvas(400, 400);
const q0 = new p5.Quat(1,2,3,4);
const q1 = new p5.Quat(3,1,4,8);
const q2 = q0.multiply(q1);
console.log(q2.w); // -23
console.log(q0.w * q1.w - q0.vec.dot(q1.vec)); // -43
console.log(
q0.w*q1.w - q0.vec.x*q1.vec.x - q0.vec.y*q1.vec.y - q0.vec.z - q1.vec.z
); // -23
}
It seems that the multiplication operation in p5.Quat is incorrect.
ver: 2.3.1
/**
* Multiplies a quaternion with other quaternion.
* @method mult
* @param {p5.Quat} [quat] quaternion to multiply with the quaternion calling the method.
* @chainable
*/
multiply(quat) {
return new Quat(
this.w * quat.w - this.vec.x * quat.vec.x - this.vec.y * quat.vec.y - this.vec.z - quat.vec.z, // incorrect
this.w * quat.vec.x + this.vec.x * quat.w + this.vec.y * quat.vec.z - this.vec.z * quat.vec.y,
this.w * quat.vec.y - this.vec.x * quat.vec.z + this.vec.y * quat.w + this.vec.z * quat.vec.x,
this.w * quat.vec.z + this.vec.x * quat.vec.y - this.vec.y * quat.vec.x + this.vec.z * quat.w
);
}
The correct version is as follows.
return new Quat(
this.w * quat.w - this.vec.x * quat.vec.x - this.vec.y * quat.vec.y - this.vec.z * quat.vec.z,
this.w * quat.vec.x + this.vec.x * quat.w + this.vec.y * quat.vec.z - this.vec.z * quat.vec.y,
this.w * quat.vec.y - this.vec.x * quat.vec.z + this.vec.y * quat.w + this.vec.z * quat.vec.x,
this.w * quat.vec.z + this.vec.x * quat.vec.y - this.vec.y * quat.vec.x + this.vec.z * quat.w
);
Most appropriate sub-area of p5.js?
p5.js version
2.3.1
Web browser and version
Chrome
Operating system
Windows
Steps to reproduce this
Steps:
Snippet:
It seems that the multiplication operation in p5.Quat is incorrect.
ver: 2.3.1
The correct version is as follows.