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
28 boost::python::register_ptr_to_python<std::shared_ptr<Quat>>();
29
30 // Quat class
31 class_<Quat>("Quat",
32 "Quaternions are the 3D generalization of complex numbers. "
33 "Quaternions are used for roations in 3D spaces and often "
34 "implemented for "
35 "computer graphics applications.",
36 init<>(arg("self"), "Construct a default Quat that will perform no transformation."))
37 .def(init<double, double, double, double>((arg("self"), arg("w"), arg("a"), arg("b"), arg("c")),
38 "Constructor with values"))
39 .def(init<V3D, V3D>((arg("self"), arg("src"), arg("dest")), "Construct a Quat between two vectors"))
40 .def(init<V3D, V3D, V3D>((arg("self"), arg("rX"), arg("rY"), arg("rZ")),
41 "Construct a Quaternion that performs a "
42 "reference frame rotation.\nThe initial X,Y,Z "
43 "vectors are aligned as expected: X=(1,0,0), "
44 "Y=(0,1,0), Z=(0,0,1)"))
45 .def(init<double, V3D>((arg("self"), arg("deg"), arg("axis")), "Constructor from an angle(degrees) and an axis."))
46 .def("rotate", &Quat::rotate, (arg("self"), arg("v")), "Rotate the quaternion by the given vector")
47 .def("real", &Quat::real, arg("self"), "Returns the real part of the quaternion")
48 .def("imagI", &Quat::imagI, arg("self"), "Returns the ith imaginary component")
49 .def("imagJ", &Quat::imagJ, arg("self"), "Returns the jth imaginary component")
50 .def("imagK", &Quat::imagK, arg("self"), "Returns the kth imaginary component")
51 .def("len", &Quat::len, arg("self"), "Returns the 'length' of the quaternion")
52 .def("len2", &Quat::len2, arg("self"), "Returns the square of the 'length' of the quaternion")
53 .def("getEulerAngles", &Quat::getEulerAngles, (arg("self"), arg("convention") = "YZX"),
54 "Default convention is \'YZX\'.")
55 .def("__add__", &Quat::operator+, (arg("left"), arg("right")))
56 .def("__iadd__", &Quat::operator+=, boost::python::return_self<>(), (arg("self"), arg("other")))
57 .def("__sub__", &Quat::operator-, (arg("left"), arg("right")))
58 .def("__isub__", &Quat::operator-=, boost::python::return_self<>(), (arg("self"), arg("other")))
59 .def("__mul__", &Quat::operator*, (arg("left"), arg("right")))
60 .def("__imul__", &Quat::operator*=, boost::python::return_self<>(), (arg("self"), arg("other")))
61 .def("__eq__", &Quat::operator==, (arg("self"), arg("other")))
62 .def("__ne__", &Quat::operator!=, (arg("self"), arg("other")))
63 .def("__getitem__", (double (Quat::*)(int) const) & Quat::operator[], (arg("self"), arg("index")))
64 .def("__str__", &Quat::toString, arg("self"));
65 //.def(boost::python::self_ns::str(self));
66}
void export_Quat()
Python exports of the Mantid::Kernel::Quat class.
Definition: Quat.cpp:27
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
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