9#include "MantidKernel/DllConfig.h"
26template <
class T>
class Matrix;
34class MANTID_KERNEL_DLL
V3D final {
36 constexpr V3D() noexcept : m_pt({{0., 0., 0.}}) {}
37 constexpr V3D(
double xx,
double yy,
double zz) noexcept : m_pt({{xx, yy, zz}}) {}
43 operator std::vector<double>()
const {
return std::vector<double>(m_pt.cbegin(), m_pt.cend()); }
51 return V3D(m_pt[0] + v.m_pt[0], m_pt[1] + v.m_pt[1], m_pt[2] + v.m_pt[2]);
60 return V3D(m_pt[0] - v.m_pt[0], m_pt[1] - v.m_pt[1], m_pt[2] - v.m_pt[2]);
69 return V3D(m_pt[0] * v.m_pt[0], m_pt[1] * v.m_pt[1], m_pt[2] * v.m_pt[2]);
78 return V3D(m_pt[0] / v.m_pt[0], m_pt[1] / v.m_pt[1], m_pt[2] / v.m_pt[2]);
87 for (
size_t i = 0; i < m_pt.size(); ++i) {
99 for (
size_t i = 0; i < m_pt.size(); ++i) {
100 m_pt[i] -= v.
m_pt[i];
111 for (
size_t i = 0; i < m_pt.size(); ++i) {
112 m_pt[i] *= v.
m_pt[i];
123 for (
size_t i = 0; i < m_pt.size(); ++i) {
124 m_pt[i] /= v.
m_pt[i];
134 constexpr V3D operator*(
const double D)
const noexcept {
return V3D(m_pt[0] * D, m_pt[1] * D, m_pt[2] * D); }
141 constexpr V3D operator/(
const double D)
const noexcept {
return V3D(m_pt[0] / D, m_pt[1] / D, m_pt[2] / D); }
149 std::for_each(m_pt.begin(), m_pt.end(), [D](
auto &pt) { pt *= D; });
160 std::for_each(m_pt.begin(), m_pt.end(), [D](
auto &pt) { pt /= D; });
168 constexpr V3D operator-() const noexcept {
return V3D(-m_pt[0], -m_pt[1], -m_pt[2]); }
176 return !(std::abs(m_pt[0] - v.m_pt[0]) >
Tolerance || std::abs(m_pt[1] - v.m_pt[1]) >
Tolerance ||
177 std::abs(m_pt[2] - v.m_pt[2]) >
Tolerance);
191 if (m_pt[0] != V.m_pt[0])
192 return m_pt[0] < V.m_pt[0];
193 if (m_pt[1] != V.m_pt[1])
194 return m_pt[1] < V.m_pt[1];
195 return m_pt[2] < V.m_pt[2];
207 void operator()(
const double xx,
const double yy,
const double zz)
noexcept { m_pt = {{xx, yy, zz}}; }
211 void spherical(
const double R,
const double theta,
const double phi)
noexcept;
212 void spherical_rad(
const double R,
const double polar,
const double azimuth)
noexcept;
213 void azimuth_polar_SNS(
const double R,
const double azimuth,
const double polar)
noexcept;
218 void setX(
const double xx)
noexcept { m_pt[0] = xx; }
224 void setY(
const double yy)
noexcept { m_pt[1] = yy; }
230 void setZ(
const double zz)
noexcept { m_pt[2] = zz; }
232 constexpr double X() const noexcept {
return m_pt[0]; }
233 constexpr double Y() const noexcept {
return m_pt[1]; }
234 constexpr double Z() const noexcept {
return m_pt[2]; }
242 assert(
index < m_pt.size());
252 assert(
index < m_pt.size());
256 void getSpherical(
double &R,
double &theta,
double &phi)
const noexcept;
260 void round() noexcept;
263 double norm() const noexcept {
return sqrt(norm2()); }
265 constexpr double norm2() const noexcept {
return m_pt[0] * m_pt[0] + m_pt[1] * m_pt[1] + m_pt[2] * m_pt[2]; }
268 double toMillerIndexes(
double eps = 1.e-3);
275 return m_pt[0] * v.m_pt[0] + m_pt[1] * v.m_pt[1] + m_pt[2] * v.m_pt[2];
279 return V3D(m_pt[1] * v.m_pt[2] - m_pt[2] * v.m_pt[1], m_pt[2] * v.m_pt[0] - m_pt[0] * v.m_pt[2],
280 m_pt[0] * v.m_pt[1] - m_pt[1] * v.m_pt[0]);
287 double distance(
const V3D &v)
const noexcept {
return (*
this - v).norm(); }
289 double zenith(
const V3D &)
const noexcept;
291 double angle(
const V3D &)
const;
293 double cosAngle(
const V3D &)
const;
295 V3D directionAngles(
bool inDegrees =
true)
const;
299 V3D absoluteValue()
const;
301 double hklError()
const;
304 static std::vector<V3D> makeVectorsOrthogonal(
const std::vector<V3D> &vectors);
307 void printSelf(std::ostream &)
const;
308 void readPrinted(std::istream &);
309 void read(std::istream &);
310 void write(std::ostream &)
const;
311 std::string toString()
const;
312 void fromString(
const std::string &str);
315 double volume() const noexcept {
return std::abs(m_pt[0] * m_pt[1] * m_pt[2]); }
317 int reBase(
const V3D &,
const V3D &,
const V3D &)
noexcept;
319 int masterDir(
const double Tol = 1e-3) const noexcept;
321 bool nullVector(const
double tolerance = 1e-3) const noexcept;
322 bool unitVector(const
double tolerance = Kernel::Tolerance) const noexcept;
323 bool coLinear(const
V3D &, const
V3D &) const noexcept;
325 void saveNexus(::
NeXus::File *file, const
std::
string &name) const;
326 void loadNexus(::
NeXus::File *file, const
std::
string &name);
329 std::array<
double, 3> m_pt;
333MANTID_KERNEL_DLL
std::ostream &operator<<(
std::ostream &, const
V3D &);
334MANTID_KERNEL_DLL
std::istream &operator>>(
std::istream &,
V3D &);
341inline MANTID_KERNEL_DLL
V3D normalize(
V3D v) {
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
double distance(const V3D &v) const noexcept
Calculates the distance between two vectors.
constexpr bool operator<(const V3D &V) const noexcept
compare
void operator()(const double xx, const double yy, const double zz) noexcept
Sets the vector position from a triplet of doubles x,y,z.
std::array< double, 3 > m_pt
constexpr V3D operator*(const double D) const noexcept
Scalar product.
constexpr V3D operator/(const V3D &v) const noexcept
Inner division.
V3D & operator*=(const double D) noexcept
Scalar product.
constexpr double operator[](const size_t index) const noexcept
Returns the axis value based in the index provided.
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
V3D & operator*=(const V3D &v) noexcept
Self-Inner product.
constexpr double X() const noexcept
Get x.
V3D & operator/=(const V3D &v) noexcept
Self-Inner division.
double normalize()
Make a normalized vector (return norm value)
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
constexpr V3D operator-() const noexcept
Negation.
constexpr double Y() const noexcept
Get y.
void setZ(const double zz) noexcept
Set is z position.
V3D & operator+=(const V3D &v) noexcept
Self-Addition operator.
constexpr double norm2() const noexcept
Vector length squared.
double volume() const noexcept
Calculate the volume of a cube X*Y*Z.
constexpr bool operator>(const V3D &rhs) const noexcept
Comparison operator greater than.
double & operator[](const size_t index) noexcept
Returns the axis value based in the index provided.
void setX(const double xx) noexcept
Set is x position.
constexpr V3D operator*(const V3D &v) const noexcept
Inner product.
V3D & operator-=(const V3D &v) noexcept
Self-Subtraction operator.
bool operator==(const V3D &v) const noexcept
Equals operator with tolerance factor.
constexpr V3D operator-(const V3D &v) const noexcept
Subtraction operator.
void setY(const double yy) noexcept
Set is y position.
constexpr double Z() const noexcept
Get z.
constexpr V3D operator/(const double D) const noexcept
Scalar divsion.
constexpr V3D(double xx, double yy, double zz) noexcept
V3D & operator/=(const double D) noexcept
Scalar division.
bool operator!=(const V3D &other) const noexcept
Not equals operator with tolerance factor.
constexpr V3D operator+(const V3D &v) const noexcept
Addtion operator.
constexpr double Tolerance
Standard tolerance value.
Helper class which provides the Collimation Length for SANS instruments.
constexpr bool operator==(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)