Wednesday, 22 January 2025

Tech Art Math Part 2

 More with Matrices

Why do we use Linear Algebra? To transform objects from one shape to another. Aka moving points from one object space to another. 

    A point can be defined as a vector in 3D space. 

Remember that the w needs to be 1 to be a point, 0 for a vector

Homogeneous Coordinates

    The extra 'w' designates position or orientation in the homogeneous coordinate system. Homogeneous coordinates allow translation to be performed in conjunction with rotations and scales.

    ‘w’ value of 1 accounts for position
    ‘w’ value of 0 accounts for orientation
    When multiplied against a 4x4 matrix a value of “0” nullifies translation

   If you multiple T * A, a 4x4 and 4x1 matrix together, you'll get another 4x1 matrix.

Translation Matrix


    First start with the identity matrix. Then in the 4th column assign the zeros with the z, y, z values you want to translate the point by. 

Scaling Matrix


    Instead of using the identity matrix, put the x,y,z scale value in the diagonal, with a 1 at the end of the diagonal.

Rotation Matrix


    You need three different rotation matrices for rotation. This works as well for 2D, use the z rotation matrix. (assume the theta is in radians)
    Right handed coordinate system determines which direction is the positive or negative rotation. Stick out your right hand, your thumb should point to your left. That is the positive x direction. If you curl your fingers inward, that direction is the positive x rotation. If you point your thumb up, that's the positive y direction. When you curl your fingers inward, that is the positive y rotation. 

    This matrix is for performing all the rotation matrices in one matrix. It's not very practical to use.


    Angle Axis has stuff to do with Quaternions. It helps to find an orientation of a vector. 

Concatenation

    Instead of multiplying point individually against each matrix, the transformation matrix can be concatenated into one matrix. The order is very important and not commutative.
    There are two types of Concatenation: Pre-(right to left) and Post-(left to right) Multiplication. Which one? Depends on what you do, open GL uses post-multiplication. Vulkan is the standard that we're moving towards in cg, so it uses Post-Multiplication 

Global Transformations

    All transformations are done relative to axis origin. 

    Pre-Multiply the matrices together!
p' = M * p = S * T * R * p

Local Transformations

    A transformations affect position and orientation of local axis. 
    Post- Multiply the matrices together
v' = M * v = R * T * S * v

    Why? Both methods can create similar results. OpenGL Fixed pipeline uses post-multiplication, therefore we probably should too. 

    To transform within context of Local coordinates: post multiply!
v' = I * T * Rz *Ry *Rx * S * v 
    This is the default Maya order
    To transform within context of Global coordinates: Pre multiply
v' - S * Rx * Ry * Rz * T I* v

But these are just one convention, Sometimes artists break order. Some softwares switch direction, some software matrices are column major, not row major, so matrices may need to be transposed. 
    Imagine you find the transformation matrix has the values in the bottom row instead of the final column. That means your point has to be transposed so that it fits in one row, so you can multiple a 1x4 and a 4x4 matrix to get the corrected final point. 

No comments:

Post a Comment

Common Art Sprint #1 Delivery

 Responsible for:  Skeleton for Character Assisted in editing layout reel to include timecode, names, and storyboards https://youtu.be/XN5_Z...