Rotation Matrix when moving in one direction - computer-vision

Assuming I have a camera mounted in a rail, I can move it back and forth to take photos of my scene.
Can I assume I have a Rotation Matrix equal to zero?

It depends on the coordinate system you choose. Assuming it's aligned with your camera rotation (e.g. negative Z-axis into viewing direction of the camera and positive y-axis points upwards) and you only move your camera without rotating it, then the rotation matrix, which is used to transform between these coordinate system is the Identity matrix.
A zero matrix makes no sense.

If you assume no rotation, then the rotation matrix is a 3x3 identity matrix, not zero.
Also, this may or may not be a good assumption depending on how accurate you want to be. Even if the camera is moving on a rail, there will be some small rotation.

Related

One Quaternion Camera

Would it be possible to represent a 3D Camera using only a Quaternion? I know that most cameras use an Up vector and a Forward vector to represent it's rotation, but couldn't the same rotation be represented as a single Quaternion with the rotation axis being forward, and the w component being the amount from the Y Axis that the camera was rotated. If there is a way to do this, any resources would be appreciated. Thanks in advance.
In general, no, it's not possible to represent a 3D camera using only a quaternion. This is because a 3D camera not only has an orientation in space, but also a position, and a projection. The quaternion only describes an orientation.
If you're actually asking whether the rotation component of the camera object could be represented as a quaternion, then the answer in general is yes. Quaternions can be easily converted into rotation matrices (Convert Quaternion rotation to rotation matrix?), and back, so anywhere a rotation matrix is used, a quaternion could also be used (and converted to a rotation matrix where appropriate).

How to flip only one axis of transformation matrix?

I have a 4x4 transformation matrix. However, after trying out the transformation I noticed that movement and rotation of the Y axis is going the opposite way. The rest is correct.
I got this matrix from some other API so probably it is the difference of coordinate system. So, how can I flip an axis of transformation matrix?
If only translation I can add minus sign on the Y translation, but I have no idea about opposite rotation of only one axis since all the rotation is being represented in the same 3x3 area. I thought there might be some way that even affect both translation and rotation at the same time. (truly flipping the axis)
Edit: I'm pretty sure the operation you're looking for is changing coordinate systems while maintaining Z-up or Y-up. In this case, try setting all the elements of the second column (or row) of your matrix to their inverse.
This question would be better for the Math StackExchange. First, a really helpful read on rotation matrices.
The first problem is the matter of rotation order. I will be assuming the XYZ rotation order. We know the rotation matrices for each axis is as follows:
Given a matrix derived from the same rotation order, the resulting matrix would be as follows, where alpha is the X angle, beta is the Y angle, and gamma is the Z angle:
You can derive the individual components of each axis angle from this matrix. For example, you can derive the Y angle from -sin(beta) using some inverse trig. Given beta, you can derive alpha from cos(beta)sin(alpha). You can also derive gamma from cos(beta)sin(gamma). Note that the same number in the matrix can represent multiple values (e.g. sin(0)=0 and sin(180)=0).
Now that you know alpha, beta, and gamma, you can reverse beta and remake the rotation matrix.
There's a good chance that there's a better way to do this using quaternions, but you should ask the Math StackExchange these kinds of language-agnostic questions.
Much shorter answer: if you are not careful with your frame orientation many things down your pipeline are likely to have a bad hair day. The reason is "parity", a.k.a. "frame orientation", a.k.a. "right-handedness" (or rarely left-handedness). Most 3D geometry tools and libraries that work together normally assume implicitly that all coordinate systems in play are right-handed (or at least consistently-handed). Inverting the orientation of just one axis in a coordinate system changes its orientation from right to left handed or viceversa.
So, suggestion for things to check & try in your problem:
Check that the frame you get from your API is right-handed. You do so
by computing the determinant of the 3x3 rotation part of your 4x4 transform matrix: it must be +1 or very close to it.
If it is -1, then flip one if its axis, i.e. change the sign of one of the columns of the 3x3 rotation.
Note carefully: I said "columns" because I assume that you apply a transform Q to a point x by multiplying as Q * x, x being a 4x1 column vector with the last component equal to one. If you use row vectors left-multiplied by Q you need flip a row.
If that determinant is +1, you have a bug someplace else.

Why does the camera face the negative end of the z-axis by default?

