Debian Codegraph @

src/Base/CoordinateSystem.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2014 Werner Mayer <wmayer[at]users.sourceforge.net> *
5 * *
6 * This file is part of the FreeCAD CAx development system. *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Library General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2 of the License, or (at your option) any later version. *
12 * *
13 * This library 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 Library General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Library General Public *
19 * License along with this library; see the file COPYING.LIB. If not, *
20 * write to the Free Software Foundation, Inc., 51 Franklin Street, *
21 * Fifth Floor, Boston, MA 02110-1301, USA *
22 * *
23 ***************************************************************************/
24
25
26 #ifndef BASE_COORDINATESYSTEM_H
27 #define BASE_COORDINATESYSTEM_H
28
29 #include "Axis.h"
30
31 namespace Base
32 {
33 class Rotation;
34
35 /**
36 * Describes a right-handed coordinate system in 3D space.
37 \author Werner Mayer
38 */
39 class BaseExport CoordinateSystem
40 {
41 public:
42 /** Construct a default coordinate system with position in (0,0,0),
43 * with X axis (1,0,0), with Y axis (0,1,0) and Z axis (0,0,1)
44 */
45 CoordinateSystem();
46 CoordinateSystem(const CoordinateSystem&) = default;
47 CoordinateSystem(CoordinateSystem&&) = default;
48 ~CoordinateSystem() = default;
49
50 CoordinateSystem& operator=(const CoordinateSystem&) = default;
51 CoordinateSystem& operator=(CoordinateSystem&&) = default;
52
53 /** Sets the main axis. X and Y dir are adjusted accordingly.
54 * The main axis \a v must not be parallel to the X axis
55 */
56 void setAxis(const Axis& axis);
57 /** Sets the main axis. X and Y dir are adjusted accordingly.
58 * The main axis must not be parallel to \a xd
59 */
60 void setAxes(const Axis&, const Vector3d& xd);
61 /** Sets the main axis. X and Y dir are adjusted accordingly.
62 * The main axis \a n must not be parallel to \a xd
63 */
64 void setAxes(const Vector3d& n, const Vector3d& xd);
65 inline const Axis& getAxis() const
66 {
67 return axis;
68 }
69
70 /** The passed vector must not be parallel to the main axis */
71 void setXDirection(const Vector3d&);
72 inline const Vector3d& getXDirection() const
73 {
74 return xdir;
75 }
76
77 /** The passed vector must not be parallel to the main axis */
78 void setYDirection(const Vector3d&);
79 inline const Vector3d& getYDirection() const
80 {
81 return ydir;
82 }
83
84 /** Sets the main axis. X and Y dir are adjusted accordingly.
85 * The main axis must not be parallel to the X axis
86 */
87 void setZDirection(const Vector3d&);
88 inline const Vector3d& getZDirection() const
89 {
90 return axis.getDirection();
91 }
92 inline void setPosition(const Vector3d& pos)
93 {
94 axis.setBase(pos);
95 }
96 inline const Vector3d& getPosition() const
97 {
98 return axis.getBase();
99 }
100
101 /** This computes the displacement from this coordinate system to the
102 * given coordinate system \a cs
103 */
104 Placement displacement(const CoordinateSystem& cs) const;
105
106 /** Transform the point \a pnt to be in this coordinate system */
107 void transformTo(Vector3d& pnt);
108
109 /** Apply the placement \a plm to the coordinate system. */
110 void transform(const Placement& plm);
111
112 /** Apply the rotation \a rot to the coordinate system. */
113 void transform(const Rotation& rot);
114
115 /** Set the placement \a plm to the coordinate system. */
116 void setPlacement(const Placement& plm);
117
118 private:
119 Axis axis;
120 Vector3d xdir;
121 Vector3d ydir;
122 };
123
124 } // namespace Base
125
126 #endif // BASE_COORDINATESYSTEM_H