LibreCAD
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lc::geo::Coordinate Class Reference

#include <geocoordinate.h>

Inheritance diagram for lc::geo::Coordinate:

Public Member Functions

 Coordinate ()
 
 Coordinate (double x, double y, double z)
 
 Coordinate (double x, double y)
 
 Coordinate (double angle)
 
 Coordinate (Coordinate &&c) noexcept
 
 Coordinate (const Coordinate &c)
 
double x () const
 Returns x of Coordinate. More...
 
double y () const
 Returns y of Coordinate. More...
 
double z () const
 Returns z of Coordinate. More...
 
Coordinateoperator= (const Coordinate &coord)
 
Coordinate flipXY () const
 flips the x and y of Coordinate More...
 
double angleTo (const Coordinate &v) const
 Returns angle To the coordinate. More...
 
double angleBetween (const Coordinate &v1, const Coordinate &v2) const
 
bool operator== (const Coordinate &coord) const
 checks for the equality of Coordinate More...
 
bool operator!= (const Coordinate &coord) const
 
double distanceTo (const geo::Coordinate &c) const
 
Coordinate operator+ (const Coordinate &coord) const
 
Coordinate operator+ (double d) const
 operator + for offset addition More...
 
Coordinate operator- (double d) const
 operator + for offset addition More...
 
Coordinate operator- () const
 operator - More...
 
Coordinate operator- (const Coordinate &coord) const
 
Coordinate operator* (const Coordinate &coord) const
 
Coordinate operator* (double s) const
 
Coordinate operator/ (double s) const
 
double magnitude () const
 
double angle () const
 
double squared () const
 
double dot (const Coordinate &coord) const
 
double dot (const Coordinate &v1, const Coordinate &v2) const
 
Coordinate rotate (const Coordinate &angleVector) const
 rotate around (0.,0.) with a given angle vector More...
 
Coordinate rotate (const double &angle) const
 rotate around (0.,0.) with a given angle More...
 
Coordinate rotate (const geo::Coordinate &point, const Coordinate &angleVector) const
 rotate around a point with a angle vector More...
 
Coordinate rotate (const geo::Coordinate &point, const double &angle) const
 rotate around a point with a angle More...
 
Coordinate rotateByArcLength (const geo::Coordinate &point, double const length) const
 rotate around a point where the rotation described length is known Example More...
 
Coordinate scale (const double &scale_factor) const
 
Coordinate scale (const Coordinate &scale_factor) const
 
Coordinate scale (const Coordinate &scale_center, const Coordinate &scale_factor) const
 
Coordinate mid (const Coordinate &other) const
 
Coordinate norm () const
 
Coordinate norm (const double f) const
 
Coordinate move (const Coordinate &direction, double d) const
 
Coordinate moveTo (const Coordinate &to, double d) const
 
Coordinate transform2d (double xx, double yx, double xy, double yy, double x0, double y0)
 
Coordinate mirror (const Coordinate &axis1, const Coordinate &axis2) const
 mirror a coordinate More...
 

Private Attributes

double _x
 
double _y
 
double _z
 

Friends

std::ostream & operator<< (std::ostream &os, const Coordinate &coordinate)
 

Detailed Description

Class that represents a coordinate in space

Definition at line 12 of file geocoordinate.h.

Constructor & Destructor Documentation

lc::geo::Coordinate::Coordinate ( )
inlineexplicit

Definition at line 14 of file geocoordinate.h.

14 : _x(0.), _y(0.), _z(0.) {}
lc::geo::Coordinate::Coordinate ( double  x,
double  y,
double  z 
)
inline

Definition at line 15 of file geocoordinate.h.

15 : _x(x), _y(y), _z(z) {}
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
double z() const
Returns z of Coordinate.
Definition: geocoordinate.h:42
lc::geo::Coordinate::Coordinate ( double  x,
double  y 
)
inline

Definition at line 16 of file geocoordinate.h.

16 : _x(x), _y(y), _z(0.) {}
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
lc::geo::Coordinate::Coordinate ( double  angle)
inlineexplicit

Definition at line 17 of file geocoordinate.h.

17 : _x(std::cos(angle)), _y(std::sin(angle)), _z(0.) {}
double angle() const
lc::geo::Coordinate::Coordinate ( Coordinate &&  c)
inlinenoexcept

