0

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

  1. +90 deg around x-Axis followed by
  2. +90 deg around y-Axis followed by
  3. +90 deg around y-Axis followed by
  4. -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).

Jan
  • 1
  • Unfortunately, your requirements are in conflict. Rotation is order-dependent, and cannot simply sum together into a running total like translations can. If you want to bake a bunch of 90-degree rotations to 3 rotations in a fixed order, you must accept that the angle values may change. If you want to preserve the exact angle totals, then you must accept that your result may contain more than three rotations, in variable order. Can you explain what you're using this for? We might be able to find other ways to meet those needs. – DMGregory Mar 20 '21 at 18:22
  • Thank you! I want to spin a cube with the arrow keys just like on this website: https://paulrhayes.com/experiments/cube-3d/ In the example you can also see the problem i have. The arrow keys perform different rotations, depending on the operations you've applied before. But I want to perform the operations always from the users point of view. And i dont't want to go to the final transformation directly, but rather interpolating from the actual transformation to the final one. – Jan Mar 20 '21 at 18:49
  • Can you explain this constraint then? "But i need the angles and the informations if it's 750 deg (not only 750 mod 360 deg)." <- why is modulo 360 not sufficient for your needs? – DMGregory Mar 20 '21 at 18:50
  • It's for the smooth transition between the actual transformation and the final one. When i have my camera position fixed, i can describe my actual perspective on the cube by 3 rotations, for example (30deg,40deg,10deg). And through the list of rotations i get a final perspective, for example (800deg, 500deg, 1100deg). I want to interpolate between these two perspectives on my cube, without loosing full rotations. – Jan Mar 20 '21 at 18:56
  • Then say "I need smooth rotation", not "I need to know if it's 750 degrees". You don't actually care about 750 per se, you just care about smoothness of interpolation. Don't invent constraints you don't actually have, otherwise you get worse answers. – DMGregory Mar 20 '21 at 19:01

0 Answers0