4namespace tinyrobotics {
7
8
9
10
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
34 return Velocity3D(x + other.getX(unit), y + other.getY(unit), z + other.getZ(unit), unit);
38 return Velocity3D(x - other.getX(unit), y - other.getY(unit), z - other.getZ(unit), unit);
42 return Velocity3D(x * scalar, y * scalar, z * scalar, unit);
46 if (scalar == 0)
return Velocity3D(0, 0, 0, unit);
47 return Velocity3D(x / scalar, y / scalar, z / scalar, unit);
50 bool operator==(
const Velocity3D& other)
const {
51 return x == other.getX(unit) && y == other.getY(unit) && z == other.getZ(unit);
54 bool operator!=(
const Velocity3D& other)
const {
return !(*
this == other); }
56 bool operator<(
const Velocity3D& other)
const {
57 return (x < other.getX(unit)) && (y < other.getY(unit)) && (z < other.getZ(unit));
60 bool operator<=(
const Velocity3D& other)
const {
61 return (x <= other.getX(unit)) && (y <= other.getY(unit)) && (z <= other.getZ(unit));
64 bool operator>(
const Velocity3D& other)
const {
65 return (x > other.getX(unit)) && (y > other.getY(unit)) && (z > other.getZ(unit));
68 bool operator>=(
const Velocity3D& other)
const {
69 return (x >= other.getX(unit)) && (y >= other.getY(unit)) && (z >= other.getZ(unit));
73 x += other.getX(unit);
74 y += other.getY(unit);
75 z += other.getZ(unit);
80 x -= other.getX(unit);
81 y -= other.getY(unit);
82 z -= other.getZ(unit);
107 VelocityUnit unit = VelocityUnit::MPS;
109 Velocity3D() =
default;
110 Velocity3D(
float x,
float y,
float z, VelocityUnit unit) : x(x), y(y), z(z), unit(unit) {}
112 float getX(VelocityUnit desiredUnit)
const {
113 if (unit == desiredUnit)
return x;
114 Speed tempSpeed(x, unit);
115 return tempSpeed.getValue(desiredUnit);
117 float getY(VelocityUnit desiredUnit)
const {
118 if (unit == desiredUnit)
return y;
119 Speed tempSpeed(y, unit);
120 return tempSpeed.getValue(desiredUnit);
122 float getZ(VelocityUnit desiredUnit)
const {
123 if (unit == desiredUnit)
return z;
124 Speed tempSpeed(z, unit);
125 return tempSpeed.getValue(desiredUnit);
Represents a speed measurement with unit conversion support.
Definition: Speed.h:40
Represents a 3D speed or velocity vector with unit support.
Definition: Velocity3D.h:32
SpeedUnit
Supported speed units for conversion and representation.
Definition: Speed.h:10