Browse Source

Prettify Bed Level Correction Matrix

- Put + in front of positive values in the output
Scott Lahteine 10 years ago
parent
commit
32331faee4
1 changed files with 30 additions and 54 deletions
  1. 30
    54
      Marlin/vector_3.cpp

+ 30
- 54
Marlin/vector_3.cpp View File

@@ -26,57 +26,40 @@ vector_3::vector_3() : x(0), y(0), z(0) { }
26 26
 
27 27
 vector_3::vector_3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) { }
28 28
 
29
-vector_3 vector_3::cross(vector_3 left, vector_3 right)
30
-{
29
+vector_3 vector_3::cross(vector_3 left, vector_3 right) {
31 30
 	return vector_3(left.y * right.z - left.z * right.y,
32 31
 		left.z * right.x - left.x * right.z,
33 32
 		left.x * right.y - left.y * right.x);
34 33
 }
35 34
 
36
-vector_3 vector_3::operator+(vector_3 v) 
37
-{
38
-	return vector_3((x + v.x), (y + v.y), (z + v.z));
39
-}
40
-
41
-vector_3 vector_3::operator-(vector_3 v) 
42
-{
43
-	return vector_3((x - v.x), (y - v.y), (z - v.z));
44
-}
35
+vector_3 vector_3::operator+(vector_3 v) { return vector_3((x + v.x), (y + v.y), (z + v.z)); }
36
+vector_3 vector_3::operator-(vector_3 v) { return vector_3((x - v.x), (y - v.y), (z - v.z)); }
45 37
 
46
-vector_3 vector_3::get_normal() 
47
-{
38
+vector_3 vector_3::get_normal() {
48 39
 	vector_3 normalized = vector_3(x, y, z);
49 40
 	normalized.normalize();
50 41
 	return normalized;
51 42
 }
52 43
 
53
-float vector_3::get_length() 
54
-{
55
-	float length = sqrt((x * x) + (y * y) + (z * z));
56
-	return length;
57
-}
58
- 
59
-void vector_3::normalize()
60
-{
44
+float vector_3::get_length() { return sqrt((x * x) + (y * y) + (z * z)); }
45
+
46
+void vector_3::normalize() {
61 47
 	float length = get_length();
62 48
 	x /= length;
63 49
 	y /= length;
64 50
 	z /= length;
65 51
 }
66 52
 
67
-void vector_3::apply_rotation(matrix_3x3 matrix)
68
-{
53
+void vector_3::apply_rotation(matrix_3x3 matrix) {
69 54
 	float resultX = x * matrix.matrix[3*0+0] + y * matrix.matrix[3*1+0] + z * matrix.matrix[3*2+0];
70 55
 	float resultY = x * matrix.matrix[3*0+1] + y * matrix.matrix[3*1+1] + z * matrix.matrix[3*2+1];
71 56
 	float resultZ = x * matrix.matrix[3*0+2] + y * matrix.matrix[3*1+2] + z * matrix.matrix[3*2+2];
72
-
73 57
 	x = resultX;
74 58
 	y = resultY;
75 59
 	z = resultZ;
76 60
 }
77 61
 
78
-void vector_3::debug(char* title)
79
-{
62
+void vector_3::debug(char* title) {
80 63
 	SERIAL_PROTOCOL(title);
81 64
 	SERIAL_PROTOCOLPGM(" x: ");
82 65
 	SERIAL_PROTOCOL_F(x, 6);
@@ -87,8 +70,7 @@ void vector_3::debug(char* title)
87 70
 	SERIAL_EOL;
88 71
 }
89 72
 
90
-void apply_rotation_xyz(matrix_3x3 matrix, float &x, float& y, float& z)
91
-{
73
+void apply_rotation_xyz(matrix_3x3 matrix, float &x, float& y, float& z) {
92 74
 	vector_3 vector = vector_3(x, y, z);
93 75
 	vector.apply_rotation(matrix);
94 76
 	x = vector.x;
@@ -96,48 +78,41 @@ void apply_rotation_xyz(matrix_3x3 matrix, float &x, float& y, float& z)
96 78
 	z = vector.z;
97 79
 }
98 80
 
99
-matrix_3x3 matrix_3x3::create_from_rows(vector_3 row_0, vector_3 row_1, vector_3 row_2)
100
-{
101
-        //row_0.debug("row_0");
102
-        //row_1.debug("row_1");
103
-        //row_2.debug("row_2");
81
+matrix_3x3 matrix_3x3::create_from_rows(vector_3 row_0, vector_3 row_1, vector_3 row_2) {
82
+  //row_0.debug("row_0");
83
+  //row_1.debug("row_1");
84
+  //row_2.debug("row_2");
104 85
 	matrix_3x3 new_matrix;
105 86
 	new_matrix.matrix[0] = row_0.x; new_matrix.matrix[1] = row_0.y; new_matrix.matrix[2] = row_0.z; 
106 87
 	new_matrix.matrix[3] = row_1.x; new_matrix.matrix[4] = row_1.y; new_matrix.matrix[5] = row_1.z; 
107 88
 	new_matrix.matrix[6] = row_2.x; new_matrix.matrix[7] = row_2.y; new_matrix.matrix[8] = row_2.z; 
108
-        //new_matrix.debug("new_matrix");
109
-        
89
+  //new_matrix.debug("new_matrix");
110 90
 	return new_matrix;
111 91
 }
112 92
 
113
-void matrix_3x3::set_to_identity()
114
-{
93
+void matrix_3x3::set_to_identity() {
115 94
 	matrix[0] = 1; matrix[1] = 0; matrix[2] = 0;
116 95
 	matrix[3] = 0; matrix[4] = 1; matrix[5] = 0;
117 96
 	matrix[6] = 0; matrix[7] = 0; matrix[8] = 1;
118 97
 }
119 98
 
120
-matrix_3x3 matrix_3x3::create_look_at(vector_3 target)
121
-{
122
-    vector_3 z_row = target.get_normal();
123
-    vector_3 x_row = vector_3(1, 0, -target.x/target.z).get_normal();
124
-    vector_3 y_row = vector_3::cross(z_row, x_row).get_normal();
99
+matrix_3x3 matrix_3x3::create_look_at(vector_3 target) {
100
+  vector_3 z_row = target.get_normal();
101
+  vector_3 x_row = vector_3(1, 0, -target.x/target.z).get_normal();
102
+  vector_3 y_row = vector_3::cross(z_row, x_row).get_normal();
125 103
 
126
-   // x_row.debug("x_row");
127
-   // y_row.debug("y_row");
128
-   // z_row.debug("z_row");
104
+  // x_row.debug("x_row");
105
+  // y_row.debug("y_row");
106
+  // z_row.debug("z_row");
129 107
 
130
- 
131
-     // create the matrix already correctly transposed
132
-    matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row);
108
+  // create the matrix already correctly transposed
109
+  matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row);
133 110
 
134
- //   rot.debug("rot");
135
-    return rot;
111
+  // rot.debug("rot");
112
+  return rot;
136 113
 }
137 114
 
138
-
139
-matrix_3x3 matrix_3x3::transpose(matrix_3x3 original)
140
-{
115
+matrix_3x3 matrix_3x3::transpose(matrix_3x3 original) {
141 116
   matrix_3x3 new_matrix;
142 117
   new_matrix.matrix[0] = original.matrix[0]; new_matrix.matrix[1] = original.matrix[3]; new_matrix.matrix[2] = original.matrix[6]; 
143 118
   new_matrix.matrix[3] = original.matrix[1]; new_matrix.matrix[4] = original.matrix[4]; new_matrix.matrix[5] = original.matrix[7]; 
@@ -150,6 +125,7 @@ void matrix_3x3::debug(char* title) {
150 125
   int count = 0;
151 126
   for(int i=0; i<3; i++) {
152 127
     for(int j=0; j<3; j++) {
128
+      if (matrix[count] >= 0.0) SERIAL_PROTOCOLPGM("+");
153 129
       SERIAL_PROTOCOL_F(matrix[count], 6);
154 130
       SERIAL_PROTOCOLPGM(" ");
155 131
       count++;
@@ -158,5 +134,5 @@ void matrix_3x3::debug(char* title) {
158 134
   }
159 135
 }
160 136
 
161
-#endif // #ifdef ENABLE_AUTO_BED_LEVELING
137
+#endif // ENABLE_AUTO_BED_LEVELING
162 138
 

Loading…
Cancel
Save