Mantid
Loading...
Searching...
No Matches
Quat.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#include "MantidKernel/Quat.h"
8#include "MantidKernel/V3D.h"
9#include <boost/python/class.hpp>
10#include <boost/python/copy_const_reference.hpp>
11#include <boost/python/operators.hpp>
12#include <boost/python/register_ptr_to_python.hpp>
13#include <boost/python/return_arg.hpp>
14#include <boost/python/return_value_policy.hpp>
15
16using boost::python::arg;
17using boost::python::class_;
18using boost::python::copy_const_reference;
19using boost::python::init;
20using boost::python::return_value_policy;
23
26std::vector<double> getAngleAxis(Quat &self) {
27 double angle, x, y, z = 0;
28 self.getAngleAxis(angle, x, y, z);
29 return {angle, x, y, z};
30}
31
36 boost::python::register_ptr_to_python<std::shared_ptr<Quat>>();
37
38 // Quat class
39 class_<Quat>("Quat",
40 "Quaternions are the 3D generalization of complex numbers. "
41 "Quaternions are used for roations in 3D spaces and often "
42 "implemented for "
43 "computer graphics applications.",
44 init<>(arg("self"), "Construct a default Quat that will perform no transformation."))
45 .def(init<double, double, double, double>((arg("self"), arg("w"), arg("a"), arg("b"), arg("c")),
46 "Constructor with values"))
47 .def(init<V3D, V3D>((arg("self"), arg("src"), arg("dest")), "Construct a Quat between two vectors"))
48 .def(init<V3D, V3D, V3D>((arg("self"), arg("rX"), arg("rY"), arg("rZ")),
49 "Construct a Quaternion that performs a "
50 "reference frame rotation.\nThe initial X,Y,Z "
51 "vectors are aligned as expected: X=(1,0,0), "
52 "Y=(0,1,0), Z=(0,0,1)"))
53 .def(init<double, V3D>((arg("self"), arg("deg"), arg("axis")), "Constructor from an angle(degrees) and an axis."))
54 .def("rotate", &Quat::rotate, (arg("self"), arg("v")), "Rotate the quaternion by the given vector")
55 .def("real", &Quat::real, arg("self"), "Returns the real part of the quaternion")
56 .def("imagI", &Quat::imagI, arg("self"), "Returns the ith imaginary component")
57 .def("imagJ", &Quat::imagJ, arg("self"), "Returns the jth imaginary component")
58 .def("imagK", &Quat::imagK, arg("self"), "Returns the kth imaginary component")
59 .def("len", &Quat::len, arg("self"), "Returns the 'length' of the quaternion")
60 .def("len2", &Quat::len2, arg("self"), "Returns the square of the 'length' of the quaternion")
61 .def("getEulerAngles", &Quat::getEulerAngles, (arg("self"), arg("convention") = "YZX"),
62 "Default convention is \'YZX\'.")
63 .def("getAngleAxis", &getAngleAxis, arg("self"), "Extracts the angle of rotation and the axis")
64 // cppcheck-suppress syntaxError
65 .def("__add__", &Quat::operator+, (arg("left"), arg("right")))
66 .def("__iadd__", &Quat::operator+=, boost::python::return_self<>(), (arg("self"), arg("other")))
67 .def("__sub__", &Quat::operator-, (arg("left"), arg("right")))
68 .def("__isub__", &Quat::operator-=, boost::python::return_self<>(), (arg("self"), arg("other")))
69 .def("__mul__", &Quat::operator*, (arg("left"), arg("right")))
70 .def("__imul__", &Quat::operator*=, boost::python::return_self<>(), (arg("self"), arg("other")))
71 .def("__eq__", &Quat::operator==, (arg("self"), arg("other")))
72 .def("__ne__", &Quat::operator!=, (arg("self"), arg("other")))
73 .def("__getitem__", (double (Quat::*)(int) const) & Quat::operator[], (arg("self"), arg("index")))
74 .def("__str__", &Quat::toString, arg("self"));
75 //.def(boost::python::self_ns::str(self));
76}
std::vector< double > getAngleAxis(Quat &self)
Extracts the angle of rotation and axis.
Definition Quat.cpp:26
void export_Quat()
Python exports of the Mantid::Kernel::Quat class.
Definition Quat.cpp:35
Class for quaternions.
Definition Quat.h:39
double len() const
Norm of a quaternion.
Definition Quat.cpp:366
double imagJ() const
Access the coefficient of j.
Definition Quat.h:121
void getAngleAxis(double &_deg, double &_ax0, double &_ax1, double &ax2) const
Extracts the angle of roatation and axis.
Definition Quat.cpp:135
double len2() const
Norm squared.
Definition Quat.cpp:371
double real() const
Access the real part.
Definition Quat.h:117
void rotate(V3D &) const
Rotate a vector.
Definition Quat.cpp:397
std::string toString() const
Definition Quat.cpp:657
std::vector< double > getEulerAngles(const std::string &convention) const
Calculate the Euler angles that are equivalent to this Quaternion.
Definition Quat.cpp:729
double imagI() const
Access the coefficient of i.
Definition Quat.h:119
double imagK() const
Access the coefficient of k.
Definition Quat.h:123
Class for 3D vectors.
Definition V3D.h:34