Understanding applymatrix() and linear algebra

Hi

How does the applymatrix transformation work in relation to the more “conventional” coordinate systems since, while the x-axis is like in conventional mathematics, the y-axis is not since it points down.

What about the z-axis? Does it point towards me or into the screen?

Also, is there some resource I can use to see the relation between this coordinate system and the more conventional Cartesian coordinate system or do I have to do the calculations myself?

Not sure what you mean about applyMatrix not using a “conventional” coordinate system?

There is an example in the applyMatrix reference. The Y-axis is vertical here. But that will change depending on how the space (coordinate system) and / or the camera view is rotated.

As for calculations I guess it depends on what you want to do. But Processing have a few built-in matrix functions as you can see in the references page (translate, rotate, scale, shear…).

The applyMatrix matrix is called an augmented matrix, since it has one more dimension to include translation (affline translation). Btw I’m not too familiar with the subject myself, though I have briefly touched it before.

Here’s another page on the subject.

Altered the above example slightly to also show Z-axis translation via applyMatrix:

size(200, 200, P3D);
noFill();
translate(100,100, 0);
rotateY(PI/6); 
stroke(0);
box(50);
// Set rotation angles
float ct = cos(PI/9.0);
float st = sin(PI/9.0);          
// Matrix for rotation around the Y axis
applyMatrix(  ct, 0.0,  st,  0.0,
             0.0, 1.0, 0.0,  0.0,
             -st, 0.0,  ct,  0.0,
             0.0, 0.0, 0.0,  1.0);  
stroke(255);
box(75);

//translate(0,0,25); // same as below

applyMatrix( 1.0, 0.0, 0.0,  0.0,
             0.0, 1.0, 0.0,  0.0,
             0.0, 0.0, 1.0, 25.0,
             0.0, 0.0, 0.0,  1.0);  

stroke(255, 100, 50);
box(75);

I meant conventional in regards to which direction it is “pointed”… That is, in regular Cartesian coordinates, the coordinates increase for the y-axis as you move up. However, in the case of Processing, the coordinates increase as you move down.

In the case of the z-axis, the way it’s normally depicted, the coordinates it increases as it moves away from you. I am not sure if this is also the case in Processing.

So, technically, it is the same coordinate system. However, it is depicted differently: We are looking at it from a different angle. So, if I am supposed to show a rotation which moves clockwise on the screen, the matrix will look differently from one which shows the same operation in a linear algebra textbook (especially if it has to rotate about the y-axis, and also the z-axis if its value decreases the further “into” the screen the object has to be)

-Z is away from you

https://processing.org/tutorials/p3d/

2 Likes

Well, I figured it out myself:

To convert between the usual depiction of the coordinates and the ones used here, the space has to be rotated 180 degrees about the x-axis first.