Prusa MINI Firmware overview
vector_3.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4  *
5  * Based on Sprinter and grbl.
6  * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 #pragma once
23 
24 /**
25  * vector_3.cpp - Vector library for bed leveling
26  * Copyright (c) 2012 Lars Brubaker. All right reserved.
27  *
28  * This library is free software; you can redistribute it and/or
29  * modify it under the terms of the GNU Lesser General Public
30  * License as published by the Free Software Foundation; either
31  * version 2.1 of the License, or (at your option) any later version.
32  *
33  * This library is distributed in the hope that it will be useful,
34  * but WITHOUT ANY WARRANTY; without even the implied warranty of
35  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36  * Lesser General Public License for more details.
37  *
38  * You should have received a copy of the GNU Lesser General Public
39  * License along with this library; if not, write to the Free Software
40  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
41  */
42 
43 #include "../core/types.h"
44 
45 class matrix_3x3;
46 
48 
49  vector_3(const float &_x, const float &_y, const float &_z) { set(_x, _y, _z); }
50  vector_3(const xy_float_t &in) { set(in.x, in.y); }
51  vector_3(const xyz_float_t &in) { set(in.x, in.y, in.z); }
52  vector_3(const xyze_float_t &in) { set(in.x, in.y, in.z); }
53 
54  // Factory method
55  static vector_3 cross(const vector_3 &a, const vector_3 &b);
56 
57  // Modifiers
58  void normalize();
59  void apply_rotation(const matrix_3x3 &matrix);
60 
61  // Accessors
62  float get_length() const;
63  vector_3 get_normal() const;
64 
65  // Operators
66  FORCE_INLINE vector_3 operator+(const vector_3 &v) const { vector_3 o = *this; o += v; return o; }
67  FORCE_INLINE vector_3 operator-(const vector_3 &v) const { vector_3 o = *this; o -= v; return o; }
68  FORCE_INLINE vector_3 operator*(const float &v) const { vector_3 o = *this; o *= v; return o; }
69 
70  void debug(PGM_P const title);
71 };
72 
73 struct matrix_3x3 {
75 
76  // Factory methods
77  static matrix_3x3 create_from_rows(const vector_3 &row_0, const vector_3 &row_1, const vector_3 &row_2);
78  static matrix_3x3 create_look_at(const vector_3 &target);
79  static matrix_3x3 transpose(const matrix_3x3 &original);
80 
81  void set_to_identity();
82 
83  void debug(PGM_P const title);
84 };
85 
86 void apply_rotation_xyz(const matrix_3x3 &rotationMatrix, float &x, float &y, float &z);
87 FORCE_INLINE void apply_rotation_xyz(const matrix_3x3 &rotationMatrix, xyz_pos_t &pos) {
88  apply_rotation_xyz(rotationMatrix, pos.x, pos.y, pos.z);
89 }
vector_3::vector_3
vector_3(const xyze_float_t &in)
Definition: vector_3.h:52
XYZval::z
T z
Definition: types.h:286
SERIAL_CHAR
#define SERIAL_CHAR(x)
Definition: serial.h:69
vector_3::normalize
void normalize()
Definition: vector_3.cpp:67
XYZval< float >::a
float a
Definition: types.h:287
RSQRT
#define RSQRT(x)
Definition: macros.h:282
XYZEval< float >
sq
#define sq(x)
Definition: wiring_constants.h:83
XYZEval::z
T z
Definition: types.h:383
XYZval::x
T x
Definition: types.h:286
matrix_3x3::create_look_at
static matrix_3x3 create_look_at(const vector_3 &target)
Definition: vector_3.cpp:114
vector_3::operator*
FORCE_INLINE vector_3 operator*(const float &v) const
Definition: vector_3.h:68
vector_3::operator-
FORCE_INLINE vector_3 operator-(const vector_3 &v) const
Definition: vector_3.h:67
vector_3::get_normal
vector_3 get_normal() const
Definition: vector_3.cpp:61
PGM_P
#define PGM_P
Definition: pgmspace.h:30
i
uint8_t i
Definition: screen_test_graph.c:72
SERIAL_ECHOLNPAIR_F
#define SERIAL_ECHOLNPAIR_F(V...)
Definition: serial.h:177
matrix_3x3::transpose
static matrix_3x3 transpose(const matrix_3x3 &original)
Definition: vector_3.cpp:131
XYZval< float >::set
FI void set(const float px)
Definition: types.h:290
vector_3::apply_rotation
void apply_rotation(const matrix_3x3 &matrix)
Definition: vector_3.cpp:72
matrix_3x3::set_to_identity
void set_to_identity()
Definition: vector_3.cpp:94
matrix_3x3
Definition: vector_3.h:73
math.h
FORCE_INLINE
#define FORCE_INLINE
Definition: macros.h:40
XYZval< float >::b
float b
Definition: types.h:287
apply_rotation_xyz
void apply_rotation_xyz(const matrix_3x3 &matrix, float &_x, float &_y, float &_z)
Definition: vector_3.cpp:88
vector_3::get_length
float get_length() const
vector_3::vector_3
vector_3(const float &_x, const float &_y, const float &_z)
Definition: vector_3.h:49
vector_3.h
vector_3::cross
static vector_3 cross(const vector_3 &a, const vector_3 &b)
Definition: vector_3.cpp:54
XYZEval::x
T x
Definition: types.h:383
SERIAL_ECHO_F
#define SERIAL_ECHO_F(V...)
Definition: serial.h:71
XYval
Definition: types.h:99
matrix_3x3::debug
void debug(PGM_P const title)
Definition: vector_3.cpp:139
vector_3::vector_3
vector_3(const xy_float_t &in)
Definition: vector_3.h:50
matrix_3x3::vectors
abc_float_t vectors[3]
Definition: vector_3.h:74
XYval::x
T x
Definition: types.h:185
uint8_t
const uint8_t[]
Definition: 404_html.c:3
vector_3::vector_3
vector_3(const xyz_float_t &in)
Definition: vector_3.h:51
XYZval::y
T y
Definition: types.h:286
apply_rotation_xyz
void apply_rotation_xyz(const matrix_3x3 &rotationMatrix, float &x, float &y, float &z)
Definition: vector_3.cpp:88
SERIAL_ECHOPAIR_F
#define SERIAL_ECHOPAIR_F(S, V...)
Definition: serial.h:176
SERIAL_EOL
#define SERIAL_EOL()
Definition: serial.h:181
vector_3
Definition: vector_3.h:47
XYval::y
T y
Definition: types.h:185
XYZval
Definition: types.h:100
matrix_3x3::create_from_rows
static matrix_3x3 create_from_rows(const vector_3 &row_0, const vector_3 &row_1, const vector_3 &row_2)
Definition: vector_3.cpp:101
vector_3::operator+
FORCE_INLINE vector_3 operator+(const vector_3 &v) const
Definition: vector_3.h:66
serialprintPGM
void serialprintPGM(PGM_P str)
Definition: serial.cpp:35
vector_3::debug
void debug(PGM_P const title)
Definition: vector_3.cpp:77
XYZEval::y
T y
Definition: types.h:383