1
/***************************************************************************
2
* Copyright (c) 2014 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 51 Franklin Street, *
19
* Fifth Floor, Boston, MA 02110-1301, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
26
#include "CoordinateSystem.h"
33
CoordinateSystem::CoordinateSystem()
34
: axis(Vector3d(), Vector3d(0, 0, 1))
39
void CoordinateSystem::setAxes(const Axis& vec, const Vector3d& xd)
41
if (xd.Sqr() < Base::Vector3d::epsilon()) {
42
throw Base::ValueError("Direction is null vector");
44
Vector3d yd = vec.getDirection() % xd;
45
if (yd.Sqr() < Base::Vector3d::epsilon()) {
46
throw Base::ValueError("Direction is parallel to Z direction");
50
xdir = ydir % vec.getDirection();
52
axis.setBase(vec.getBase());
53
Base::Vector3d zdir = vec.getDirection();
55
axis.setDirection(zdir);
58
void CoordinateSystem::setAxes(const Vector3d& n, const Vector3d& xd)
60
if (xd.Sqr() < Base::Vector3d::epsilon()) {
61
throw Base::ValueError("Direction is null vector");
64
if (yd.Sqr() < Base::Vector3d::epsilon()) {
65
throw Base::ValueError("Direction is parallel to Z direction");
71
Base::Vector3d zdir = n;
73
axis.setDirection(zdir);
76
void CoordinateSystem::setAxis(const Axis& axis)
81
void CoordinateSystem::setXDirection(const Vector3d& dir)
83
Vector3d yd = axis.getDirection() % dir;
84
if (yd.Sqr() < Base::Vector3d::epsilon()) {
85
throw Base::ValueError("Direction is parallel to Z direction");
89
xdir = ydir % axis.getDirection();
93
void CoordinateSystem::setYDirection(const Vector3d& dir)
95
Vector3d xd = dir % axis.getDirection();
96
if (xd.Sqr() < Base::Vector3d::epsilon()) {
97
throw Base::ValueError("Direction is parallel to Z direction");
101
ydir = axis.getDirection() % xdir;
105
void CoordinateSystem::setZDirection(const Vector3d& dir)
110
Placement CoordinateSystem::displacement(const CoordinateSystem& cs) const
113
const Base::Vector3d& a = axis.getBase();
114
const Base::Vector3d& zdir = axis.getDirection();
125
Base::Vector3d at = At * a;
130
const Base::Vector3d& b = cs.axis.getBase();
131
const Base::Vector3d& cszdir = cs.axis.getDirection();
148
Placement C = PB * PAt;
153
void CoordinateSystem::transformTo(Vector3d& pnt)
155
return pnt.TransformToCoordinateSystem(axis.getBase(), xdir, ydir);
158
void CoordinateSystem::transform(const Placement& plm)
161
plm.getRotation().multVec(this->xdir, this->xdir);
162
plm.getRotation().multVec(this->ydir, this->ydir);
165
void CoordinateSystem::transform(const Rotation& rot)
167
Vector3d zdir = axis.getDirection();
168
rot.multVec(zdir, zdir);
169
axis.setDirection(zdir);
170
rot.multVec(this->xdir, this->xdir);
171
rot.multVec(this->ydir, this->ydir);
174
void CoordinateSystem::setPlacement(const Placement& plm)
176
Vector3d zdir(0, 0, 1);
177
plm.getRotation().multVec(zdir, zdir);
178
axis.setBase(plm.getPosition());
179
axis.setDirection(zdir);
181
plm.getRotation().multVec(Vector3d(1, 0, 0), this->xdir);
182
plm.getRotation().multVec(Vector3d(0, 1, 0), this->ydir);