wfmath  1.0.3
A math library for the Worldforge system.
WFMath::Point< dim > Class Template Reference

A dim dimensional point. More...

#include <point.h>

Public Member Functions

 Point ()
 Construct an uninitialized point. More...
 
 Point (const Point &)=default
 Construct a copy of a point. More...
 
 Point (const AtlasInType &a)
 Construct a point from an object passed by Atlas. More...
 
 Point (const Vector< dim > &vector)
 Construct a point from a vector. More...
 
AtlasOutType toAtlas () const
 Create an Atlas object from the point. More...
 
void fromAtlas (const AtlasInType &a)
 Set the point's value to that given by an Atlas object. More...
 
Pointoperator= (const Point &rhs)=default
 
bool isEqualTo (const Point &p, CoordType epsilon=numeric_constants< CoordType >::epsilon()) const
 
bool operator== (const Point &rhs) const
 
bool operator!= (const Point &rhs) const
 
bool isValid () const
 
void setValid (bool valid=true)
 make isValid() return true if you've initialized the point by hand More...
 
PointsetToOrigin ()
 Set point to (0,0,...,0) More...
 
Pointrotate (const RotMatrix< dim > &m, const Point &p)
 Rotate about point p. More...
 
size_t numCorners () const
 
Point< dim > getCorner (size_t) const
 
Point< dim > getCenter () const
 
Point shift (const Vector< dim > &v)
 
Point moveCornerTo (const Point &p, size_t)
 
Point moveCenterTo (const Point &p)
 
PointrotateCorner (const RotMatrix< dim > &, size_t)
 
PointrotateCenter (const RotMatrix< dim > &)
 
PointrotatePoint (const RotMatrix< dim > &m, const Point &p)
 
Pointrotate (const Quaternion &q, const Point &p)
 
PointrotateCorner (const Quaternion &, size_t)
 
PointrotateCenter (const Quaternion &)
 
PointrotatePoint (const Quaternion &q, const Point &p)
 
AxisBox< dim > boundingBox () const
 
Ball< dim > boundingSphere () const
 
Ball< dim > boundingSphereSloppy () const
 
Point toParentCoords (const Point &origin, const RotMatrix< dim > &rotation=RotMatrix< dim >().identity()) const
 
Point toParentCoords (const AxisBox< dim > &coords) const
 
Point toParentCoords (const RotBox< dim > &coords) const
 
Point toLocalCoords (const Point &origin, const RotMatrix< dim > &rotation=RotMatrix< dim >().identity()) const
 
Point toLocalCoords (const AxisBox< dim > &coords) const
 
Point toLocalCoords (const RotBox< dim > &coords) const
 
Point toParentCoords (const Point &origin, const Quaternion &rotation) const
 
Point toLocalCoords (const Point &origin, const Quaternion &rotation) const
 
CoordType operator[] (const int i) const
 Access the i'th coordinate of the point. More...
 
CoordTypeoperator[] (const int i)
 Access the i'th coordinate of the point. More...
 
 Point (CoordType x, CoordType y)
 2D only: construct a point from its (x, y) coordinates More...
 
 Point (CoordType x, CoordType y, CoordType z)
 3D only: construct a point from its (x, y, z) coordinates More...
 
CoordType x () const
 access the first component of a point More...
 
CoordTypex ()
 access the first component of a point More...
 
CoordType y () const
 access the second component of a point More...
 
CoordTypey ()
 access the second component of a point More...
 
CoordType z () const
 access the third component of a point More...
 
CoordTypez ()
 access the third component of a point More...
 
Pointpolar (CoordType r, CoordType theta)
 2D only: construct a vector from polar coordinates More...
 
void asPolar (CoordType &r, CoordType &theta) const
 2D only: convert a vector to polar coordinates More...
 
Pointpolar (CoordType r, CoordType theta, CoordType z)
 3D only: construct a vector from polar coordinates More...
 
void asPolar (CoordType &r, CoordType &theta, CoordType &z) const
 3D only: convert a vector to polar coordinates More...
 
Pointspherical (CoordType r, CoordType theta, CoordType phi)
 3D only: construct a vector from spherical coordinates More...
 
void asSpherical (CoordType &r, CoordType &theta, CoordType &phi) const
 3D only: convert a vector to spherical coordinates More...
 
const CoordTypeelements () const
 
template<>
Point< 2 > & polar (CoordType r, CoordType theta)
 
template<>
void asPolar (CoordType &r, CoordType &theta) const
 
template<>
Point< 3 > & polar (CoordType r, CoordType theta, CoordType z)
 
template<>
void asPolar (CoordType &r, CoordType &theta, CoordType &z) const
 
template<>
Point< 3 > & spherical (CoordType r, CoordType theta, CoordType phi)
 
template<>
void asSpherical (CoordType &r, CoordType &theta, CoordType &phi) const
 