Definition at line 18 of file geocoordinate.h.

18 : _x(c._x), _y(c._y), _z(c._z) {}
lc::geo::Coordinate::Coordinate ( const Coordinate c)
inline

Definition at line 19 of file geocoordinate.h.

19 : _x(c._x), _y(c._y), _z(c._z) {}

Member Function Documentation

double lc::geo::Coordinate::angle ( ) const
inline

Definition at line 183 of file geocoordinate.h.

183  {
184  return std::atan2(_y, _x);
185  }
double Coordinate::angleBetween ( const Coordinate v1,
const Coordinate v2 
) const
Returns
The angle from between two vectors using the current vector as the center return 0, if the angle is not well defined

Definition at line 7 of file geocoordinate.cpp.

7  {
8  Coordinate vStart(v1 - (*this));
9  Coordinate vEnd(v2 - (*this));
10  return atan2(vStart.x() * vEnd.y() - vStart.y() * vEnd.x(), vStart.x() * vEnd.x() + vStart.y() * vEnd.y());
11 }
double lc::geo::Coordinate::angleTo ( const Coordinate v) const
inline

Returns angle To the coordinate.

Parameters
geo::Coordinatev
Returns
double angle

Definition at line 77 of file geocoordinate.h.

77  {
78  return (v - (*this)).angle();
79  }
double lc::geo::Coordinate::distanceTo ( const geo::Coordinate c) const
inline

Calculate the distance between this coordinate and another coordinate

Returns
double

Definition at line 104 of file geocoordinate.h.

104  {
105  return (*this - c).magnitude();
106  }
double lc::geo::Coordinate::dot ( const Coordinate coord) const
inline

Dot product with other coordindate : return _x * coord._x + _y * coord._y + _z * coord._z;

Parameters
Coordinate
Returns
double Dot product value

Definition at line 203 of file geocoordinate.h.

203  {
204  return _x * coord._x + _y * coord._y + _z * coord._z;
205  }
double lc::geo::Coordinate::dot ( const Coordinate v1,
const Coordinate v2 
) const
inline

Definition at line 207 of file geocoordinate.h.

207  {
208  return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
209  }
Coordinate lc::geo::Coordinate::flipXY ( ) const
inline

flips the x and y of Coordinate

Returns
geo::Coordinate coordinate

Definition at line 68 of file geocoordinate.h.

68  {
69  return Coordinate(this->y(), this->x(), this->z());
70  }
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
double z() const
Returns z of Coordinate.
Definition: geocoordinate.h:42
double lc::geo::Coordinate::magnitude ( ) const
inline

Magnitude or length of the point relative to zero : return sqrtf(_x * _x + _y * _y + _z * _z)

Returns
double Length of the vector

Definition at line 179 of file geocoordinate.h.

179  {
180  return std::sqrt(_x * _x + _y * _y + _z * _z);
181  }
Coordinate lc::geo::Coordinate::mid ( const Coordinate other) const
inline

Midpoint between two coordinates

Definition at line 292 of file geocoordinate.h.

292  {
293  return (other - *this) / 2. + *this;
294  }
Coordinate lc::geo::Coordinate::mirror ( const Coordinate axis1,
const Coordinate axis2 
) const
inline

mirror a coordinate

Parameters
axis1: First point of line to be mirrored about
axis2: Second point of line to be mirrored about
Returns
mirrored coordinate

Definition at line 342 of file geocoordinate.h.

342  {
343  Coordinate dir(axis2 - axis1);
344  auto a= dir.squared();
345  auto ret= axis1 + dir* dot(*this- axis1, dir)/a; //projection point
346  return ret + ret - *this;
347  }
double dot(const Coordinate &coord) const
Coordinate lc::geo::Coordinate::move ( const Coordinate direction,
double  d 
) const
inline

move the coordinate by distance d over vector direction

Definition at line 315 of file geocoordinate.h.

315  {
316  return direction.norm() * d + *this;
317  }
Coordinate lc::geo::Coordinate::moveTo ( const Coordinate to,
double  d 
) const
inline

Move the coordinate in the direction of point 'to' with distance d

Definition at line 322 of file geocoordinate.h.

322  {
323  return (to - *this).norm() * d + *this;
324  }
Coordinate lc::geo::Coordinate::norm ( ) const
inline

