19 #ifndef BORNAGAIN_BASE_VECTOR_BASICVECTOR3D_H
20 #define BORNAGAIN_BASE_VECTOR_BASICVECTOR3D_H
63 T
x()
const {
return v_[0]; }
65 T
y()
const {
return v_[1]; }
67 T
z()
const {
return v_[2]; }
128 double mag2()
const {
return std::norm(
v_[0]) + std::norm(
v_[1]) + std::norm(
v_[2]); }
134 double magxy2()
const {
return std::norm(
v_[0]) + std::norm(
v_[1]); }
208 return os <<
"(" << a.
x() <<
"," << a.
y() <<
"," << a.
z() <<
")";
283 return (a.
x() == b.
x() && a.
y() == b.
y() && a.
z() == b.
z());
290 return (a.
x() != b.
x() || a.
y() != b.
y() || a.
z() != b.
z());
304 return left_star.
x() * v.
x() + left_star.
y() * v.
y() + left_star.
z() * v.
z();
315 y() * v.
z() - v.
y() * z(), z() * v.
x() - v.
z() * x(), x() * v.
y() - v.
x() * y());
Defines complex_t, and a few elementary functions.
Three-dimensional vector template, for use with integer, double, or complex components.
auto operator*=(U a)
Multiplies this with a scalar, and returns result.
double mag2() const
Returns magnitude squared of the vector.
bool operator!=(const BasicVector3D< T > &a, const BasicVector3D< T > &b)
Comparison of two vectors for inequality.
BasicVector3D< T > conj() const
Returns complex conjugate vector.
BasicVector3D(const T x1, const T y1, const T z1)
Constructs a vector from cartesian components.
auto dot(const BasicVector3D< U > &v) const
Returns dot product of vectors (antilinear in the first [=self] argument).
double sin2Theta() const
Returns squared sine of polar angle.
BasicVector3D< T > rotated(double a, const BasicVector3D< T > &v) const
Returns result of rotation around the axis specified by another vector.
BasicVector3D< T > rotatedY(double a) const
Returns result of rotation around y-axis.
BasicVector3D< T > project(const BasicVector3D< T > &v) const
Returns projection of this onto other vector: (this*v)*v/|v|^2.
BasicVector3D< T > unit() const
Returns unit vector in direction of this. Throws for null vector.
double magxy2() const
Returns squared distance from z axis.
BasicVector3D< T > operator+(const BasicVector3D< T > &v)
Unary plus.
auto operator*(const BasicVector3D< T > &v, const U a)
Multiplication vector by scalar.
double mag() const
Returns magnitude of the vector.
double theta() const
Returns polar angle.
BasicVector3D< complex_t > complex() const
Returns this, trivially converted to complex type.
BasicVector3D()
Constructs the null vector.
BasicVector3D< double > real() const
Returns real parts.
void setX(const T &a)
Sets x-component in cartesian coordinate system.
auto operator*(const U a, const BasicVector3D< T > &v)
Multiplication scalar by vector.
BasicVector3D< T > rotatedZ(double a) const
Returns result of rotation around z-axis.
T z() const
Returns z-component in cartesian coordinate system.
BasicVector3D< T > & operator+=(const BasicVector3D< T > &v)
Adds other vector to this, and returns result.
BasicVector3D< T > operator/(const BasicVector3D< T > &v, U a)
Division vector by scalar.
void setY(const T &a)
Sets y-component in cartesian coordinate system.
BasicVector3D< T > rotatedX(double a) const
Returns result of rotation around x-axis.
BasicVector3D< T > & operator-=(const BasicVector3D< T > &v)
Subtracts other vector from this, and returns result.
T operator[](int i) const
Returns components by index.
T & operator[](int i)
Sets components by index.
T y() const
Returns y-component in cartesian coordinate system.
BasicVector3D< T > operator-(const BasicVector3D< T > &a, const BasicVector3D< T > &b)
Subtraction of two vectors.
bool operator==(const BasicVector3D< T > &a, const BasicVector3D< T > &b)
Comparison of two vectors for equality.
auto operator/=(U a)
Divides this by a scalar, and returns result.
double phi() const
Returns azimuth angle.
std::ostream & operator<<(std::ostream &os, const BasicVector3D< T > &a)
Output to stream.
T x() const
Returns x-component in cartesian coordinate system.
void setZ(const T &a)
Sets z-component in cartesian coordinate system.
double magxy() const
Returns distance from z axis.
double angle(const BasicVector3D< T > &v) const
Returns angle with respect to another vector.
auto cross(const BasicVector3D< U > &v) const
Returns cross product of vectors (linear in both arguments).
BasicVector3D< T > operator+(const BasicVector3D< T > &a, const BasicVector3D< T > &b)
Addition of two vectors.
double cosTheta() const
Returns cosine of polar angle.
BasicVector3D< T > operator-(const BasicVector3D< T > &v)
Unary minus.