template<>
Point< 3 > & rotate (const Quaternion &q, const Point< 3 > &p)
 
template<>
Point< 3 > & rotatePoint (const Quaternion &q, const Point< 3 > &p)
 
template<>
Point< 3 > toLocalCoords (const Point< 3 > &origin, const Quaternion &rotation) const
 
template<>
Point< 3 > toParentCoords (const Point< 3 > &origin, const Quaternion &rotation) const
 
template<>
CoordType z () const
 
template<>
CoordTypez ()
 
template<>
 Point (CoordType x, CoordType y)
 
template<>
 Point (CoordType x, CoordType y, CoordType z)
 
template<>
Point< 2 > & polar (CoordType r, CoordType theta)
 
template<>
void asPolar (CoordType &r, CoordType &theta) const
 
template<>
Point< 3 > & polar (CoordType r, CoordType theta, CoordType z)
 
template<>
void asPolar (CoordType &r, CoordType &theta, CoordType &z) const
 
template<>
Point< 3 > & spherical (CoordType r, CoordType theta, CoordType phi)
 
template<>
void asSpherical (CoordType &r, CoordType &theta, CoordType &phi) const
 

Static Public Member Functions

static const Point< dim > & ZERO ()
 Provides a global instance preset to zero. More...
 

Friends

class ZeroPrimitive< Point< dim > >
 
std::ostream & operator (std::ostream &os, const Point &p)
 
std::istream & operator>> (std::istream &is, Point &p)
 
Vector< dim > operator- (const Point &c1, const Point &c2)
 
Point operator+ (const Point &c, const Vector< dim > &v)
 
Point operator- (const Point &c, const Vector< dim > &v)
 
Point operator+ (const Vector< dim > &v, const Point &c)
 
Pointoperator+= (Point &p, const Vector< dim > &rhs)
 
Pointoperator-= (Point &p, const Vector< dim > &rhs)
 
CoordType SquaredDistance (const Point &p1, const Point &p2)
 Get the square of the distance from p1 to p2. More...
 
Point< dim > Midpoint (const Point &p1, const Point &p2, CoordType dist)
 Find a point on the line containing p1 and p2, by default the midpoint. More...
 

Detailed Description

template<int dim = 3>
class WFMath::Point< dim >

A dim dimensional point.

This class implements the full shape interface, as described in the fake class Shape.

Definition at line 50 of file const.h.

Constructor & Destructor Documentation

◆ Point() [1/6]

template<int dim = 3>
WFMath::Point< dim >::Point ( )
inline

Construct an uninitialized point.

Definition at line 100 of file point.h.

Referenced by WFMath::Point< 2 >::operator[](), WFMath::Point< 2 >::Point(), and WFMath::Point< 2 >::rotate().

◆ Point() [2/6]

template<int dim = 3>
WFMath::Point< dim >::Point ( const Point< dim > &  )
default

Construct a copy of a point.

◆ Point() [3/6]

template<int dim>
WFMath::Point< dim >::Point ( const AtlasInType a)
inlineexplicit

Construct a point from an object passed by Atlas.

Definition at line 184 of file atlasconv.h.

◆ Point() [4/6]

template<int dim>
WFMath::Point< dim >::Point ( const Vector< dim > &  vector)
inlineexplicit

Construct a point from a vector.

Definition at line 40 of file point_funcs.h.

◆ Point() [5/6]

template<int dim = 3>
WFMath::Point< dim >::Point ( CoordType  x,
CoordType  y 
)

2D only: construct a point from its (x, y) coordinates

◆ Point() [6/6]

template<int dim = 3>
WFMath::Point< dim >::Point ( CoordType  x,
CoordType  y,
CoordType  z 
)

3D only: construct a point from its (x, y, z) coordinates

Member Function Documentation

◆ asPolar() [1/2]

template<int dim = 3>
void WFMath::Point< dim >::asPolar ( CoordType r,
CoordType theta 
) const

2D only: convert a vector to polar coordinates

Referenced by WFMath::Point< 2 >::y().

◆ asPolar() [2/2]

template<int dim = 3>
void WFMath::Point< dim >::asPolar ( CoordType r,
CoordType theta,
CoordType z 
) const

3D only: convert a vector to polar coordinates

◆ asSpherical()

template<int dim = 3>
void WFMath::Point< dim >::asSpherical ( CoordType r,
CoordType theta,
CoordType phi 
) const

3D only: convert a vector to spherical coordinates

Referenced by WFMath::Point< 2 >::y().

◆ fromAtlas()

template<int dim>
void WFMath::Point< dim >::fromAtlas ( const AtlasInType a)
inline

Set the point's value to that given by an Atlas object.

Definition at line 190 of file atlasconv.h.

Referenced by WFMath::RotBox< dim >::fromAtlas(), and WFMath::Point< 2 >::Point().

