I have a list of rotations (on a cube in 3d space with the y-Axis pointing upwards, x-Axis pointing righthand and z-Axis pointing towards you) for example
- +90 deg around x-Axis followed by
- +90 deg around y-Axis followed by
- +90 deg around y-Axis followed by
- -90 deg around x-Axis
All rotations are only of type (+- 90 deg around x / y). The list can be of any length. My goal is to break it down to only three operations. I can't figure out how to calculate the three arguments xDeg,yDeg,zDeg which i can apply in the same order to rotateX,rotateY,rotateZ to get the same result as applying the complete list one after another to the rotation-functions. i tried to build up a permutation matrix depending on the actual position in the list of rotations when i iterate over it to apply the current deg value of a list item to either xDeg,yDeg,zDeg. I couldn't make ist work.
var gTrans = (function() {
var perm = [[1,0,0],[0,1,0],[0,0,1]];
var set = [0,0,0];
function rotateUp() {
//set = math.chain(set).add(math.multiply(perm,[-90,0,0])).done();
//set = math.chain(set).add([-90,0,0]).multiply(math.transpose(perm)).done();
perm = math.multiply([[1,0,0],[0,0,1],[0,-1,0]],perm);
set[0] -= 90;
}
function rotateDown() {
//set = math.chain(set).add(math.multiply(perm,[90,0,0])).done();
//set = math.chain(set).add([90,0,0]).multiply(math.transpose(perm)).done();
perm = math.multiply([[1,0,0],[0,0,-1],[0,1,0]],perm);
set[0] += 90;
}
function rotateLeft() {
//set = math.chain(set).add(math.multiply(perm,[0,-90,0])).done();
//set = math.chain(set).add([0,-90,0]).multiply(math.transpose(perm)).done();
perm = math.multiply([[0,0,-1],[0,1,0],[1,0,0]],perm);
set[1] -= 90;
}
function rotateRight() {
//set = math.chain(set).add(math.multiply(perm,[0,90,0])).done();
//set = math.chain(set).add([0,90,0]).multiply(math.transpose(perm)).done();
perm = math.multiply([[0,0,1],[0,1,0],[-1,0,0]],perm);
set[1] += 90;
}
})();
The code above is written with javascript, p5js and mathjs libs. Does someone have an idea? I know it's possible to simply multiply the rotation matrices. But i need the angles and the informations if it's 750 deg (not only 750 mod 360 deg).