I have a rectangle parallelepiped in the 3d space like this:
Assume that it's placed on the axis origin and when its rotation is (0,0,0), its largest face (the green) is on XY, its smallest one (the blue) is parallel to YZ.
Assuming I have two (orthogonal) vectors, V1 and V2.
V1 represents the normal of the biggest face (the green one) of the Object3d.
V2, instead, is the normal of the smallest face (the blue one).
Given two new vectors, how can I rotate in the 3d space this parallelepiped so that its faces normals would align to these new vectors?
Example:
const V1 = new Vector3(0, 1, 0);
const V2 = new Vector3(0, 0, 1);
In this configuration, I expect to have this rotation (euler in grad): (-90, 0, -90).
(The resulting solid will have its largest face down on XZ and its smallest on XY).
What I've tried:
const v1 = some_value;
const v2 = some_othen_value; // ortogonal to v1
const q1 = new Quaternion();
q1.setFromUnitVectors(new Vector3(1, 0, 0), v1);
const q2 = new Quaternion();
q2.setFromUnitVectors(new Vector3(0, 0, 1), v2);
parallelepiped.setRotationFromQuaternion(q2.multiply(q1));
This method works for certain configurations but fails badly with others.
Failure example:
V1 = new Vector3(1, 0, 0);
V2 = new Vector3(0, 0, 1);
In this case the resulting rotation is (0, 0, 0), but I would expect something like (0, 90, 90)
Do you have any idea?