Normalised version of this coordinate

Definition at line 298 of file geocoordinate.h.

298  {
299  auto m = magnitude();
300  return Coordinate(_x / m, _y / m, _z / m);
301  }
double magnitude() const
Coordinate lc::geo::Coordinate::norm ( const double  f) const
inline

Normalised version of this coordinate with a factor The final Coordinate has a length of f

Definition at line 307 of file geocoordinate.h.

307  {
308  auto m = magnitude() / f;
309  return Coordinate(_x / m, _y / m, _z / m);
310  }
double magnitude() const
bool lc::geo::Coordinate::operator!= ( const Coordinate coord) const
inline

Definition at line 96 of file geocoordinate.h.

96  {
97  return this->_x != coord._x || this->_y != coord._y || this->_z != coord._z;
98  }
Coordinate lc::geo::Coordinate::operator* ( const Coordinate coord) const
inline

Multiplication by Coordinate : return Coordinate(_x * s, _y * s, _z * s)

Parameters
Coordinate
Returns
Coordinate

Definition at line 157 of file geocoordinate.h.

157  {
158  return Coordinate(_x * coord._x, _y * coord._y, _z * coord._z);
159  }
Coordinate lc::geo::Coordinate::operator* ( double  s) const
inline

Definition at line 161 of file geocoordinate.h.

161  {
162  return Coordinate(_x * s, _y * s, _z * s);
163  }
Coordinate lc::geo::Coordinate::operator+ ( const Coordinate coord) const
inline

Add two points to each other and return a new coordinate : return Coordinate(_x + coord._x, _y + coord._y, _z + coord._z);

Returns
Coordinate Addition of two vectors

Definition at line 112 of file geocoordinate.h.

112  {
113  return Coordinate(_x + coord._x, _y + coord._y, _z + coord._z);
114  }
Coordinate lc::geo::Coordinate::operator+ ( double  d) const
inline

operator + for offset addition

Parameters
doubleoffset
Returns
geo::Coordinate

Definition at line 121 of file geocoordinate.h.

121  {
122  return Coordinate(_x + d, _y + d, _z + d);
123  }
Coordinate lc::geo::Coordinate::operator- ( double  d) const
inline

operator + for offset addition

Parameters
doubleoffset
Returns
geo::Coordinate

Definition at line 130 of file geocoordinate.h.

130  {
131  return Coordinate(_x - d, _y - d, _z - d);
132  }
Coordinate lc::geo::Coordinate::operator- ( ) const
inline

operator -

Parameters
return geo::Coordinate

Definition at line 139 of file geocoordinate.h.

139  {
140  return Coordinate(-_x, -_y, -_z);
141  }
Coordinate lc::geo::Coordinate::operator- ( const Coordinate coord) const
inline

Substract two points from each other and return a new coordinate : return _x - coord._x, _y - coord._y, _z - coord._z returns Coordinate

Definition at line 147 of file geocoordinate.h.

147  {
148  return Coordinate(_x - coord._x, _y - coord._y, _z - coord._z);
149  }
Coordinate lc::geo::Coordinate::operator/ ( double  s) const
inline

Division by double : return Coordinate(_x / s, _y / s, _z / s)

Parameters
double
Returns
Coordinate

Definition at line 170 of file geocoordinate.h.

170  {
171  return Coordinate(_x / s, _y / s, _z / s);
172  }
Coordinate& lc::geo::Coordinate::operator= ( const Coordinate coord)
inline

Definition at line 47 of file geocoordinate.h.

47  {
48  if (this != &coord) {
49  _x = coord._x;
50  _y = coord._y;
51  _z = coord._z;
52  }
53 
54  return *this;
55  }
bool lc::geo::Coordinate::operator== ( const Coordinate coord) const
inline

checks for the equality of Coordinate

Parameters
geo::coordinate
Returns
bool equality

Definition at line 92 of file geocoordinate.h.

92  {
93  return this->_x == coord._x && this->_y == coord._y && this->_z == coord._z;
94  }
Coordinate lc::geo::Coordinate::rotate ( const Coordinate angleVector) const
inline

rotate around (0.,0.) with a given angle vector

Parameters
angleVector
Returns

Definition at line 217 of file geocoordinate.h.

