Vector3

Struct Vector3 

Source
pub struct Vector3 {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

Fields§

§x: f64§y: f64§z: f64

Implementations§

Source§

impl Vector3

Source

pub fn new(x: f64, y: f64, z: f64) -> Vector3

Examples found in repository?
examples/vector-example.rs (line 5)
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}
Source

pub fn add(&mut self, other: &Vector3) -> Vector3

  • Add the elements of another vector to this one.
Examples found in repository?
examples/vector-example.rs (line 9)
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}
Source

pub fn add_scalar(&mut self, scalar: f64) -> Vector3

  • Add a scalar value to each element of the vector.
Examples found in repository?
examples/vector-example.rs (line 14)
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}
Source

pub fn subtract(&mut self, other: &Vector3) -> Vector3

  • Subtract the elements of another vector from this one.
Examples found in repository?
examples/vector-example.rs (line 19)
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}
Source

pub fn subtract_scalar(&mut self, scalar: f64) -> Vector3

  • Subtract a scalar value from each element of the vector.
Examples found in repository?
examples/vector-example.rs (line 24)
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}
Source

pub fn clone(&self) -> Vector3

  • Clone the Vector3 instance and return a new one.
Examples found in repository?
examples/vector-example.rs (line 28)
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}
Source

pub fn zero(&mut self)

  • Set the current vector elements to zero.
Examples found in repository?
examples/vector-example.rs (line 33)
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}
Source

pub fn copy(&mut self, other: &Vector3)

  • Copy the elements from another Vector3 instance.
Examples found in repository?
examples/vector-example.rs (line 38)
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}
Source

pub fn multiply_scalar(&mut self, scalar: f64) -> Vector3

  • Multiply the vector by a scalar value.
Examples found in repository?
examples/vector-example.rs (line 43)
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}
Source

pub fn multiply(&mut self, other: &Vector3) -> Vector3

  • Multiply the vector by another Vector3 instance element-wise.
Examples found in repository?
examples/vector-example.rs (line 50)
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}
Source

pub fn divide(&mut self, other: &Vector3) -> Vector3

  • Divide the vector by another Vector3 instance element-wise.
Examples found in repository?
examples/vector-example.rs (line 61)
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}
Source

pub fn divide_scalar(&mut self, scalar: f64) -> Vector3

  • Divide the vector by a scalar value.
Examples found in repository?
examples/vector-example.rs (line 55)
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}
Source

pub fn negate(&mut self) -> Vector3

  • Invert the vector by negating the vector elements.
Examples found in repository?
examples/vector-example.rs (line 66)
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}
Source

pub fn dot(&self, other: &Vector3) -> f64

  • Calculate the dot product of this vector with another Vector3 instance.
Examples found in repository?
examples/vector-example.rs (line 72)
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}
Source

pub fn magnitude(&self) -> f64

  • Calculate the magnitude (length) of the vector.
Examples found in repository?
examples/vector-example.rs (line 77)
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}
Source

pub fn length(&self) -> f64

  • Calculate the length of the vector.
  • Since length is equivalent to magnitude, this method is an alias.
Source

pub fn normalize(&mut self) -> Vector3

  • Normalize the vector
Examples found in repository?
examples/vector-example.rs (line 82)
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}
Source

pub fn cross(&self, other: &Vector3) -> Vector3

  • Calculate the cross product and return the result as a new Vector3
Examples found in repository?
examples/vector-example.rs (line 88)
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}
Source

pub fn distance(&self, other: &Vector3) -> f64

  • Calculate the distance between this vector and another Vector3 instance.
  • Return the distance as a f64 value in Euclidean space.
Examples found in repository?
examples/vector-example.rs (line 94)
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}
Source

pub fn apply_matrix4(&mut self, matrix: Matrix4)

  • Apply a transformation matrix to the vector.
  • This method assumes the transformation matrix is a 4x4 matrix.
Examples found in repository?
examples/vector-example.rs (line 105)
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}

Trait Implementations§

Source§

impl Clone for Vector3

Source§

fn clone(&self) -> Vector3

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'de> Deserialize<'de> for Vector3

Source§

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 From<Vector3> for JsValue

Source§

fn from(value: Vector3) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for Vector3

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for Vector3

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for Vector3

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<Vector3>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for Vector3

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for Vector3

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for Vector3

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<Vector3>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for Vector3

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<Vector3>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl Serialize for Vector3

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFromJsValue for Vector3

Source§

type Error = JsValue

The type returned in the event of a conversion error.
Source§

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl VectorFromWasmAbi for Vector3

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Vector3]>

Source§

impl VectorIntoJsValue for Vector3

Source§

impl VectorIntoWasmAbi for Vector3

Source§

impl WasmDescribe for Vector3

Source§

impl WasmDescribeVector for Vector3

Source§

impl Copy for Vector3

Source§

impl SupportsConstructor for Vector3

Source§

impl SupportsInstanceProperty for Vector3

Source§

impl SupportsStaticProperty for Vector3

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

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.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,