# Understanding applymatrix() and linear algebra

**URL:** <https://discourse.processing.org/t/understanding-applymatrix-and-linear-algebra/11068>\
**Category:** Processing\
**Created:** [May 9, 2019, 2:38pm UTC](https://discourse.processing.org/t/understanding-applymatrix-and-linear-algebra/11068 "2019-05-09T14:38:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avatrin](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Avatrin](https://discourse.processing.org/u/Avatrin)\
**Post date:** [May 9, 2019, 2:38pm UTC](https://discourse.processing.org/t/understanding-applymatrix-and-linear-algebra/11068/1 "2019-05-09T14:38:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![raron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/raron/32/13651_2.png) [@raron](https://discourse.processing.org/u/raron)\
**Post date:** [May 9, 2019, 4:46pm UTC](https://discourse.processing.org/t/understanding-applymatrix-and-linear-algebra/11068/2 "2019-05-09T16:46:48Z")

</div>

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

There is an example in the [applyMatrix reference](https://www.processing.org/reference/applyMatrix_.html). 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](https://en.wikipedia.org/wiki/Affine_transformation#Augmented_matrix), since it has one more dimension to include translation ([affline translation](https://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations)). Btw I’m not too familiar with the subject myself, though I have briefly touched it before.

Here’s [another page](https://www.tutorialspoint.com/computer_graphics/3d_transformation.htm) on the subject.

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

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![Avatrin](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Avatrin](https://discourse.processing.org/u/Avatrin)\
**Post date:** [May 9, 2019, 8:42pm UTC](https://discourse.processing.org/t/understanding-applymatrix-and-linear-algebra/11068/3 "2019-05-09T20:42:59Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 9, 2019, 9:20pm UTC](https://discourse.processing.org/t/understanding-applymatrix-and-linear-algebra/11068/4 "2019-05-09T21:20:03Z")

</div>

-Z is away from you

[https://processing.org/tutorials/p3d/](https://processing.org/tutorials/p3d/)

> **[Kango/Processing-snippets](https://github.com/Kango/Processing-snippets/wiki/3D---P3D---OPENGL-BASICS)**
>
> These are small useful snippets. Please feel free to work on it. Best put ready to use functions in it. - Kango/Processing-snippets

---

<div class="post-metadata">

**Author:** ![Avatrin](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Avatrin](https://discourse.processing.org/u/Avatrin)\
**Post date:** [May 12, 2019, 2:51pm UTC](https://discourse.processing.org/t/understanding-applymatrix-and-linear-algebra/11068/5 "2019-05-12T14:51:37Z")

</div>

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.
