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
 
26
 
27
 vector_3::vector_3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) { }
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
 	return vector_3(left.y * right.z - left.z * right.y,
30
 	return vector_3(left.y * right.z - left.z * right.y,
32
 		left.z * right.x - left.x * right.z,
31
 		left.z * right.x - left.x * right.z,
33
 		left.x * right.y - left.y * right.x);
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
 	vector_3 normalized = vector_3(x, y, z);
39
 	vector_3 normalized = vector_3(x, y, z);
49
 	normalized.normalize();
40
 	normalized.normalize();
50
 	return normalized;
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
 	float length = get_length();
47
 	float length = get_length();
62
 	x /= length;
48
 	x /= length;
63
 	y /= length;
49
 	y /= length;
64
 	z /= length;
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
 	float resultX = x * matrix.matrix[3*0+0] + y * matrix.matrix[3*1+0] + z * matrix.matrix[3*2+0];
54
 	float resultX = x * matrix.matrix[3*0+0] + y * matrix.matrix[3*1+0] + z * matrix.matrix[3*2+0];
70
 	float resultY = x * matrix.matrix[3*0+1] + y * matrix.matrix[3*1+1] + z * matrix.matrix[3*2+1];
55
 	float resultY = x * matrix.matrix[3*0+1] + y * matrix.matrix[3*1+1] + z * matrix.matrix[3*2+1];
71
 	float resultZ = x * matrix.matrix[3*0+2] + y * matrix.matrix[3*1+2] + z * matrix.matrix[3*2+2];
56
 	float resultZ = x * matrix.matrix[3*0+2] + y * matrix.matrix[3*1+2] + z * matrix.matrix[3*2+2];
72
-
73
 	x = resultX;
57
 	x = resultX;
74
 	y = resultY;
58
 	y = resultY;
75
 	z = resultZ;
59
 	z = resultZ;
76
 }
60
 }
77
 
61
 
78
-void vector_3::debug(char* title)
79
-{
62
+void vector_3::debug(char* title) {
80
 	SERIAL_PROTOCOL(title);
63
 	SERIAL_PROTOCOL(title);
81
 	SERIAL_PROTOCOLPGM(" x: ");
64
 	SERIAL_PROTOCOLPGM(" x: ");
82
 	SERIAL_PROTOCOL_F(x, 6);
65
 	SERIAL_PROTOCOL_F(x, 6);
87
 	SERIAL_EOL;
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
 	vector_3 vector = vector_3(x, y, z);
74
 	vector_3 vector = vector_3(x, y, z);
93
 	vector.apply_rotation(matrix);
75
 	vector.apply_rotation(matrix);
94
 	x = vector.x;
76
 	x = vector.x;
96
 	z = vector.z;
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
 	matrix_3x3 new_matrix;
85
 	matrix_3x3 new_matrix;
105
 	new_matrix.matrix[0] = row_0.x; new_matrix.matrix[1] = row_0.y; new_matrix.matrix[2] = row_0.z; 
86
 	new_matrix.matrix[0] = row_0.x; new_matrix.matrix[1] = row_0.y; new_matrix.matrix[2] = row_0.z; 
106
 	new_matrix.matrix[3] = row_1.x; new_matrix.matrix[4] = row_1.y; new_matrix.matrix[5] = row_1.z; 
87
 	new_matrix.matrix[3] = row_1.x; new_matrix.matrix[4] = row_1.y; new_matrix.matrix[5] = row_1.z; 
107
 	new_matrix.matrix[6] = row_2.x; new_matrix.matrix[7] = row_2.y; new_matrix.matrix[8] = row_2.z; 
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
 	return new_matrix;
90
 	return new_matrix;
111
 }
91
 }
112
 
92
 
113
-void matrix_3x3::set_to_identity()
114
-{
93
+void matrix_3x3::set_to_identity() {
115
 	matrix[0] = 1; matrix[1] = 0; matrix[2] = 0;
94
 	matrix[0] = 1; matrix[1] = 0; matrix[2] = 0;
116
 	matrix[3] = 0; matrix[4] = 1; matrix[5] = 0;
95
 	matrix[3] = 0; matrix[4] = 1; matrix[5] = 0;
117
 	matrix[6] = 0; matrix[7] = 0; matrix[8] = 1;
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
   matrix_3x3 new_matrix;
116
   matrix_3x3 new_matrix;
142
   new_matrix.matrix[0] = original.matrix[0]; new_matrix.matrix[1] = original.matrix[3]; new_matrix.matrix[2] = original.matrix[6]; 
117
   new_matrix.matrix[0] = original.matrix[0]; new_matrix.matrix[1] = original.matrix[3]; new_matrix.matrix[2] = original.matrix[6]; 
143
   new_matrix.matrix[3] = original.matrix[1]; new_matrix.matrix[4] = original.matrix[4]; new_matrix.matrix[5] = original.matrix[7]; 
118
   new_matrix.matrix[3] = original.matrix[1]; new_matrix.matrix[4] = original.matrix[4]; new_matrix.matrix[5] = original.matrix[7]; 
150
   int count = 0;
125
   int count = 0;
151
   for(int i=0; i<3; i++) {
126
   for(int i=0; i<3; i++) {
152
     for(int j=0; j<3; j++) {
127
     for(int j=0; j<3; j++) {
128
+      if (matrix[count] >= 0.0) SERIAL_PROTOCOLPGM("+");
153
       SERIAL_PROTOCOL_F(matrix[count], 6);
129
       SERIAL_PROTOCOL_F(matrix[count], 6);
154
       SERIAL_PROTOCOLPGM(" ");
130
       SERIAL_PROTOCOLPGM(" ");
155
       count++;
131
       count++;
158
   }
134
   }
159
 }
135
 }
160
 
136
 
161
-#endif // #ifdef ENABLE_AUTO_BED_LEVELING
137
+#endif // ENABLE_AUTO_BED_LEVELING
162
 
138
 

Loading…
Cancel
Save