Go to the source code of this file.
Data Structures | |
struct | s_matrix |
The struct t_matrix stores a matrix up to 4x4 and size of 16. A matrix is a grid of numbers that can be manipulated as a single unit. Matrices and their operations are the foundational basis which will helps us to manipulate points, vectors and, ultimately, shapes. More... | |
struct | s_shearing |
The struct t_shearing is a helper type to allow shearing operation on matrices. Shearing (or skew) is a complex operation where the coordinate is changed in proportion to the other two coordinates. When doing it to a matrix, it means that x will change in proportion to y and z, y will change in proportion to x and z and, lastly, z will change in proportion to x and y. For example, to apply shearing to the x axis of a given matrix, we pass to shearing() a struct of type t_shearing containing the y and z values. For instance, when done to the y axis, we pass p1 and p2 which stands for x and z. Lastly, when applying it to the z axis, we pass x and y as p1 and p2, respectively. More... | |
Macros | |
#define | MAX 4 |
#define | SIZE 16 |
Typedefs | |
typedef struct s_matrix | t_matrix |
The struct t_matrix stores a matrix up to 4x4 and size of 16. A matrix is a grid of numbers that can be manipulated as a single unit. Matrices and their operations are the foundational basis which will helps us to manipulate points, vectors and, ultimately, shapes. More... | |
typedef struct s_shearing | t_shearing |
The struct t_shearing is a helper type to allow shearing operation on matrices. Shearing (or skew) is a complex operation where the coordinate is changed in proportion to the other two coordinates. When doing it to a matrix, it means that x will change in proportion to y and z, y will change in proportion to x and z and, lastly, z will change in proportion to x and y. For example, to apply shearing to the x axis of a given matrix, we pass to shearing() a struct of type t_shearing containing the y and z values. For instance, when done to the y axis, we pass p1 and p2 which stands for x and z. Lastly, when applying it to the z axis, we pass x and y as p1 and p2, respectively. More... | |
Functions | |
t_matrix | multiply_mx_mx (t_matrix a, t_matrix b) |
This function multiplies two matrices. "Mx" means matrix. For more information about how matrix multiplication works, refer to the book TRTC on page 28. More... | |
t_tuple | multiply_tp_mx (t_matrix a, t_tuple b) |
This function multiplies a matrix by a tuple. "Mx" means matrix and "tp" means tuple. For more information about how vector and matrix multiplication works, refer to the following link quoted by author J. Buck: https://betterexplained.com/articles/linear-algebra-guide/. More... | |
t_matrix | transpose (t_matrix t) |
This function transposes the matrix passed to the function as parameter. In other words, it turns the first row into the first column, the second row into the second column, and so forth. Thus, it's importante to remember that the transpose of the identity matrix always gives the own identity matrix as result. More... | |
t_matrix | inverse (t_matrix t) |
This function get the inverse of a given matrix. That is, if you multiply some matrix A by another matrix B, producing C, you can multiply C by the inverse of B to get A again. To invert the matrix, this function employs a method known as cofactor expansion. Additionally, there some interesting properties of the inverse: 1) if you invert an identity matrix, the result is also an identity matrix. 2) when you multiply a matrix by its inverse, you get as result the identity matrix. 3) The inverse of the transpose of a matrix and the transpose of the inverse only commute if the matrix is symmetric or orthogonal. Otherwise, the result of the two operations will always be different. More... | |
t_matrix | translation (double x, double y, double z) |
This function translates a given matrix. Translation is a transformation that moves a point. Thus, it's important to note that the inverse of a translation matrix is another translation matrix that moves points in reverse. More... | |
t_matrix | scaling (double x, double y, double z) |
This function scales a given matrix by multiplication. When applied to an object centered at the origin, this transformation scales all points on the object, effectively making it larger (if the scale value is greater than 1) or smaller (if the scale value is less than 1). Note that reflection is scaling by a negative value. More... | |
t_matrix | shearing (t_shearing x, t_shearing y, t_shearing z) |
This function applies shearing (or skew) transformation to a given matrix. It has the effect of making straight lines slanted. Each coordinate is changed in proportion to the other two coordinates. When doing it to a matrix, it means that x will change in proportion to y and z, y will change in proportion to x and z and, lastly, z will change in proportion to x and y. More... | |
t_matrix | rotation_x (double rad) |
This function rotates a given matrix around the x-axis. More... | |
t_matrix | rotation_y (double rad) |
This function rotates a given matrix around the y-axis. More... | |
t_matrix | rotation_z (double rad) |
This function rotates a given matrix around the z-axis. More... | |
double | get_determinant (t_matrix t) |
This function gets the determinant of a given matrix. The determinant is a number that is derived from the elements of a matrix. The name comes from the use of matrices to solve systems of equations, where it’s used to determine whether or not the system has a solution. If the determinant is zero, then the corresponding system of equations has no solution. More... | |
t_matrix | get_submatrix (t_matrix t, size_t del_row, size_t del_col) |
This functions gets the submatrix of a given matrix. That is, what is left when you delete a single row and column from a matrix. The submatrix of a 4x4 matrix is 3x3 and the submatrix of a 3x3 matrix is 2x2. More... | |
double | get_minor (t_matrix t, size_t row, size_t col) |
This function gets the minor of a given matrix. To put it differently, the minor of an element at row i and column j is the determinant of the submatrix at (i,j). More... | |
double | get_cofactor (t_matrix t, size_t row, size_t col) |
This function gets the cofactor of a given matrix. Cofactors are minors that have (possibly) had their sign changed. If row + column equals to an odd number as result, the minor must be negated. Therefore, if the row and column identifies a spot with a +, then the minor’s sign doesn’t change. If the row and column identifies a spot with a -, then the minor must be negated. More... | |
t_matrix | get_identity_matrix (void) |
This fucntion gets a new matrix with the special attribute of being an identity matrix or multiplicative identity. That is, if you multiply any matrix or tuple by the identity matrix, you get back the matrix or tuple you started with. More... | |
t_shearing | to_shear (double a, double b) |
t_matrix | create_matrix (const double table[MAX][MAX], size_t size) |
This function creates a matrix up to 4x4 and, therefore, size of 16 (4x4). For instance, a matrix of 3x3 will have a size of 9(3x3). More... | |
int | compare_matrix (t_matrix a, t_matrix b) |
The function compare_matrix() checks if two matrices are identical or not. The matrices passed as parameter to the function are compared with ft_memcmp(). More... | |
t_bool | is_invertible (t_matrix t) |
This function checks if a given matrix is invertible or not. Not every matrix is invertible. An matrix is invertible if its determinant is a non-zero number. If its determinant is 0, then the given matrix is not invertible. More... | |
t_matrix | rotation_matrix (t_vector vector) |
Calculates the rotation matrix for a given vector. More... | |
The struct t_matrix stores a matrix up to 4x4 and size of 16. A matrix is a grid of numbers that can be manipulated as a single unit. Matrices and their operations are the foundational basis which will helps us to manipulate points, vectors and, ultimately, shapes.
matrix | Stores a matrix. |
size | Stores the size of the matrix. For example, a matrix of 3x3 has a size of 9. For instance, a 2x2 matrix has a size of 4. |
typedef struct s_shearing t_shearing |
The struct t_shearing is a helper type to allow shearing operation on matrices. Shearing (or skew) is a complex operation where the coordinate is changed in proportion to the other two coordinates. When doing it to a matrix, it means that x will change in proportion to y and z, y will change in proportion to x and z and, lastly, z will change in proportion to x and y. For example, to apply shearing to the x axis of a given matrix, we pass to shearing() a struct of type t_shearing containing the y and z values. For instance, when done to the y axis, we pass p1 and p2 which stands for x and z. Lastly, when applying it to the z axis, we pass x and y as p1 and p2, respectively.
p1 | The first value to be used as proportion for shearing. |
p2 | The second value to be used as proportion for shearing. |
The function compare_matrix() checks if two matrices are identical or not. The matrices passed as parameter to the function are compared with ft_memcmp().
a | Receives the first matrix to be compared. |
b | Receives the second matrix to be compared. |
t_matrix create_matrix | ( | const double | table[MAX][MAX], |
size_t | size | ||
) |
This function creates a matrix up to 4x4 and, therefore, size of 16 (4x4). For instance, a matrix of 3x3 will have a size of 9(3x3).
table | A bidimensional array of const double containing the matrix. |
size | A size_t value containing how much elements the array has. |
double get_cofactor | ( | t_matrix | t, |
size_t | row, | ||
size_t | col | ||
) |
This function gets the cofactor of a given matrix. Cofactors are minors that have (possibly) had their sign changed. If row + column equals to an odd number as result, the minor must be negated. Therefore, if the row and column identifies a spot with a +, then the minor’s sign doesn’t change. If the row and column identifies a spot with a -, then the minor must be negated.
t | Receives the matrix from which the cofactor will be calculated. |
row | Receives the row value from which the cofactor will be calculated. |
col | Receives the column value from which the cofactor will be calculated. |
double get_determinant | ( | t_matrix | t | ) |
This function gets the determinant of a given matrix. The determinant is a number that is derived from the elements of a matrix. The name comes from the use of matrices to solve systems of equations, where it’s used to determine whether or not the system has a solution. If the determinant is zero, then the corresponding system of equations has no solution.
t | Receives the matrix to calculate its determinant. |
t_matrix get_identity_matrix | ( | void | ) |
This fucntion gets a new matrix with the special attribute of being an identity matrix or multiplicative identity. That is, if you multiply any matrix or tuple by the identity matrix, you get back the matrix or tuple you started with.
double get_minor | ( | t_matrix | t, |
size_t | row, | ||
size_t | col | ||
) |
This function gets the minor of a given matrix. To put it differently, the minor of an element at row i and column j is the determinant of the submatrix at (i,j).
t | Receives the matrix from which the minor will be calculated. |
row | Receives the row value from which the minor will be calculated. |
col | Receives the column value from which the minor will be calculated. |
This functions gets the submatrix of a given matrix. That is, what is left when you delete a single row and column from a matrix. The submatrix of a 4x4 matrix is 3x3 and the submatrix of a 3x3 matrix is 2x2.
t | Receives the matrix from which the submatrix will be calculated. |
del_row | Receives a size_t value which stands for the row to be deleted when calculating the submatrix. |
del_col | Receives a size_t value which stands for the column to be deleted when calculating the submatrix. |
This function get the inverse of a given matrix. That is, if you multiply some matrix A by another matrix B, producing C, you can multiply C by the inverse of B to get A again. To invert the matrix, this function employs a method known as cofactor expansion. Additionally, there some interesting properties of the inverse: 1) if you invert an identity matrix, the result is also an identity matrix. 2) when you multiply a matrix by its inverse, you get as result the identity matrix. 3) The inverse of the transpose of a matrix and the transpose of the inverse only commute if the matrix is symmetric or orthogonal. Otherwise, the result of the two operations will always be different.
t | Receives the matrix to be inverted. |
t_bool is_invertible | ( | t_matrix | t | ) |
This function checks if a given matrix is invertible or not. Not every matrix is invertible. An matrix is invertible if its determinant is a non-zero number. If its determinant is 0, then the given matrix is not invertible.
t | Receives a matrix to be checked. |
This function multiplies two matrices. "Mx" means matrix. For more information about how matrix multiplication works, refer to the book TRTC on page 28.
a | Receives the first matrix to be multiplied. |
b | Receives the second matrix to be multiplied. |
This function multiplies a matrix by a tuple. "Mx" means matrix and "tp" means tuple. For more information about how vector and matrix multiplication works, refer to the following link quoted by author J. Buck: https://betterexplained.com/articles/linear-algebra-guide/.
a | Receives the matrix to be multiplied. |
b | Receives the tuple to be multiplied. |
Calculates the rotation matrix for a given vector.
vector | The vector for which the rotation matrix will be calculated. |
t_matrix rotation_x | ( | double | rad | ) |
This function rotates a given matrix around the x-axis.
rad | Receives the rotation around x axis to be performed in radians. |
t_matrix rotation_y | ( | double | rad | ) |
This function rotates a given matrix around the y-axis.
rad | Receives the rotation around y axis to be performed in radians. |
t_matrix rotation_z | ( | double | rad | ) |
This function rotates a given matrix around the z-axis.
rad | Receives the rotation around z axis to be performed in radians. |
t_matrix scaling | ( | double | x, |
double | y, | ||
double | z | ||
) |
This function scales a given matrix by multiplication. When applied to an object centered at the origin, this transformation scales all points on the object, effectively making it larger (if the scale value is greater than 1) or smaller (if the scale value is less than 1). Note that reflection is scaling by a negative value.
x | Receives the x-axis value to scale. |
y | Receives the y-axis value to scale. |
z | Receives the z-axis value to scale. |
t_matrix shearing | ( | t_shearing | x, |
t_shearing | y, | ||
t_shearing | z | ||
) |
This function applies shearing (or skew) transformation to a given matrix. It has the effect of making straight lines slanted. Each coordinate is changed in proportion to the other two coordinates. When doing it to a matrix, it means that x will change in proportion to y and z, y will change in proportion to x and z and, lastly, z will change in proportion to x and y.
x | Receives a struct t_shearing storing the y and z values to change x in proportion to them. |
y | Receives a struct t_shearing storing the x and z values to change y in proportion to them. |
z | Receives a struct t_shearing storing the x and y values to change z in proportion to them. |
t_matrix translation | ( | double | x, |
double | y, | ||
double | z | ||
) |
This function translates a given matrix. Translation is a transformation that moves a point. Thus, it's important to note that the inverse of a translation matrix is another translation matrix that moves points in reverse.
x | Receives the x-axis value of the translation. |
y | Receives the y-axis value of the translation. |
z | Receives the z-axis value of the translation. |
This function transposes the matrix passed to the function as parameter. In other words, it turns the first row into the first column, the second row into the second column, and so forth. Thus, it's importante to remember that the transpose of the identity matrix always gives the own identity matrix as result.
t | Receives the matrix to be transposed. |