26 #ifndef WFMATH_POINT_H 27 #define WFMATH_POINT_H 29 #include <wfmath/const.h> 39 Point<dim>& operator+=(Point<dim>& p,
const Vector<dim>& v);
41 Point<dim>& operator-=(Point<dim>& p,
const Vector<dim>& v);
44 Vector<dim> operator-(
const Point<dim>& c1,
const Point<dim>& c2);
46 Point<dim> operator+(
const Point<dim>& c,
const Vector<dim>& v);
48 Point<dim> operator+(
const Vector<dim>& v,
const Point<dim>& c);
50 Point<dim> operator-(
const Point<dim>& c,
const Vector<dim>& v);
53 CoordType SquaredDistance(
const Point<dim>& p1,
const Point<dim>& p2);
55 CoordType Distance(
const Point<dim>& p1,
const Point<dim>& p2)
56 {
return std::sqrt(SquaredDistance(p1, p2));}
58 CoordType SloppyDistance(
const Point<dim>& p1,
const Point<dim>& p2)
59 {
return (p1 - p2).sloppyMag();}
62 template<
int dim,
template<
class,
class>
class container>
63 Point<dim>
Barycenter(
const container<Point<dim>, std::allocator<Point<dim> > >& c);
71 template<
int dim,
template<
class,
class>
class container,
72 template<
class,
class>
class container2>
73 Point<dim>
Barycenter(
const container<Point<dim>, std::allocator<Point<dim> > >& c,
74 const container2<
CoordType, std::allocator<CoordType> >& weights);
78 Point<dim>
Midpoint(
const Point<dim>& p1,
const Point<dim>& p2,
82 std::ostream& operator<<(std::ostream& os, const Point<dim>& m);
84 std::istream& operator>>(std::istream& is, Point<dim>& m);
86 template<
typename Shape>
104 explicit Point (
const AtlasInType& a);
113 friend std::ostream& operator<< <dim>(std::ostream& os,
const Point& p);
114 friend std::istream&
operator>> <dim>(std::istream& is,
Point& p);
123 bool isEqualTo(
const Point &p,
CoordType epsilon = numeric_constants<CoordType>::epsilon())
const;
124 bool operator== (
const Point& rhs)
const {
return isEqualTo(rhs);}
125 bool operator!= (
const Point& rhs)
const {
return !isEqualTo(rhs);}
127 bool isValid()
const {
return m_valid;}
129 void setValid(
bool valid =
true) {m_valid = valid;}
147 {
return (*
this = p +
Prod(*
this - p, m));}
151 size_t numCorners()
const {
return 1;}
152 Point<dim> getCorner(
size_t)
const {
return *
this;}
153 Point<dim> getCenter()
const {
return *
this;}
155 Point shift(
const Vector<dim>& v) {
return *
this += v;}
157 {
return operator=(p);}
158 Point moveCenterTo(
const Point& p) {
return operator=(p);}
160 Point& rotateCorner(
const RotMatrix<dim>&,
size_t)
162 Point& rotateCenter(
const RotMatrix<dim>&) {
return *
this;}
163 Point& rotatePoint(
const RotMatrix<dim>& m,
const Point& p) {
return rotate(m, p);}
167 Point& rotateCorner(
const Quaternion&,
size_t)
169 Point& rotateCenter(
const Quaternion&) {
return *
this;}
170 Point& rotatePoint(
const Quaternion& q,
const Point& p);
174 AxisBox<dim> boundingBox()
const;
175 Ball<dim> boundingSphere()
const;
176 Ball<dim> boundingSphereSloppy()
const;
179 const RotMatrix<dim>& rotation = RotMatrix<dim>().identity())
const 180 {
return origin + (*
this -
Point().setToOrigin()) * rotation;}
181 Point toParentCoords(
const AxisBox<dim>& coords)
const;
182 Point toParentCoords(
const RotBox<dim>& coords)
const;
189 const RotMatrix<dim>& rotation = RotMatrix<dim>().identity())
const 190 {
return Point().setToOrigin() + rotation * (*
this - origin);}
191 Point toLocalCoords(
const AxisBox<dim>& coords)
const;
192 Point toLocalCoords(
const RotBox<dim>& coords)
const;
195 Point toParentCoords(
const Point& origin,
const Quaternion& rotation)
const;
196 Point toLocalCoords(
const Point& origin,
const Quaternion& rotation)
const;
258 const CoordType* elements()
const {
return m_elem;}
315 inline Point<3>::Point(CoordType x, CoordType y, CoordType z) : m_valid(true)
324 #endif // WFMATH_POINT_H Generic library namespace.
Definition: atlasconv.h:45
Point & setToOrigin()
Set point to (0,0,...,0)
Definition: point_funcs.h:64
CoordType & operator[](const int i)
Access the i'th coordinate of the point.
Definition: point.h:203
static const Point< dim > & ZERO()
Provides a global instance preset to zero.
Definition: point_funcs.h:56
Point & polar(CoordType r, CoordType theta)
2D only: construct a vector from polar coordinates
CoordType & x()
access the first component of a point
Definition: point.h:234
A dim dimensional rotation matrix. Technically, a member of the group O(dim).
Definition: const.h:53
CoordType & y()
access the second component of a point
Definition: point.h:238
CoordType z() const
access the third component of a point
Point & spherical(CoordType r, CoordType theta, CoordType phi)
3D only: construct a vector from spherical coordinates
void setValid(bool valid=true)
make isValid() return true if you've initialized the point by hand
Definition: point.h:129
CoordType operator[](const int i) const
Access the i'th coordinate of the point.
Definition: point.h:201
void fromAtlas(const AtlasInType &a)
Set the point's value to that given by an Atlas object.
Definition: atlasconv.h:172
Point< dim > Midpoint(const Point< dim > &p1, const Point< dim > &p2, CoordType dist=0.5)
Definition: point_funcs.h:240
Point & rotate(const RotMatrix< dim > &m, const Point &p)
Rotate about point p.
Definition: point.h:146
A dim dimensional vector.
Definition: const.h:55
Point()
Construct an uninitialized point.
Definition: point.h:100
float CoordType
Basic floating point type.
Definition: const.h:140
CoordType x() const
access the first component of a point
Definition: point.h:232
AtlasOutType toAtlas() const
Create an Atlas object from the point.
Definition: atlasconv.h:179
CoordType y() const
access the second component of a point
Definition: point.h:236
Utility class for providing zero primitives. This class will only work with simple structures such as...
Definition: point.h:87
void asPolar(CoordType &r, CoordType &theta) const
2D only: convert a vector to polar coordinates
RotMatrix< dim > Prod(const RotMatrix< dim > &m1, const RotMatrix< dim > &m2)
returns m1 * m2
Definition: rotmatrix_funcs.h:89
A dim dimensional point.
Definition: const.h:50
Point< dim > Barycenter(const container< Point< dim >, std::allocator< Point< dim > > > &c)
Find the center of a set of points, all weighted equally.
Definition: point_funcs.h:207
void asSpherical(CoordType &r, CoordType &theta, CoordType &phi) const
3D only: convert a vector to spherical coordinates