TinyRobotics
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Coordinate< T > Class Template Reference

A generic 3D coordinate class for robotics, navigation, and spatial calculations. More...

#include <Coordinate.h>

Inheritance diagram for Coordinate< T >:
Inheritance graph
[legend]
Collaboration diagram for Coordinate< T >:
Collaboration graph
[legend]

Public Types

using value_type = T
 

Public Member Functions

 Coordinate (T x, T y, T z=0)
 
 Coordinate (const Coordinate &other)
 Copy constructor.
 
 Coordinate (Distance x, Distance y, Distance z=0)
 Construct from Distance objects.
 
DistanceM distance (const Coordinate &other, DistanceUnit unit=DistanceUnit::M) const
 
float bearing (const Coordinate &other, AngleUnit unit=AngleUnit::DEG) const
 
float elevation (const Coordinate &other, AngleUnit unit=AngleUnit::DEG) const
 Calculate the elevation angle from this coordinate to another.
 
Coordinate navigate (Distance distance, Angle bearing, Distance altDiff=0) const
 
Coordinate navigate (DistanceM distanceM, float headingDegrees, float altDiffM=0) const
 
DistanceM altitudeDifference (const Coordinate &other) const
 
bool equals (const Coordinate &other, DistanceM limit) const
 
bool equalsWithAltitude (const Coordinate &other, DistanceM limit, DistanceM altLimit) const
 
Coordinate operator+ (const Coordinate &other) const
 
Coordinate operator- (const Coordinate &other) const
 Calculate new coordinate by subtracting offset in other from this one.
 
void operator+= (const Coordinate &other)
 Add offset defined in other to current coordinate.
 
void operator-= (const Coordinate &other)
 Subtract offset in other from this one.
 
void operator= (const Coordinate &other)
 Assign values from another coordinate.
 
bool operator== (const Coordinate< T > &other) const
 Equality operators for use in std::unordered_map and comparisons.
 
bool operator!= (const Coordinate< T > &other) const
 
bool operator< (const Coordinate &other) const
 Lexicographical comparison for STL containers (priority_queue, set, etc.)
 
std::string toString () const
 Convert coordinate to string representation.
 
bool fromString (const std::string &str)
 Parse coordinate from string representation.
 
void setValues (T newX, T newY, T newZ=0)
 Set coordinate values from numeric types.
 
void setValues (Distance newX, Distance newY, Distance newZ=0)
 Set coordinate values from Distance objects.
 
std::vector< Coordinate< T > > interpolateTo (const Coordinate< T > &target, T resolution)
 Interpolate points between source and target with a defined resolution.
 
std::vector< Coordinate< T > > interpolateTo (const Coordinate< T > &target, Distance resolution)
 Interpolate points between source and target with Distance resolution.
 
const char * getTypeName () const
 Get the type name string.
 
- Public Member Functions inherited from Serializable
virtual std::string toString () const =0
 
const char * toCString () const
 
virtual bool fromString (const std::string &in)=0
 
virtual bool fromString (const char *in)
 
size_t writeTo (Print &out) const
 
size_t readFrom (Stream &in)
 

Public Attributes

x = 0
 X coordinate (meters)
 
y = 0
 Y coordinate (meters)
 
z = 0
 Z coordinate (meters)
 

Protected Member Functions

AngleDeg bearingDeg (const Coordinate &other) const
 Calculate bearing in degrees to another coordinate.
 
AngleDeg elevationDeg (const Coordinate &other) const
 Calculate elevation angle in degrees to another coordinate.
 
DistanceM distanceM (const Coordinate &other) const
 Calculate Euclidean distance in meters to another coordinate.
 

Detailed Description

template<typename T = DistanceM>
class tinyrobotics::Coordinate< T >

A generic 3D coordinate class for robotics, navigation, and spatial calculations.

The Coordinate class represents a point in 3D space with x, y, and z values (in meters by default). It is templated to support different numeric types (e.g., float, double) for precision or memory needs. This class provides essential geometric operations for robotics, mapping, and navigation, including:

The x, y, and z values are interpreted as meters in a local or global Cartesian frame.

Template Parameters
TNumeric type for coordinates (default: float)

Example usage:

Coordinate<float> a(1.0, 2.0, 0.5);
Coordinate<float> b(2.0, 3.0, 1.0);
float dist = a.distance(b); // Euclidean distance in meters
float bearing = a.bearing(b); // Horizontal angle in degrees
float elev = a.elevation(b); // Vertical angle in degrees
Coordinate<float> c = a.navigate(5.0, 90); // Move 5m east from a
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
float bearing(const Coordinate &other, AngleUnit unit=AngleUnit::DEG) const
Definition: Coordinate.h:88
Coordinate navigate(Distance distance, Angle bearing, Distance altDiff=0) const
Definition: Coordinate.h:105

This class is suitable for use in path planning, SLAM, mapping, sensor fusion, and any application requiring 2D or 3D spatial representation and geometric calculations.

Member Function Documentation

◆ altitudeDifference()

DistanceM altitudeDifference ( const Coordinate< T > &  other) const
inline

Calculate the altitude difference in meters between this coordinate and another

◆ bearing()

float bearing ( const Coordinate< T > &  other,
AngleUnit  unit = AngleUnit::DEG 
) const
inline

Calculate the horizontal bearing (heading) in degrees from this coordinate to another

◆ distance()

DistanceM distance ( const Coordinate< T > &  other,
DistanceUnit  unit = DistanceUnit::M 
) const
inline

Calculate the Euclidean distance to another coordinate, with optional unit conversion

◆ equals()

bool equals ( const Coordinate< T > &  other,
DistanceM  limit 
) const
inline

Check if this coordinate is within a certain distance of another coordinate

◆ equalsWithAltitude()

bool equalsWithAltitude ( const Coordinate< T > &  other,
DistanceM  limit,
DistanceM  altLimit 
) const
inline

Compare two GPS coordinates for proximity within specified distance and altitude limits

◆ fromString()

bool fromString ( const std::string &  str)
inlinevirtual

Parse coordinate from string representation.

Implements Serializable.

◆ interpolateTo()

std::vector< Coordinate< T > > interpolateTo ( const Coordinate< T > &  target,
resolution 
)
inline

Interpolate points between source and target with a defined resolution.

Parameters
sourceThe starting coordinate.
targetThe ending coordinate.
resolutionThe distance between interpolated points.
Returns
std::vector<Coordinate<T>> List of interpolated coordinates (including source and target).

◆ navigate() [1/2]

Coordinate navigate ( Distance  distance,
Angle  bearing,
Distance  altDiff = 0 
) const
inline

Navigate to a new coordinate given a distance, heading, and optional altitude change

◆ navigate() [2/2]

Coordinate navigate ( DistanceM  distanceM,
float  headingDegrees,
float  altDiffM = 0 
) const
inline

Navigate to a new coordinate given a distance, heading, and optional altitude change

◆ operator+()

Coordinate operator+ ( const Coordinate< T > &  other) const
inline

Calculate new Coordinate by adding offset defined in other to current coordinate

◆ toString()

std::string toString ( ) const
inlinevirtual

Convert coordinate to string representation.

Implements Serializable.


The documentation for this class was generated from the following file: