pub struct Matrix4 { /* private fields */ }Expand description
- Matrix4 Module
- 2D Representation of a 4x4 Matrix
- It’s a row-major matrix.
Implementations§
Source§impl Matrix4
impl Matrix4
Sourcepub fn elements(&self) -> Vec<f64>
pub fn elements(&self) -> Vec<f64>
Examples found in repository?
examples/matrix-example.rs (line 6)
3fn main() {
4 // Create a new Matrix4 instance
5 let mut m1 = Matrix4::new();
6 println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8 // Set m1 to identity matrix
9 m1.identity();
10 println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12 // Create another Matrix4 instance with specific elements
13 let m2 = Matrix4::set(
14 1.0, 2.0, 3.0, 4.0,
15 5.0, 6.0, 7.0, 8.0,
16 9.0, 10.0, 11.0, 12.0,
17 13.0, 14.0, 15.0, 16.0,
18 );
19
20 println!("3. Matrix4 m2: {:?}", m2.elements());
21
22 // // Multiply two matrices
23 // let m3 = m1.clone().multiply(&m2);
24 // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26 // // Add two matrices
27 // let m4 = m1.clone().add(&m2);
28 // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30 // // Subtract two matrices
31 // let m5 = m2.clone().subtract(&m1);
32 // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34 // Determinant of a matrix m6
35 let m6 = Matrix4::set(
36 1.0, 2.0, 3.0, 4.0,
37 5.0, 6.0, 7.0, 8.0,
38 9.0, 10.0, 11.0, 12.0,
39 13.0, 14.0, 15.0, 16.0,
40 );
41 let det = m6.determinant();
42 println!("7. Determinant of m6: {}", det);
43
44 // // Adjugate of a matrix
45 // let adj = m6.adjucate();
46 // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48 // // Inverse of a matrix
49 // let m7 = m6.clone().inverse();
50 // println!("9. Inverse of m6: {:?}", m7.elements);
51
52 // // Check if the inverse is correct by multiplying m6 with its inverse
53 // let m6_cloned = m6.clone();
54 // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55 // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56
57 // // Check if the inverse multiplication gives identity matrix
58 // let identity_check = m6_inverse_multiplied.is_identity();
59 // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61 // Transpose of a matrix
62 let m8 = m2.clone().transpose();
63 println!("12. Transpose of m2: {:?}", m8.elements());
64}Sourcepub fn new() -> Matrix4
pub fn new() -> Matrix4
- Create a new Matrix4 with identity elements.
Examples found in repository?
examples/matrix-example.rs (line 5)
3fn main() {
4 // Create a new Matrix4 instance
5 let mut m1 = Matrix4::new();
6 println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8 // Set m1 to identity matrix
9 m1.identity();
10 println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12 // Create another Matrix4 instance with specific elements
13 let m2 = Matrix4::set(
14 1.0, 2.0, 3.0, 4.0,
15 5.0, 6.0, 7.0, 8.0,
16 9.0, 10.0, 11.0, 12.0,
17 13.0, 14.0, 15.0, 16.0,
18 );
19
20 println!("3. Matrix4 m2: {:?}", m2.elements());
21
22 // // Multiply two matrices
23 // let m3 = m1.clone().multiply(&m2);
24 // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26 // // Add two matrices
27 // let m4 = m1.clone().add(&m2);
28 // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30 // // Subtract two matrices
31 // let m5 = m2.clone().subtract(&m1);
32 // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34 // Determinant of a matrix m6
35 let m6 = Matrix4::set(
36 1.0, 2.0, 3.0, 4.0,
37 5.0, 6.0, 7.0, 8.0,
38 9.0, 10.0, 11.0, 12.0,
39 13.0, 14.0, 15.0, 16.0,
40 );
41 let det = m6.determinant();
42 println!("7. Determinant of m6: {}", det);
43
44 // // Adjugate of a matrix
45 // let adj = m6.adjucate();
46 // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48 // // Inverse of a matrix
49 // let m7 = m6.clone().inverse();
50 // println!("9. Inverse of m6: {:?}", m7.elements);
51
52 // // Check if the inverse is correct by multiplying m6 with its inverse
53 // let m6_cloned = m6.clone();
54 // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55 // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56
57 // // Check if the inverse multiplication gives identity matrix
58 // let identity_check = m6_inverse_multiplied.is_identity();
59 // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61 // Transpose of a matrix
62 let m8 = m2.clone().transpose();
63 println!("12. Transpose of m2: {:?}", m8.elements());
64}Sourcepub fn set(
m0: f64,
m1: f64,
m2: f64,
m3: f64,
m4: f64,
m5: f64,
m6: f64,
m7: f64,
m8: f64,
m9: f64,
m10: f64,
m11: f64,
m12: f64,
m13: f64,
m14: f64,
m15: f64,
) -> Matrix4
pub fn set( m0: f64, m1: f64, m2: f64, m3: f64, m4: f64, m5: f64, m6: f64, m7: f64, m8: f64, m9: f64, m10: f64, m11: f64, m12: f64, m13: f64, m14: f64, m15: f64, ) -> Matrix4
Examples found in repository?
examples/matrix-example.rs (lines 13-18)
3fn main() {
4 // Create a new Matrix4 instance
5 let mut m1 = Matrix4::new();
6 println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8 // Set m1 to identity matrix
9 m1.identity();
10 println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12 // Create another Matrix4 instance with specific elements
13 let m2 = Matrix4::set(
14 1.0, 2.0, 3.0, 4.0,
15 5.0, 6.0, 7.0, 8.0,
16 9.0, 10.0, 11.0, 12.0,
17 13.0, 14.0, 15.0, 16.0,
18 );
19
20 println!("3. Matrix4 m2: {:?}", m2.elements());
21
22 // // Multiply two matrices
23 // let m3 = m1.clone().multiply(&m2);
24 // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26 // // Add two matrices
27 // let m4 = m1.clone().add(&m2);
28 // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30 // // Subtract two matrices
31 // let m5 = m2.clone().subtract(&m1);
32 // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34 // Determinant of a matrix m6
35 let m6 = Matrix4::set(
36 1.0, 2.0, 3.0, 4.0,
37 5.0, 6.0, 7.0, 8.0,
38 9.0, 10.0, 11.0, 12.0,
39 13.0, 14.0, 15.0, 16.0,
40 );
41 let det = m6.determinant();
42 println!("7. Determinant of m6: {}", det);
43
44 // // Adjugate of a matrix
45 // let adj = m6.adjucate();
46 // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48 // // Inverse of a matrix
49 // let m7 = m6.clone().inverse();
50 // println!("9. Inverse of m6: {:?}", m7.elements);
51
52 // // Check if the inverse is correct by multiplying m6 with its inverse
53 // let m6_cloned = m6.clone();
54 // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55 // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56
57 // // Check if the inverse multiplication gives identity matrix
58 // let identity_check = m6_inverse_multiplied.is_identity();
59 // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61 // Transpose of a matrix
62 let m8 = m2.clone().transpose();
63 println!("12. Transpose of m2: {:?}", m8.elements());
64}More examples
examples/vector-example.rs (lines 99-104)
3fn main() {
4 // Create two Vector3 instances
5 let mut v1 = Vector3::new(1.0, 2.0, 3.0);
6 let v2 = Vector3::new(4.0, 5.0, 6.0);
7
8 // Vector addition
9 v1.add(&v2);
10 println!("1. Elements of v1 after addition: ({}, {}, {})", v1.x, v1.y, v1.z);
11
12 // Adding a Scalar value to a Vector3
13 let mut v3 = Vector3::new(1.0, 3.0, 2.0);
14 v3.add_scalar(2.0);
15 println!("2. Adding a Scalar to v3, new elements: ({}, {}, {})", v3.x, v3.y, v3.z);
16
17 // Subtracting a Vector3
18 let mut v4 = Vector3::new(10.0, 9.0, 8.0);
19 v4.subtract(&v2);
20 println!("3. Elements of v4 after subtraction: ({}, {}, {})", v4.x, v4.y, v4.z);
21
22 // Subtracting a Scalar value from a Vector3
23 let mut v5 = Vector3::new(5.0, 6.0, 7.0);
24 v5.subtract_scalar(3.0);
25 println!("4. Subtracting a Scalar from v5, new elements: ({}, {}, {})", v5.x, v5.y, v5.z);
26
27 // Cloning a Vector3
28 let v6 = v1.clone();
29 println!("5. Cloned Vector3 v6: ({}, {}, {})", v6.x, v6.y, v6.z);
30
31 // Zeroing a Vector3
32 let mut v7 = Vector3::new(8.0, 9.0, 10.0);
33 v7.zero();
34 println!("6. Zeroed Vector3 v7: ({}, {}, {})", v7.x, v7.y, v7.z);
35
36 // Copying a Vector3
37 let mut v8 = Vector3::new(2.0, 3.0, 4.0);
38 v8.copy(&v6);
39 println!("7. Copied Vector3 v8 from v6: ({}, {}, {})", v8.x, v8.y, v8.z);
40
41 // Multiplying a Vector3 by a scalar
42 let mut v9 = Vector3::new(1.0, 2.0, 3.0);
43 v9.multiply_scalar(2.0);
44 println!("8. v9 after multiplying by scalar: ({}, {}, {})", v9.x, v9.y, v9.z);
45
46 // Multiply two vectors
47 let v10 = Vector3::new(2.0, 3.0, 4.0);
48 let v11 = Vector3::new(5.0, 6.0, 7.0);
49 let mut v12 = v10.clone();
50 v12.multiply(&v11);
51 println!("9. v12 after multiplying v10 and v11: ({}, {}, {})", v12.x, v12.y, v12.z);
52
53 // Divide a Vector3 by a scalar
54 let mut v13 = Vector3::new(10.0, 20.0, 30.0);
55 v13.divide_scalar(2.0);
56 println!("10. v13 after dividing by scalar: ({}, {}, {})", v13.x, v13.y, v13.z);
57
58 // Divide two vectors
59 let mut v14 = Vector3::new(20.0, 30.0, 40.0);
60 let v15 = Vector3::new(2.0, 3.0, 4.0);
61 v14.divide(&v15);
62 println!("11. v14 after dividing by v15: ({}, {}, {})", v14.x, v14.y, v14.z);
63
64 // Negate a Vector3
65 let mut v16 = Vector3::new(1.0, -2.0, 3.0);
66 v16.negate();
67 println!("12. v16 after negation: ({}, {}, {})", v16.x, v16.y, v16.z);
68
69 // Dot product of two vectors
70 let v17 = Vector3::new(1.0, 2.0, 3.0);
71 let v18 = Vector3::new(4.0, 5.0, 6.0);
72 let dot_product = v17.dot(&v18);
73 println!("13. Dot product of v17 and v18: {}", dot_product);
74
75 // Magnitude of a Vector3
76 let v19 = Vector3::new(3.0, 4.0, 0.0);
77 let magnitude = v19.magnitude();
78 println!("14. Magnitude/Length of v19: {}", magnitude);
79
80 // Normalize a Vector3
81 let mut v20 = Vector3::new(3.0, 4.0, 0.0);
82 v20.normalize();
83 println!("15. Normalized v20: ({}, {}, {})", v20.x, v20.y, v20.z);
84
85 // Cross product of two vectors
86 let v21 = Vector3::new(1.0, 0.0, 0.0);
87 let v22 = Vector3::new(0.0, 1.0, 0.0);
88 let v23 = v21.cross(&v22);
89 println!("16. Cross product of v21 and v22: ({}, {}, {})", v23.x, v23.y, v23.z);
90
91 // Distance between two vectors
92 let v24 = Vector3::new(1.0, 2.0, 3.0);
93 let v25 = Vector3::new(4.0, 5.0, 6.0);
94 let distance = v24.distance(&v25);
95 println!("17. Distance between v24 and v25: {}", distance);
96
97 // Apply a transformation matrix with translation at 2 in x axis, to a vector
98 let mut v26 = Vector3::new(1.0, 2.0, 3.0);
99 let matrix = openmaths::Matrix4::set(
100 1.0, 0.0, 0.0, 2.0,
101 0.0, 1.0, 0.0, 5.0,
102 0.0, 0.0, 1.0, 0.0,
103 0.0, 0.0, 0.0, 1.0
104 );
105 v26.apply_matrix4(matrix);
106 println!("18. v26 after applying transformation matrix: ({}, {}, {})", v26.x, v26.y, v26.z);
107}Sourcepub fn clone(&self) -> Matrix4
pub fn clone(&self) -> Matrix4
- Clone the Matrix4 instance and return a new one.
Examples found in repository?
examples/matrix-example.rs (line 62)
3fn main() {
4 // Create a new Matrix4 instance
5 let mut m1 = Matrix4::new();
6 println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8 // Set m1 to identity matrix
9 m1.identity();
10 println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12 // Create another Matrix4 instance with specific elements
13 let m2 = Matrix4::set(
14 1.0, 2.0, 3.0, 4.0,
15 5.0, 6.0, 7.0, 8.0,
16 9.0, 10.0, 11.0, 12.0,
17 13.0, 14.0, 15.0, 16.0,
18 );
19
20 println!("3. Matrix4 m2: {:?}", m2.elements());
21
22 // // Multiply two matrices
23 // let m3 = m1.clone().multiply(&m2);
24 // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26 // // Add two matrices
27 // let m4 = m1.clone().add(&m2);
28 // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30 // // Subtract two matrices
31 // let m5 = m2.clone().subtract(&m1);
32 // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34 // Determinant of a matrix m6
35 let m6 = Matrix4::set(
36 1.0, 2.0, 3.0, 4.0,
37 5.0, 6.0, 7.0, 8.0,
38 9.0, 10.0, 11.0, 12.0,
39 13.0, 14.0, 15.0, 16.0,
40 );
41 let det = m6.determinant();
42 println!("7. Determinant of m6: {}", det);
43
44 // // Adjugate of a matrix
45 // let adj = m6.adjucate();
46 // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48 // // Inverse of a matrix
49 // let m7 = m6.clone().inverse();
50 // println!("9. Inverse of m6: {:?}", m7.elements);
51
52 // // Check if the inverse is correct by multiplying m6 with its inverse
53 // let m6_cloned = m6.clone();
54 // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55 // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56
57 // // Check if the inverse multiplication gives identity matrix
58 // let identity_check = m6_inverse_multiplied.is_identity();
59 // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61 // Transpose of a matrix
62 let m8 = m2.clone().transpose();
63 println!("12. Transpose of m2: {:?}", m8.elements());
64}Sourcepub fn identity(&mut self)
pub fn identity(&mut self)
- Sets the matrix element to create an identity matrix.
Examples found in repository?
examples/matrix-example.rs (line 9)
3fn main() {
4 // Create a new Matrix4 instance
5 let mut m1 = Matrix4::new();
6 println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8 // Set m1 to identity matrix
9 m1.identity();
10 println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12 // Create another Matrix4 instance with specific elements
13 let m2 = Matrix4::set(
14 1.0, 2.0, 3.0, 4.0,
15 5.0, 6.0, 7.0, 8.0,
16 9.0, 10.0, 11.0, 12.0,
17 13.0, 14.0, 15.0, 16.0,
18 );
19
20 println!("3. Matrix4 m2: {:?}", m2.elements());
21
22 // // Multiply two matrices
23 // let m3 = m1.clone().multiply(&m2);
24 // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26 // // Add two matrices
27 // let m4 = m1.clone().add(&m2);
28 // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30 // // Subtract two matrices
31 // let m5 = m2.clone().subtract(&m1);
32 // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34 // Determinant of a matrix m6
35 let m6 = Matrix4::set(
36 1.0, 2.0, 3.0, 4.0,
37 5.0, 6.0, 7.0, 8.0,
38 9.0, 10.0, 11.0, 12.0,
39 13.0, 14.0, 15.0, 16.0,
40 );
41 let det = m6.determinant();
42 println!("7. Determinant of m6: {}", det);
43
44 // // Adjugate of a matrix
45 // let adj = m6.adjucate();
46 // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48 // // Inverse of a matrix
49 // let m7 = m6.clone().inverse();
50 // println!("9. Inverse of m6: {:?}", m7.elements);
51
52 // // Check if the inverse is correct by multiplying m6 with its inverse
53 // let m6_cloned = m6.clone();
54 // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55 // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56
57 // // Check if the inverse multiplication gives identity matrix
58 // let identity_check = m6_inverse_multiplied.is_identity();
59 // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61 // Transpose of a matrix
62 let m8 = m2.clone().transpose();
63 println!("12. Transpose of m2: {:?}", m8.elements());
64}Sourcepub fn determinant(&self) -> f64
pub fn determinant(&self) -> f64
- Determinant for a 4x4 matrix.
- https://en.wikipedia.org/wiki/Determinant
Examples found in repository?
examples/matrix-example.rs (line 41)
3fn main() {
4 // Create a new Matrix4 instance
5 let mut m1 = Matrix4::new();
6 println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8 // Set m1 to identity matrix
9 m1.identity();
10 println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12 // Create another Matrix4 instance with specific elements
13 let m2 = Matrix4::set(
14 1.0, 2.0, 3.0, 4.0,
15 5.0, 6.0, 7.0, 8.0,
16 9.0, 10.0, 11.0, 12.0,
17 13.0, 14.0, 15.0, 16.0,
18 );
19
20 println!("3. Matrix4 m2: {:?}", m2.elements());
21
22 // // Multiply two matrices
23 // let m3 = m1.clone().multiply(&m2);
24 // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26 // // Add two matrices
27 // let m4 = m1.clone().add(&m2);
28 // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30 // // Subtract two matrices
31 // let m5 = m2.clone().subtract(&m1);
32 // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34 // Determinant of a matrix m6
35 let m6 = Matrix4::set(
36 1.0, 2.0, 3.0, 4.0,
37 5.0, 6.0, 7.0, 8.0,
38 9.0, 10.0, 11.0, 12.0,
39 13.0, 14.0, 15.0, 16.0,
40 );
41 let det = m6.determinant();
42 println!("7. Determinant of m6: {}", det);
43
44 // // Adjugate of a matrix
45 // let adj = m6.adjucate();
46 // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48 // // Inverse of a matrix
49 // let m7 = m6.clone().inverse();
50 // println!("9. Inverse of m6: {:?}", m7.elements);
51
52 // // Check if the inverse is correct by multiplying m6 with its inverse
53 // let m6_cloned = m6.clone();
54 // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55 // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56
57 // // Check if the inverse multiplication gives identity matrix
58 // let identity_check = m6_inverse_multiplied.is_identity();
59 // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61 // Transpose of a matrix
62 let m8 = m2.clone().transpose();
63 println!("12. Transpose of m2: {:?}", m8.elements());
64}pub fn adjucate(&self) -> Matrix4
Sourcepub fn inverse(&self) -> Matrix4
pub fn inverse(&self) -> Matrix4
- Inverse of a matrix
- Returns a new Matrix4 instance.
- If the determinant is zero, it returns a zero matrix.
- It can be checked with is_zero() method.
Sourcepub fn multiply(&self, other: &Matrix4) -> Matrix4
pub fn multiply(&self, other: &Matrix4) -> Matrix4
- Multiply this matrix with another Matrix4
- Returns a new Matrix4 instance
Sourcepub fn add(&self, incoming: &Matrix4) -> Matrix4
pub fn add(&self, incoming: &Matrix4) -> Matrix4
- Add another Matrix4 to this one.
- Returns a new Matrix4 instance with the result.
Sourcepub fn subtract(&self, incoming: &Matrix4) -> Matrix4
pub fn subtract(&self, incoming: &Matrix4) -> Matrix4
- Subtract another Matrix4 from this one.
- Returns a new Matrix4 instance with the result.
Sourcepub fn get_element_at(&self, index: usize) -> Option<f64>
pub fn get_element_at(&self, index: usize) -> Option<f64>
- Get the element at a specific index in the flattened matrix.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
- Check if the matrix is an identity matrix.
Sourcepub fn transpose(&self) -> Matrix4
pub fn transpose(&self) -> Matrix4
- Create a Transpose of the matrix.
- Returns a new Matrix4 instance.
Examples found in repository?
examples/matrix-example.rs (line 62)
3fn main() {
4 // Create a new Matrix4 instance
5 let mut m1 = Matrix4::new();
6 println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8 // Set m1 to identity matrix
9 m1.identity();
10 println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12 // Create another Matrix4 instance with specific elements
13 let m2 = Matrix4::set(
14 1.0, 2.0, 3.0, 4.0,
15 5.0, 6.0, 7.0, 8.0,
16 9.0, 10.0, 11.0, 12.0,
17 13.0, 14.0, 15.0, 16.0,
18 );
19
20 println!("3. Matrix4 m2: {:?}", m2.elements());
21
22 // // Multiply two matrices
23 // let m3 = m1.clone().multiply(&m2);
24 // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26 // // Add two matrices
27 // let m4 = m1.clone().add(&m2);
28 // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30 // // Subtract two matrices
31 // let m5 = m2.clone().subtract(&m1);
32 // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34 // Determinant of a matrix m6
35 let m6 = Matrix4::set(
36 1.0, 2.0, 3.0, 4.0,
37 5.0, 6.0, 7.0, 8.0,
38 9.0, 10.0, 11.0, 12.0,
39 13.0, 14.0, 15.0, 16.0,
40 );
41 let det = m6.determinant();
42 println!("7. Determinant of m6: {}", det);
43
44 // // Adjugate of a matrix
45 // let adj = m6.adjucate();
46 // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48 // // Inverse of a matrix
49 // let m7 = m6.clone().inverse();
50 // println!("9. Inverse of m6: {:?}", m7.elements);
51
52 // // Check if the inverse is correct by multiplying m6 with its inverse
53 // let m6_cloned = m6.clone();
54 // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55 // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56
57 // // Check if the inverse multiplication gives identity matrix
58 // let identity_check = m6_inverse_multiplied.is_identity();
59 // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61 // Transpose of a matrix
62 let m8 = m2.clone().transpose();
63 println!("12. Transpose of m2: {:?}", m8.elements());
64}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Matrix4
impl<'de> Deserialize<'de> for Matrix4
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl FromWasmAbi for Matrix4
impl FromWasmAbi for Matrix4
Source§impl IntoWasmAbi for Matrix4
impl IntoWasmAbi for Matrix4
Source§impl LongRefFromWasmAbi for Matrix4
impl LongRefFromWasmAbi for Matrix4
Source§impl OptionFromWasmAbi for Matrix4
impl OptionFromWasmAbi for Matrix4
Source§impl OptionIntoWasmAbi for Matrix4
impl OptionIntoWasmAbi for Matrix4
Source§impl RefFromWasmAbi for Matrix4
impl RefFromWasmAbi for Matrix4
Source§impl RefMutFromWasmAbi for Matrix4
impl RefMutFromWasmAbi for Matrix4
Source§impl TryFromJsValue for Matrix4
impl TryFromJsValue for Matrix4
Source§impl VectorFromWasmAbi for Matrix4
impl VectorFromWasmAbi for Matrix4
Source§impl VectorIntoWasmAbi for Matrix4
impl VectorIntoWasmAbi for Matrix4
impl SupportsConstructor for Matrix4
impl SupportsInstanceProperty for Matrix4
impl SupportsStaticProperty for Matrix4
Auto Trait Implementations§
impl Freeze for Matrix4
impl RefUnwindSafe for Matrix4
impl Send for Matrix4
impl Sync for Matrix4
impl Unpin for Matrix4
impl UnwindSafe for Matrix4
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.