File size: 4,535 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// SPDX-License-Identifier: LGPL-2.1-or-later

/***************************************************************************
 *   Copyright (c) 2014 Werner Mayer <wmayer[at]users.sourceforge.net>     *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 51 Franklin Street,      *
 *   Fifth Floor, Boston, MA  02110-1301, USA                              *
 *                                                                         *
 ***************************************************************************/


#ifndef BASE_COORDINATESYSTEM_H
#define BASE_COORDINATESYSTEM_H

#include "Axis.h"

namespace Base
{
class Rotation;

/**
 * Describes a right-handed coordinate system in 3D space.
 \author Werner Mayer
 */
class BaseExport CoordinateSystem
{
public:
    /** Construct a default coordinate system with position in (0,0,0),
     * with X axis (1,0,0), with Y axis (0,1,0) and Z axis (0,0,1)
     */
    CoordinateSystem();
    CoordinateSystem(const CoordinateSystem&) = default;
    CoordinateSystem(CoordinateSystem&&) = default;
    ~CoordinateSystem() = default;

    CoordinateSystem& operator=(const CoordinateSystem&) = default;
    CoordinateSystem& operator=(CoordinateSystem&&) = default;

    /** Sets the main axis. X and Y dir are adjusted accordingly.
     * The main axis \a v must not be parallel to the X axis
     */
    void setAxis(const Axis& axis);
    /** Sets the main axis. X and Y dir are adjusted accordingly.
     * The main axis must not be parallel to \a xd
     */
    void setAxes(const Axis&, const Vector3d& xd);
    /** Sets the main axis. X and Y dir are adjusted accordingly.
     * The main axis \a n must not be parallel to \a xd
     */
    void setAxes(const Vector3d& n, const Vector3d& xd);
    inline const Axis& getAxis() const
    {
        return axis;
    }

    /** The passed vector must not be parallel to the main axis */
    void setXDirection(const Vector3d&);
    inline const Vector3d& getXDirection() const
    {
        return xdir;
    }

    /** The passed vector must not be parallel to the main axis */
    void setYDirection(const Vector3d&);
    inline const Vector3d& getYDirection() const
    {
        return ydir;
    }

    /** Sets the main axis. X and Y dir are adjusted accordingly.
     * The main axis must not be parallel to the X axis
     */
    void setZDirection(const Vector3d&);
    inline const Vector3d& getZDirection() const
    {
        return axis.getDirection();
    }
    inline void setPosition(const Vector3d& pos)
    {
        axis.setBase(pos);
    }
    inline const Vector3d& getPosition() const
    {
        return axis.getBase();
    }

    /** This computes the displacement from this coordinate system to the
     * given coordinate system \a cs
     */
    Placement displacement(const CoordinateSystem& cs) const;

    /** Transform the point \a pnt to be in this coordinate system */
    void transformTo(Vector3d& pnt);

    /** Apply the placement \a plm to the coordinate system. */
    void transform(const Placement& plm);

    /** Apply the rotation \a rot to the coordinate system. */
    void transform(const Rotation& rot);

    /** Set the placement \a plm to the coordinate system. */
    void setPlacement(const Placement& plm);

private:
    Axis axis;
    Vector3d xdir;
    Vector3d ydir;
};

}  // namespace Base

#endif  // BASE_COORDINATESYSTEM_H