RoboDK Plug-In Interface
Loading...
Searching...
No Matches
vector3.h
1/****************************************************************************
2**
3** Copyright (c) 2015-2026 RoboDK Global.
4** Contact: https://robodk.com/
5**
6** This file is part of the RoboDK API.
7**
8** Permission is hereby granted, free of charge, to any person obtaining a copy
9** of this software and associated documentation files (the "Software"), to deal
10** in the Software without restriction, including without limitation the rights
11** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12** copies of the Software, and to permit persons to whom the Software is
13** furnished to do so, subject to the following conditions:
14**
15** The above copyright notice and this permission notice shall be included in all
16** copies or substantial portions of the Software.
17**
18** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24** SOFTWARE.
25**
26** RoboDK is a registered trademark of RoboDK Global.
27**
28****************************************************************************/
29
30#ifndef ROBODK_VECTOR3_H
31#define ROBODK_VECTOR3_H
32
33
34#include <cstddef>
35
36
37namespace robodk
38{
39
49{
50public:
54 Vector3() = default;
55
59 Vector3(double x, double y, double z);
60
64 Vector3(const Vector3& v) = default;
65
69 double Length() const;
70
75 void Normalize();
76
80 inline double X() const { return _v[0]; }
81
85 inline double Y() const { return _v[1]; }
86
90 inline double Z() const { return _v[2]; }
91
95 inline void SetX(double x) { _v[0] = x; }
96
100 inline void SetY(double y) { _v[0] = y; }
101
105 inline void SetZ(double z) { _v[0] = z; }
106
110 inline const double& operator[](size_t i) const { return _v[i]; }
111
116 inline double& operator[](size_t i) { return _v[i]; }
117
121 static double DotProduct(const Vector3& v1, const Vector3& v2);
122
127 static Vector3 CrossProduct(const Vector3& v1, const Vector3& v2);
128
132 Vector3& operator=(const Vector3& v) = default;
133
134private:
137 double _v[3] = {0.0, 0.0, 0.0};
138
140};
141
142} // namespace robodk
143
144
145#endif // ROBODK_VECTOR3_H
The Vector3 class represents a vector or vertex in 3D space.
Definition vector3.h:49
static double DotProduct(const Vector3 &v1, const Vector3 &v2)
Returns the dot product of v1 and v2.
Definition vector3.cpp:61
void SetZ(double z)
Sets the z coordinate of this vector to the given z coordinate.
Definition vector3.h:105
double & operator[](size_t i)
Returns the component of the vector at index position i as a modifiable reference.
Definition vector3.h:116
Vector3(const Vector3 &v)=default
Constructs a vector object as a copy of v.
Vector3()=default
Constructs a null vector, i.e.
const double & operator[](size_t i) const
Returns the component of the vector at index position i.
Definition vector3.h:110
double Length() const
Returns the length of the vector from the origin.
Definition vector3.cpp:45
static Vector3 CrossProduct(const Vector3 &v1, const Vector3 &v2)
Returns the cross-product of vectors v1 and v2, which corresponds to the normal vector of a plane def...
Definition vector3.cpp:66
void SetX(double x)
Sets the x coordinate of this vector to the given x coordinate.
Definition vector3.h:95
double Z() const
Returns the z coordinate of this vector.
Definition vector3.h:90
Vector3 & operator=(const Vector3 &v)=default
Sets this Vector3 object as a copy of v.
double X() const
Returns the x coordinate of this vector.
Definition vector3.h:80
void Normalize()
Normalizes the currect vector in place.
Definition vector3.cpp:50
double Y() const
Returns the y coordinate of this vector.
Definition vector3.h:85
void SetY(double y)
Sets the y coordinate of this vector to the given y coordinate.
Definition vector3.h:100