Why is it that when I multiply a rotation matrix with the camera matrix -
let rotation = m.mult4(m.rotateX(xRads)),m.rotateY(yRads)));
camera = m.mult4(rotation,camera);
I get incorrect rotation. But when I multiply that same rotation matrix with just the translation portion of the camera matrix I get the correct rotation?
let rotation = m.mult4(m.rotateX(xRads)),m.rotateY(yRads)));
camera = m.mult4(rotation, m.identity([ camera[12], camera[13], camera[14] ]))
Is there some kind of unintended accumulation that's throwing out the result? Is there a way to successfully multiply with the entire camera matrix so I don't have to track rotations separately?
You're doing two different things here: rotate a (presumably) already rotated coordinate system vs. setting the translation component on a newly created rotation matrix.
Is there some kind of unintended accumulation that's throwing out the result?
Unintended by you, yes. Unintended by linear algebra, no.
Is there a way to successfully multiply with the entire camera matrix so I don't have to track rotations separately?
Not really, as even if you were to decompose the matrix you'd have the problem that there's more than one valid result.
Related
From I've understood, the transform order (rotate first or translate first) yield different [R|t].
So I want to know what's the order of the 4 possible poses you got from essential matrix SVD.
I've read a code implementation of Pose From Essential Matrix(Hartley and Zisserman's multiple view geometry (page 259)). And the author seems to interpret it as rotate first then translate, where he retrieve camera position by using p = -R^T * t.
Also, opencv seems to use trasnlate first then rotate rule. Because the t vector I got from calibrating camera is the position of camera.
Or maybe I have been wrong and the order doesn't matter?
You shouldn't use SVD to decompose a transformation into rotation and translation components. Viewed as x' = M*x = T*R*x, the translation is just the fourth column of M, and the rotation is in the upper-left 3x3 submatrix.
If you feed the whole 4x4 matrix into SVD, I'm not sure what you'll get out, but it won't be useful. (If nothing else, U and V will not be affine.)
I have a given 3x3 rotation matrix and I want to calculate the rotation angle around z axis. How do I get there?
For example, in this case below, how did they calculated the "-30deg rotation around the x axis"? Or how did they get to the "-74deg" value around that axis?
This is my original matrix:
Thank you!
It is simple if the rotation matrix is just a rotation matrix and there is no scaling. Here is a site that explains in more pretty terms then I am willing to diagram here. Basically the rotation matrix is composed of sinf(x) and cosf(x) of euler angles (well you can think of it like that at least). You can therefore use values within it to back calculate the euler angles.
http://nghiaho.com/?page_id=846
If you have scaling involved you will need to normalize each row of the matrix first. Then apply the above method.
I have problem when I am trying to apply the rotational matrix on a gravity vector (obtained and stored from a static accelerometer) when the device is moving around with certain rotation (yaw, pitch, roll). The rotation matrix should not change the magnitude of the vector, but in my case, the magnitude of the vector is changing for every iteration. The code below shows the rotational matrix I used:
averageA contains a constant gravity vector, angleypr contains the yam,pitch and roll angle calculated using gyroscope, magnetometer, accelerometer.
temp[0]=averageA[0];
temp[1]=averageA[1];
temp[2]=averageA[2];
//Yaw
temp[0]=cos(angleypr[0]*pi/180)*temp[0]+sin(angleypr[0]*pi/180)*temp[1];
temp[1]=-sin(angleypr[0]*pi/180)*temp[0]+cos(angleypr[0]*pi/180)*temp[1];
temp[2]=temp[2];
//pitch
temp[0]=temp[0];
temp[1]=(cos(angleypr[1]*pi/180))*temp[1]+(sin(angleypr[1]*pi/180))*temp[2];
temp[2]=(-sin(angleypr[1]*pi/180))*temp[1]+cos(angleypr[1]*pi/180))*temp[2];
//roll
temp[0]=(cos(angleypr[2]*pi/180))*temp[0]-(sin(angleypr[2]*pi/180))*temp[2];
temp[1]=temp[1];
temp[2]=(sin(angleypr[2]*pi/180))*temp[0]+(cos(angleypr[2]*pi/180))*temp[2];
gravity[0]=temp[0];
gravity[1]=temp[1];
gravity[2]=temp[2];
a simple example of the problem I am facing now:
temp[0]=cos(angleypr[0]*pi/180)*20+sin(angleypr[0]*pi/180)*30;
temp[1]=-sin(angleypr[0]*pi/180)*20+cos(angleypr[0]*pi/180)*30;
temp[2]=50;
temp[0]=cos(angleypr[0]*pi/180)*temp[0]+sin(angleypr[0]*pi/180)*temp[1];
temp[1]=-sin(angleypr[0]*pi/180)*temp[0]+cos(angleypr[0]*pi/180)*temp[1];
temp[2]=temp[2];
I apply the same yaw rotation matrix on a vector [20,30,50] for twice, the 1st rotation give me a constant magnitude but the the second one end up with varying value for every iteration.
Please let me know where I have done wrongly, thanks in advance!
I would like to find a solution for taking a rotation represented as a matrix and then resetting one of it's components. Basically I want to be able to multiply a vector by this matrix and get a direction that is rotation around x and z axis and be constant along the y axis (up). I want to take object rotation and get the vector that represents gravity but in object local space and disregarding the yaw. So I want to reset the yaw.
I don't want to convert this to euler angles. I would prefer using a quaternion or doing some sequence of operations on the rotation matrix directly in order to avoid possible bugs with certain angles.
Ok, so I have the follwoing:
btTransform t;
mBody->getMotionState()->getWorldTransform(t);
btMatrix3x3 trans = t.getBasis().inverse();
btVector3 up = (trans * btVector3(0, 1, 0));
I realized that if I used quaternion then I got completely wrong results (why?). Now I'm getting a vector in object space that represents up vector in world space. BUT I want to rotate this vector so that it represents global up vector in object space WHEN MODEL HAS ZERO rotation around Y axis. So I have to somehow rotate this vector back. How?
You can use quaternion swing twist decomposition with passed "Y" axis. It will decompose quaternion to rotation around Y axis and rotation around axis that is perpendicular to Y.
It is described here, in my answer.
Component of a quaternion rotation around an axis
I have a 3d object which is free to rotate along x,y and z axis and it is then saved as a transform matrix. In a case where the sequence of rotation is not known and the object is rotated for more than 3 times (eg :-if i rotate the object x-60degress, y-30 degrees, z-45 degrees then again x->30 degrees), is it possible to extract the angles rotated from the transform matrix?.I know that it is possible to get angles if the sequence of rotation is known, but if I have only the final transform matrix with me and nothing else, is it possible to get the angles rotated(x,y,and z) from the transform matrix ?
Euler angle conversion is a pretty well known topic. Just normalize the matrix orientation vectors and then use something like this c source code.
The matrix is the current state of things it has no knowledge of what the transformation has been in the past. It does not know how the matrix was built. You can just take the matrix into and decompose it into any pieces you like, as long as:
The data do not overlap. For example:Two X turns after each other is indistinguishable form each other (no way to know if its 1 2 or three different rotations summed).
The sequence order is known
A decomposition can be built out of the data (for example scale can be measured)