IOSS 2.0

vector3d.h
Go to the documentation of this file.
1 /*
2 * Copyright(C) 1999-2017 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 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * * Neither the name of NTESS nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 #ifndef VECTOR3D
35 #define VECTOR3D
36
37 class vector3d
38 {
39 public:
40 // construction
41 vector3d();
42 vector3d(double X, double Y, double Z);
43 explicit vector3d(double location[3]);
44 vector3d(const vector3d &from);
45
46 double x{}, y{}, z{};
47
48 vector3d &operator=(const vector3d &from);
49 bool operator==(const vector3d &from) const;
50 bool operator!=(const vector3d &from) const;
51 void set(double X, double Y, double Z);
52 void set(double location[3]);
53 vector3d &reverse();
54
55 vector3d operator-() const;
56
57 vector3d &operator+=(const vector3d &from);
58 vector3d &operator-=(const vector3d &from);
59 vector3d &operator*=(double scalar);
60 vector3d &operator/=(double scalar);
61
62 double length() const;
63 double normalize(double tolerance = 1e-06);
64 vector3d cross(const vector3d &from) const;
65 static vector3d plane_normal(const vector3d &v1, const vector3d &v2, const vector3d &v3);
66 };
67
68 vector3d operator*(double scalar, const vector3d &from);
69 vector3d operator*(const vector3d &lhs, double scalar);
70 vector3d operator/(const vector3d &lhs, double scalar);
71
72 vector3d operator+(const vector3d &lhs, const vector3d &rhs);
73 vector3d operator-(const vector3d &lhs, const vector3d &rhs);
74
75 //----------------------------------------------------------------------------
76 inline vector3d vector3d::cross(const vector3d &from) const
77 {
78 return vector3d(y * from.z - z * from.y, z * from.x - x * from.z, x * from.y - y * from.x);
79 }
80 //----------------------------------------------------------------------------
81 inline vector3d &vector3d::operator+=(const vector3d &from)
82 {
83 x += from.x;
84 y += from.y;
85 z += from.z;
86 return *this;
87 }
88 //----------------------------------------------------------------------------
89 inline vector3d &vector3d::operator-=(const vector3d &from)
90 {
91 x -= from.x;
92 y -= from.y;
93 z -= from.z;
94 return *this;
95 }
96 //----------------------------------------------------------------------------
97 inline vector3d &vector3d::operator*=(double scalar)
98 {
99 x *= scalar;
100 y *= scalar;
101 z *= scalar;
102 return *this;
103 }
104
105 #endif
vector3d::cross
vector3d cross(const vector3d &from) const
Definition: vector3d.h:76
vector3d::operator+=
vector3d & operator+=(const vector3d &from)
Definition: vector3d.h:81
vector3d::operator==
bool operator==(const vector3d &from) const
Definition: vector3d.C:73
vector3d::operator/=
vector3d & operator/=(double scalar)
Definition: vector3d.C:122
vector3d::set
void set(double X, double Y, double Z)
Definition: vector3d.C:49
anonymous_namespace{Ioss_ConcreteVariableType.C}::Y
const std::string Y()
Definition: Ioss_ConcreteVariableType.C:41
vector3d::reverse
vector3d & reverse()
Definition: vector3d.C:65
vector3d::z
double z
Definition: vector3d.h:46
operator*
vector3d operator*(double scalar, const vector3d &from)
Definition: vector3d.C:107
vector3d::vector3d
vector3d()
Definition: vector3d.C:38
vector3d
Definition: vector3d.h:37
operator+
vector3d operator+(const vector3d &lhs, const vector3d &rhs)
Definition: vector3d.C:83
operator/
vector3d operator/(const vector3d &lhs, double scalar)
Definition: vector3d.C:113
vector3d::operator=
vector3d & operator=(const vector3d &from)
anonymous_namespace{Ioss_ConcreteVariableType.C}::scalar
const std::string scalar()
Definition: Ioss_ConcreteVariableType.C:57
vector3d::operator*=
vector3d & operator*=(double scalar)
Definition: vector3d.h:97
operator-
vector3d operator-(const vector3d &lhs, const vector3d &rhs)
Definition: vector3d.C:89
vector3d::x
double x
Definition: vector3d.h:46
vector3d::operator!=
bool operator!=(const vector3d &from) const
Definition: vector3d.C:78
vector3d::normalize
double normalize(double tolerance=1e-06)
Definition: vector3d.C:140
anonymous_namespace{Ioss_ConcreteVariableType.C}::X
const std::string X()
Definition: Ioss_ConcreteVariableType.C:40
vector3d::operator-=
vector3d & operator-=(const vector3d &from)
Definition: vector3d.h:89
anonymous_namespace{Ioss_ConcreteVariableType.C}::Z
const std::string Z()
Definition: Ioss_ConcreteVariableType.C:42
vector3d::length
double length() const
Definition: vector3d.C:138
vector3d::y
double y
Definition: vector3d.h:46
vector3d::operator-
vector3d operator-() const
Definition: vector3d.C:101
vector3d::plane_normal
static vector3d plane_normal(const vector3d &v1, const vector3d &v2, const vector3d &v3)
Definition: vector3d.C:156