Mantid
Loading...
Searching...
No Matches
V2D.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/V2D.h"
9
10#include <ostream>
11
12namespace Mantid::Kernel {
13
14//-----------------------------------------------------------------------------
15// Public member functions
16//-----------------------------------------------------------------------------
17
23 const double length = norm();
24 X() /= length;
25 Y() /= length;
26 return length;
27}
28
32double V2D::angle(const V2D &other) const {
33 double ratio = this->scalar_prod(other) / (this->norm() * other.norm());
34
35 if (ratio >= 1.0) // NOTE: Due to rounding errors, if "other"
36 return 0.0; // is nearly the same as "this" or
37 else if (ratio <= -1.0) // as "-this", ratio can be slightly
38 return M_PI; // more than 1 in absolute value.
39 // That causes acos() to return NaN.
40 return acos(ratio);
41}
42
43//--------------------------------------------------------------------------
44// Non-member, non-friend functions
45//--------------------------------------------------------------------------
51std::ostream &operator<<(std::ostream &os, const V2D &point) {
52 os << "[" << point.X() << "," << point.Y() << "]";
53 return os;
54}
55
56} // namespace Mantid::Kernel
Implements a 2-dimensional vector embedded in a 3D space, i.e.
Definition: V2D.h:29
double Y() const
Y position.
Definition: V2D.h:49
double normalize()
Make a normalized vector (return norm value)
Definition: V2D.cpp:22
double angle(const V2D &other) const
Angle between this and another vector.
Definition: V2D.cpp:32
double scalar_prod(const V2D &other) const
Compute the scalar product with another vector.
Definition: V2D.h:133
double X() const
X position.
Definition: V2D.h:44
double norm() const
Compute the norm.
Definition: V2D.h:121
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.
Definition: CPUTimer.cpp:86