My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vector_3.h 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * vector_3.cpp - Vector library for bed leveling
  25. * Copyright (c) 2012 Lars Brubaker. All right reserved.
  26. *
  27. * This library is free software; you can redistribute it and/or
  28. * modify it under the terms of the GNU Lesser General Public
  29. * License as published by the Free Software Foundation; either
  30. * version 2.1 of the License, or (at your option) any later version.
  31. *
  32. * This library is distributed in the hope that it will be useful,
  33. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  35. * Lesser General Public License for more details.
  36. *
  37. * You should have received a copy of the GNU Lesser General Public
  38. * License along with this library; if not, write to the Free Software
  39. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  40. */
  41. #include "../core/types.h"
  42. class matrix_3x3;
  43. struct vector_3 {
  44. union {
  45. struct { float x, y, z; };
  46. float pos[3];
  47. };
  48. vector_3(const_float_t _x, const_float_t _y, const_float_t _z) : x(_x), y(_y), z(_z) {}
  49. vector_3(const xy_float_t &in) { x = in.x; TERN_(HAS_Y_AXIS, y = in.y); }
  50. vector_3(const xyz_float_t &in) { x = in.x; TERN_(HAS_Y_AXIS, y = in.y); TERN_(HAS_Z_AXIS, z = in.z); }
  51. vector_3(const xyze_float_t &in) { x = in.x; TERN_(HAS_Y_AXIS, y = in.y); TERN_(HAS_Z_AXIS, z = in.z); }
  52. vector_3() { x = y = z = 0; }
  53. // Factory method
  54. static vector_3 cross(const vector_3 &a, const vector_3 &b);
  55. // Modifiers
  56. void normalize();
  57. void apply_rotation(const matrix_3x3 &matrix);
  58. // Accessors
  59. float magnitude() const;
  60. vector_3 get_normal() const;
  61. // Operators
  62. float& operator[](const int n) { return pos[n]; }
  63. const float& operator[](const int n) const { return pos[n]; }
  64. vector_3& operator*=(const float &v) { x *= v; y *= v; z *= v; return *this; }
  65. vector_3 operator+(const vector_3 &v) { return vector_3(x + v.x, y + v.y, z + v.z); }
  66. vector_3 operator-(const vector_3 &v) { return vector_3(x - v.x, y - v.y, z - v.z); }
  67. vector_3 operator*(const float &v) { return vector_3(x * v, y * v, z * v); }
  68. operator xy_float_t() { return xy_float_t({ x OPTARG(HAS_Y_AXIS, y) }); }
  69. operator xyz_float_t() { return xyz_float_t({ x OPTARG(HAS_Y_AXIS, y) OPTARG(HAS_Z_AXIS, z) }); }
  70. void debug(FSTR_P const title);
  71. };
  72. struct matrix_3x3 {
  73. vector_3 vectors[3];
  74. // Factory methods
  75. static matrix_3x3 create_from_rows(const vector_3 &row_0, const vector_3 &row_1, const vector_3 &row_2);
  76. static matrix_3x3 create_look_at(const vector_3 &target);
  77. static matrix_3x3 transpose(const matrix_3x3 &original);
  78. void set_to_identity();
  79. void debug(FSTR_P const title);
  80. void apply_rotation_xyz(float &x, float &y, float &z);
  81. };