◆ operator[]() [1/2]

template<int dim = 3>
CoordType WFMath::Point< dim >::operator[] ( const int  i) const
inline

Access the i'th coordinate of the point.

Definition at line 201 of file point.h.

◆ operator[]() [2/2]

template<int dim = 3>
CoordType& WFMath::Point< dim >::operator[] ( const int  i)
inline

Access the i'th coordinate of the point.

Definition at line 203 of file point.h.

◆ polar() [1/2]

template<int dim = 3>
Point& WFMath::Point< dim >::polar ( CoordType  r,
CoordType  theta 
)

2D only: construct a vector from polar coordinates

Referenced by WFMath::Point< 2 >::y().

◆ polar() [2/2]

template<int dim = 3>
Point& WFMath::Point< dim >::polar ( CoordType  r,
CoordType  theta,
CoordType  z 
)

3D only: construct a vector from polar coordinates

◆ rotate()

template<int dim = 3>
Point& WFMath::Point< dim >::rotate ( const RotMatrix< dim > &  m,
const Point< dim > &  p 
)
inline

Rotate about point p.

Definition at line 146 of file point.h.

Referenced by WFMath::Point< 2 >::rotate().

◆ setToOrigin()

template<int dim>
Point< dim > & WFMath::Point< dim >::setToOrigin ( )
inline

Set point to (0,0,...,0)

Definition at line 56 of file point_funcs.h.

Referenced by WFMath::BoundingBox(), and WFMath::Point< 2 >::setValid().

◆ setValid()

template<int dim = 3>
void WFMath::Point< dim >::setValid ( bool  valid = true)
inline

make isValid() return true if you've initialized the point by hand

Definition at line 129 of file point.h.

Referenced by WFMath::Barycenter(), WFMath::BoundingSphere(), WFMath::BoundingSphereSloppy(), and WFMath::AxisBox< dim >::setCorners().

◆ spherical()

template<int dim = 3>
Point& WFMath::Point< dim >::spherical ( CoordType  r,
CoordType  theta,
CoordType  phi 
)

3D only: construct a vector from spherical coordinates

Referenced by WFMath::Point< 2 >::y().

◆ toAtlas()

template<int dim>
AtlasOutType WFMath::Point< dim >::toAtlas ( ) const
inline

Create an Atlas object from the point.

Definition at line 203 of file atlasconv.h.

Referenced by WFMath::Point< 2 >::Point().

◆ x() [1/2]

template<int dim = 3>
CoordType WFMath::Point< dim >::x ( ) const
inline

access the first component of a point

Definition at line 232 of file point.h.

Referenced by WFMath::Ball< dim >::Ball(), and WFMath::Point< 2 >::operator[]().

◆ x() [2/2]

template<int dim = 3>
CoordType& WFMath::Point< dim >::x ( )
inline

access the first component of a point

Definition at line 234 of file point.h.

◆ y() [1/2]

template<int dim = 3>
CoordType WFMath::Point< dim >::y ( ) const
inline

access the second component of a point

Definition at line 236 of file point.h.

Referenced by WFMath::Ball< dim >::Ball(), and WFMath::Point< 2 >::operator[]().

◆ y() [2/2]

template<int dim = 3>
CoordType& WFMath::Point< dim >::y ( )
inline

access the second component of a point

Definition at line 238 of file point.h.

◆ z() [1/2]

template<int dim = 3>
CoordType WFMath::Point< dim >::z ( ) const

access the third component of a point

Referenced by WFMath::Ball< dim >::Ball(), WFMath::Point< 2 >::operator[](), and WFMath::Point< 2 >::y().

◆ z() [2/2]

template<int dim = 3>
CoordType& WFMath::Point< dim >::z ( )

access the third component of a point

◆ ZERO()

template<int dim>
const Point< dim > & WFMath::Point< dim >::ZERO ( )
static

Provides a global instance preset to zero.

Definition at line 48 of file point_funcs.h.

Referenced by WFMath::Point< 2 >::Point().

Friends And Related Function Documentation

◆ Midpoint

template<int dim = 3>
Point<dim> Midpoint ( const Point< dim > &  p1,
const Point< dim > &  p2,
CoordType  dist = 0.5 
)
friend

Find a point on the line containing p1 and p2, by default the midpoint.

The default value of 0.5 for dist gives the midpoint. A value of 0 gives p1, and 1 gives p2. Values of dist outside the [0, 1] range are allowed, and give points on the line which are not on the segment bounded by p1 and p2.

Definition at line 219 of file point_funcs.h.

◆ SquaredDistance

template<int dim = 3>
CoordType SquaredDistance ( const Point< dim > &  p1,
const Point< dim > &  p2 
)
friend

Get the square of the distance from p1 to p2.

Definition at line 124 of file point_funcs.h.


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