| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2022, 2023, 2024 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
#pragma once |
| 9 |
|
| 10 |
class vector3d |
| 11 |
{ |
| 12 |
public: |
| 13 |
// construction |
| 14 |
vector3d() = default; |
| 15 |
vector3d(double X, double Y, double Z); |
| 16 |
|
| 17 |
double x{}, y{}, z{}; |
| 18 |
|
| 19 |
bool operator==(const vector3d &from) const; |
| 20 |
bool operator!=(const vector3d &from) const; |
| 21 |
void set(double X, double Y, double Z); |
| 22 |
void set(const double location[3]); |
| 23 |
vector3d &reverse(); |
| 24 |
|
| 25 |
vector3d operator-() const; |
| 26 |
|
| 27 |
vector3d &operator+=(const vector3d &from); |
| 28 |
vector3d &operator-=(const vector3d &from); |
| 29 |
vector3d &operator*=(double scalar); |
| 30 |
vector3d &operator/=(double scalar); |
| 31 |
|
| 32 |
friend vector3d operator*(double scalar, const vector3d &from); |
| 33 |
friend vector3d operator*(const vector3d &lhs, double scalar); |
| 34 |
friend vector3d operator/(const vector3d &lhs, double scalar); |
| 35 |
|
| 36 |
friend vector3d operator+(const vector3d &lhs, const vector3d &rhs); |
| 37 |
friend vector3d operator-(const vector3d &lhs, const vector3d &rhs); |
| 38 |
|
| 39 |
double length() const; |
| 40 |
double normalize(double tolerance = 1e-06); |
| 41 |
vector3d cross(const vector3d &from) const; |
| 42 |
static vector3d plane_normal(const vector3d &v1, const vector3d &v2, const vector3d &v3); |
| 43 |
}; |
| 44 |
|
| 45 |
//---------------------------------------------------------------------------- |
| 46 |
inline vector3d vector3d::cross(const vector3d &from) const |
| 47 |
{ |
| 48 |
return {y * from.z - z * from.y, z * from.x - x * from.z, x * from.y - y * from.x}; |
| 49 |
} |
| 50 |
//---------------------------------------------------------------------------- |
| 51 |
inline vector3d &vector3d::operator+=(const vector3d &from) |
| 52 |
{ |
| 53 |
x += from.x; |
| 54 |
y += from.y; |
| 55 |
z += from.z; |
| 56 |
return *this; |
| 57 |
} |
| 58 |
//---------------------------------------------------------------------------- |
| 59 |
inline vector3d &vector3d::operator-=(const vector3d &from) |
| 60 |
{ |
| 61 |
x -= from.x; |
| 62 |
y -= from.y; |
| 63 |
z -= from.z; |
| 64 |
return *this; |
| 65 |
} |
| 66 |
//---------------------------------------------------------------------------- |
| 67 |
inline vector3d &vector3d::operator*=(double scalar) |
| 68 |
{ |
| 69 |
x *= scalar; |
| 70 |
y *= scalar; |
| 71 |
z *= scalar; |
| 72 |
return *this; |
| 73 |
} |