I am learning openGL from this scratchpixel, and here is a quote from the perspective project matrix chapter:
Cameras point along the world coordinate system negative z-axis so that when a point is converted from world space to camera space (and then later from camera space to screen space), if the point is to left of the world coordinate system y-axis, it will also map to the left of the camera coordinate system y-axis. In other words, we need the x-axis of the camera coordinate system to point to the right when the world coordinate system x-axis also points to the right; and the only way you can get that configuration, is by having camera looking down the negative z-axis.
I think it has something to do with the mirror image? but this explanation just confused me...why is the camera's coordinate by default does not coincide with the world coordinate(like every other 3D objects we created in openGL)? I mean, we will need to transform the camera coordinate anyway with a transformation matrix (whatever we want with the negative z set up, we can simulate it)...why bother?
It is totally arbitrary what to pick for z direction.
But your pick has a lot of deep impact.
One reason to stick with the GL -z way is that the culling of faces will match GL constant names like GL_FRONT. I'd advise just to roll with the tutorial.
Flipping the sign on just one axis also flips the "parity". So a front face becomes a back face. A znear depth test becomes zfar. So it is wise to pick one early on and stick with it.
By default, yes, it's "right hand" system (used in physics, for example). Your thumb is X-axis, index finger Y-axis, and when you make those go to right directions, Z-points (middle finger) to you. Why Z-axis has been selected to point inside/outside screen? Because then X- and Y-axes go on screen, like in 2D graphics.
But in reality, OpenGL has no preferred coordinate system. You can tweak it as you like. For example, if you are making maze game, you might want Y to go outside/inside screen (and Z upwards), so that you can move nicely at XY plane. You modify your view/perspective matrices, and you get it.
What is this "camera" you're talking about? In OpenGL there is no such thing as a "camera". All you've got is a two stage transformation chain:
vertex position → viewspace position (by modelview transform)
viewspace position → clipspace position (by projection transform)
To see why be default OpenGL is "looking down" -z, we have to look at what happens if both transformation steps do "nothing", i.e. full identity transform.
In that case all vertex positions passed to OpenGL are unchanged. X maps to window width, Y maps to window height. All calculations in OpenGL by default (you can change that) have been chosen adhere to the rules of a right hand coordinate system, so if +X points right and +Y points up, then Z+ must point "out of the screen" for the right hand rule to be consistent.
And that's all there is about it. No camera. Just linear transformations and the choice of using right handed coordinates.

OpenGL camera direction

So I was reading this tutorial's "Inverting the Camera Orientation Matrix" section and I don't understand why, when calculating the camera's up direction, I need to multiply the inverse of orientation by the up direction vector, and not just orientation.
I drew the following image to illustrate my insight of the tutorial I read.
What did I get wrong?
Well, that tutorial explicitely states:
The way we calculate the up direction of the camera is by taking the
"directly upwards" unit vector (0,1,0) and "unrotate" it by using the
inverse of the camera's orientation matrix. Or, to explain it
differently, the up direction is always (0,1,0) after the camera
rotation has been applied, so we multiply (0,1,0) by the inverse
rotation, which gives us the up direction before the camera rotation
was applied.
The up direction which is calculated here is the up direction in world space. In eye space, the up vector is (0,1,0) (by convention, one could define it differently). As the view matrix will transform coordinates from world space to eye space, we need to use the inverse to transform that up vector from eye space to the world space. Your image is wrong as it does not correctly relate to eye and world space.

opengl basic transformation

A vector can be rotated and scaled, since it has direction and scale. But does it mean by plotting a point. Point can only be translated. But wikipedia says "For example the matrix
R = [ cos0,-sin0]
[ sin0,cos0]
rotates points in the xy-Cartesian plane counter-clockwise through an angle θ about the origin of the Cartesian coordinate system.
Also what does it mean by "since matrix multiplication has no effect on the zero vector (the coordinates of the origin), rotation matrices can only be used to describe rotations about the origin of the coordinate system."? Does this mean I cannot perform rotation around any point other than the origin?
Absolutely, to rotate about another point than the origin, you have to create a matrix that translates your vertices from your rotation center to the origin, rotates, then translates back from the origin to your rotation center.
When describing transformations, Wikipedia and other sites often refer to the effect on "points"; however this implicitly applies to every point in the coordinate system (with explicit exceptions like rotation of the origin.) These transformations - typically rotating, translating, and scaling - apply to the entire frame of reference and any derivative frames of reference. Use of the word 'point' is in the mathematical sense, a choice of coordinates within a coordinate system, and doesn't imply anything about a point in the graphical sense, like a "plotted" or "drawn" point (although graphing a point is just a visualization of this concept, so the distinction is moot.)
While it's true that a rotation has no effect on the origin, you are free to translate the origin itself, or equivalently to translate your models relative to the origin. Once you have applied the rotation, you can reverse the translation to restore the original origin.