217  {
218  double x0 = _x * angleVector.x() - _y * angleVector.y();
219  double y0 = _x * angleVector.y() + _y * angleVector.x();
220  return Coordinate(x0, y0);
221  }
Coordinate lc::geo::Coordinate::rotate ( const double &  angle) const
inline

rotate around (0.,0.) with a given angle

Parameters
angle
Returns

Definition at line 229 of file geocoordinate.h.

229  {
230  return rotate(Coordinate(angle));
231  }
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
double angle() const
Coordinate lc::geo::Coordinate::rotate ( const geo::Coordinate point,
const Coordinate angleVector 
) const
inline

rotate around a point with a angle vector

Parameters
point
angleVector
Returns

Definition at line 240 of file geocoordinate.h.

240  {
241  return point + (*this - point).rotate(angleVector);
242  }
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
Coordinate lc::geo::Coordinate::rotate ( const geo::Coordinate point,
const double &  angle 
) const
inline

rotate around a point with a angle

Parameters
point
angle
Returns

Definition at line 251 of file geocoordinate.h.

251  {
252  return rotate(point, Coordinate(angle));
253  }
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
double angle() const
Coordinate lc::geo::Coordinate::rotateByArcLength ( const geo::Coordinate point,
double const  length 
) const
inline

rotate around a point where the rotation described length is known Example

Parameters
point
length
Returns

Definition at line 263 of file geocoordinate.h.

263  {
264  double const angle = (length / point.distanceTo(*this));
265  return rotate(point, Coordinate(angle));
266  }
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
double angle() const
Coordinate lc::geo::Coordinate::scale ( const double &  scale_factor) const
inline

Scales the vector by given factors with 0/0 as center

Definition at line 271 of file geocoordinate.h.

271  {
272  return Coordinate(_x * scale_factor, _y * scale_factor);
273  }
Coordinate lc::geo::Coordinate::scale ( const Coordinate scale_factor) const
inline

Scales the vector by given factors with 0/0 as center

Definition at line 278 of file geocoordinate.h.

278  {
279  return Coordinate(_x * scale_factor.x(), _y * scale_factor.y());
280  }
Coordinate lc::geo::Coordinate::scale ( const Coordinate scale_center,
const Coordinate scale_factor 
) const
inline

Scales this vector by the given factors with the given center.

Definition at line 285 of file geocoordinate.h.

285  {
286  return scale_center + ((*this - scale_center) * scale_factor);
287  }
double lc::geo::Coordinate::squared ( ) const
inline

Squared of this Coordinate : return _x * _x + _y * _y + _z * _z;

Returns
double Squared value

Definition at line 193 of file geocoordinate.h.

193  {
194  return _x * _x + _y * _y + _z * _z;
195  }
Coordinate lc::geo::Coordinate::transform2d ( double  xx,
double  yx,
double  xy,
double  yy,
double  x0,
double  y0 
)
inline

Apply transformation matrix to coordinates in X/Y only Note: this is a very naive approach to transform if we see ourselves using this function on large vectors of coordinates we should consider using Eigen

Definition at line 332 of file geocoordinate.h.

332  {
333  return Coordinate(xx * _x + xy * _y + x0, yx * _x + yy * _y + y0, _z);
334  }
double lc::geo::Coordinate::x ( ) const
inline

Returns x of Coordinate.

Returns
double x

Definition at line 26 of file geocoordinate.h.

26  {
27  return _x;
28  }
double lc::geo::Coordinate::y ( ) const
inline

Returns y of Coordinate.

Returns
double y

Definition at line 34 of file geocoordinate.h.

34  {
35  return _y;
36  }
double lc::geo::Coordinate::z ( ) const
inline

Returns z of Coordinate.

Returns
double z

Definition at line 42 of file geocoordinate.h.

42  {
43  return _z;
44  }

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Coordinate coordinate 
)
friend

Definition at line 350 of file geocoordinate.h.

350  {
351  os << "Coordinate(x=" << coordinate._x << " y=" << coordinate._y << " z=" << coordinate._z << ")";
352  return os;
353  }

Member Data Documentation

double lc::geo::Coordinate::_x
private

Definition at line 356 of file geocoordinate.h.

double lc::geo::Coordinate::_y
private

Definition at line 357 of file geocoordinate.h.

double lc::geo::Coordinate::_z
private

Definition at line 358 of file geocoordinate.h.


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