Public Member Functions | Private Attributes | Related Functions | List of all members
vgl_point_2d< Type > Class Template Reference

Represents a cartesian 2D point. More...

#include <vgl_area.h>

Inheritance diagram for vgl_point_2d< Type >:
Inheritance graph
[legend]

Public Member Functions

 vgl_point_2d ()=default
 Default constructor. More...
 
 vgl_point_2d (Type px, Type py)
 Construct from two Types. More...
 
 vgl_point_2d (Type const v[2])
 Construct from 2-array. More...
 
 vgl_point_2d (vgl_homg_point_2d< Type > const &p)
 Construct from homogeneous point. More...
 
 vgl_point_2d (vgl_line_2d< Type > const &l1, vgl_line_2d< Type > const &l2)
 Construct from 2 lines (intersection). More...
 
bool operator== (vgl_point_2d< Type >const &p) const
 Test for equality. More...
 
bool operator!= (vgl_point_2d< Type >const &p) const
 
Type & x ()
 
Type & y ()
 
Type x () const
 
Type y () const
 
void set (Type px, Type py)
 Set x and y. More...
 
void set (Type const p[2])
 Set x and y. More...
 
bool ideal (Type=(Type) 0) const
 Return true iff the point is at infinity (an ideal point). More...
 
std::istream & read (std::istream &is)
 Read from stream, possibly with formatting. More...
 

Private Attributes

Type x_
 
Type y_
 

Related Functions

(Note that these are not member functions.)

template<class T >
vgl_point_2d< T > vgl_closest_point_origin (vgl_line_2d< T > const &l)
 Return the point on the given line closest to the origin. More...
 
template<class T >
double vgl_distance (vgl_point_2d< T >const &p1, vgl_point_2d< T >const &p2)
 return the distance between two points. More...
 
template<class T >
bool vgl_intersection (vgl_point_2d< T > const &p0, vgl_point_2d< T > const &p1)
 Return true if the two points intersect, i.e., coincide. More...
 
template<class T >
bool vgl_intersection (vgl_point_3d< T > const &p0, vgl_point_3d< T > const &p1)
 Return true if the two points intersect, i.e., coincide. More...
 
template<class T >
bool vgl_intersection (vgl_point_2d< T > const &p1, vgl_point_2d< T > const &p2, vgl_point_2d< T > const &q1, vgl_point_2d< T > const &q2, double tol=1e-6)
 Return true if any point on [p1,p2] is within tol of [q1,q2]. More...
 
template<class T >
std::vector< vgl_point_2d< T > > vgl_intersection (vgl_polygon< T > const &poly, vgl_line_2d< T > const &line)
 Find the intersections of a line with a polygon( can have multiple sheets). More...
 
template<class Type >
std::ostream & operator<< (std::ostream &s, vgl_point_2d< Type > const &p)
 Write "<vgl_point_2d x,y>" to stream. More...
 
template<class Type >
std::istream & operator>> (std::istream &s, vgl_point_2d< Type > &p)
 Read from stream, possibly with formatting. More...
 
template<class Type >
vgl_vector_2d< Type > operator- (vgl_point_2d< Type > const &p1, vgl_point_2d< Type > const &p2)
 The difference of two points is the vector from second to first point. More...
 
template<class Type >
vgl_point_2d< Type > operator+ (vgl_point_2d< Type > const &p, vgl_vector_2d< Type > const &v)
 Adding a vector to a point gives a new point at the end of that vector. More...
 
template<class Type >
vgl_point_2d< Type > & operator+= (vgl_point_2d< Type > &p, vgl_vector_2d< Type > const &v)
 Adding a vector to a point gives the point at the end of that vector. More...
 
template<class Type >
vgl_point_2d< Type > operator- (vgl_point_2d< Type > const &p, vgl_vector_2d< Type > const &v)
 Subtracting a vector from a point is the same as adding the inverse vector. More...
 
template<class Type >
vgl_point_2d< Type > & operator-= (vgl_point_2d< Type > &p, vgl_vector_2d< Type > const &v)
 Subtracting a vector from a point is the same as adding the inverse vector. More...
 
template<class T >
double cross_ratio (vgl_point_2d< T >const &p1, vgl_point_2d< T >const &p2, vgl_point_2d< T >const &p3, vgl_point_2d< T >const &p4)
 cross ratio of four collinear points. More...
 
template<class Type >
bool collinear (vgl_point_2d< Type > const &p1, vgl_point_2d< Type > const &p2, vgl_point_2d< Type > const &p3)
 Are three points collinear, i.e., do they lie on a common line?. More...
 
template<class Type >
double ratio (vgl_point_2d< Type > const &p1, vgl_point_2d< Type > const &p2, vgl_point_2d< Type > const &p3)
 Return the relative distance to p1 wrt p1-p2 of p3. More...
 
template<class Type >
vgl_point_2d< Type > midpoint (vgl_point_2d< Type > const &p1, vgl_point_2d< Type > const &p2, Type f=(Type) 0.5)
 Return the point at a given ratio wrt two other points. More...
 
template<class Type >
vgl_point_2d< Type > centre (vgl_point_2d< Type > const &p1, vgl_point_2d< Type > const &p2)
 Return the point at the centre of gravity of two given points. More...
 
template<class Type >
vgl_point_2d< Type > centre (vgl_point_2d< Type > const &p1, vgl_point_2d< Type > const &p2, vgl_point_2d< Type > const &p3)
 Return the point at the centre of gravity of three given points. More...
 
template<class Type >
vgl_point_2d< Type > centre (vgl_point_2d< Type > const &p1, vgl_point_2d< Type > const &p2, vgl_point_2d< Type > const &p3, vgl_point_2d< Type > const &p4)
 Return the point at the centre of gravity of four given points. More...
 
template<class Type >
vgl_point_2d< Type > centre (std::vector< vgl_point_2d< Type > > const &v)
 Return the point at the centre of gravity of a set of given points. More...
 

Detailed Description

template<class Type>
class vgl_point_2d< Type >

Represents a cartesian 2D point.

Definition at line 7 of file vgl_area.h.

Constructor & Destructor Documentation

◆ vgl_point_2d() [1/5]

template<class Type>
vgl_point_2d< Type >::vgl_point_2d ( )
inlinedefault

Default constructor.

◆ vgl_point_2d() [2/5]

template<class Type>
vgl_point_2d< Type >::vgl_point_2d ( Type  px,
Type  py 
)
inline

Construct from two Types.

Definition at line 41 of file vgl_point_2d.h.

◆ vgl_point_2d() [3/5]

template<class Type>
vgl_point_2d< Type >::vgl_point_2d ( Type const  v[2])
inline

Construct from 2-array.

Definition at line 44 of file vgl_point_2d.h.

◆ vgl_point_2d() [4/5]

template<class Type>
vgl_point_2d< Type >::vgl_point_2d ( vgl_homg_point_2d< Type > const &  p)

Construct from homogeneous point.

Definition at line 21 of file vgl_point_2d.hxx.

◆ vgl_point_2d() [5/5]

template<class Type>
vgl_point_2d< Type >::vgl_point_2d ( vgl_line_2d< Type > const &  l1,
vgl_line_2d< Type > const &  l2 
)

Construct from 2 lines (intersection).

Definition at line 28 of file vgl_point_2d.hxx.

Member Function Documentation

◆ ideal()

template<class Type>
bool vgl_point_2d< Type >::ideal ( Type  = (Type)0) const
inline

Return true iff the point is at infinity (an ideal point).

Always returns false.

Definition at line 86 of file vgl_point_2d.h.

◆ operator!=()

template<class Type>
bool vgl_point_2d< Type >::operator!= ( vgl_point_2d< Type >const &  p) const
inline

Definition at line 66 of file vgl_point_2d.h.

◆ operator==()

template<class Type>
bool vgl_point_2d< Type >::operator== ( vgl_point_2d< Type >const &  p) const
inline

Test for equality.

Definition at line 64 of file vgl_point_2d.h.

◆ read()

template<class Type >
std::istream & vgl_point_2d< Type >::read ( std::istream &  is)

Read from stream, possibly with formatting.

Either just reads two blank-separated numbers, or reads two comma-separated numbers, or reads two numbers in parenthesized form "(123, 321)"

Either just reads two blank-separated numbers, or reads two comma-separated numbers, or reads two numbers in parenthesized form "(123, 321)" or reads form written by <<, "<vgl_point_2d 123, 321 >"

Definition at line 63 of file vgl_point_2d.hxx.

◆ set() [1/2]

template<class Type>
void vgl_point_2d< Type >::set ( Type  px,
Type  py 
)
inline

Set x and y.

Note that x and y can also be set individually.

Definition at line 79 of file vgl_point_2d.h.

◆ set() [2/2]

template<class Type>
void vgl_point_2d< Type >::set ( Type const  p[2])
inline

Set x and y.

Note that x and y can also be set individually.

Definition at line 82 of file vgl_point_2d.h.

◆ x() [1/2]

template<class Type>
Type& vgl_point_2d< Type >::x ( )
inline

Definition at line 71 of file vgl_point_2d.h.

◆ x() [2/2]

template<class Type>
Type vgl_point_2d< Type >::x ( ) const
inline

Definition at line 74 of file vgl_point_2d.h.

◆ y() [1/2]

template<class Type>
Type& vgl_point_2d< Type >::y ( )
inline

Definition at line 72 of file vgl_point_2d.h.

◆ y() [2/2]

template<class Type>
Type vgl_point_2d< Type >::y ( ) const
inline

Definition at line 75 of file vgl_point_2d.h.

Friends And Related Function Documentation

◆ centre() [1/4]

template<class Type >
vgl_point_2d< Type > centre ( vgl_point_2d< Type > const &  p1,
vgl_point_2d< Type > const &  p2 
)
related

Return the point at the centre of gravity of two given points.

Identical to midpoint(p1,p2).

Definition at line 219 of file vgl_point_2d.h.

◆ centre() [2/4]

template<class Type >
vgl_point_2d< Type > centre ( vgl_point_2d< Type > const &  p1,
vgl_point_2d< Type > const &  p2,
vgl_point_2d< Type > const &  p3 
)
related

Return the point at the centre of gravity of three given points.

Definition at line 229 of file vgl_point_2d.h.

◆ centre() [3/4]

template<class Type >
vgl_point_2d< Type > centre ( vgl_point_2d< Type > const &  p1,
vgl_point_2d< Type > const &  p2,
vgl_point_2d< Type > const &  p3,
vgl_point_2d< Type > const &  p4 
)
related

Return the point at the centre of gravity of four given points.

Definition at line 240 of file vgl_point_2d.h.

◆ centre() [4/4]

template<class Type >
vgl_point_2d< Type > centre ( std::vector< vgl_point_2d< Type > > const &  v)
related

Return the point at the centre of gravity of a set of given points.

Beware of possible rounding errors when Type is e.g. int.

Definition at line 253 of file vgl_point_2d.h.

◆ collinear()

template<class Type >
bool collinear ( vgl_point_2d< Type > const &  p1,
vgl_point_2d< Type > const &  p2,
vgl_point_2d< Type > const &  p3 
)
related

Are three points collinear, i.e., do they lie on a common line?.

Definition at line 180 of file vgl_point_2d.h.

◆ cross_ratio()

template<class T >
double cross_ratio ( vgl_point_2d< T >const &  p1,
vgl_point_2d< T >const &  p2,
vgl_point_2d< T >const &  p3,
vgl_point_2d< T >const &  p4 
)
related

cross ratio of four collinear points.

This number is projectively invariant, and it is the coordinate of p4 in the reference frame where p2 is the origin (coordinate 0), p3 is the unity (coordinate 1) and p1 is the point at infinity. This cross ratio is often denoted as ((p1, p2; p3, p4)) (which also equals ((p3, p4; p1, p2)) or ((p2, p1; p4, p3)) or ((p4, p3; p2, p1)) ) and is calculated as

                      p1 - p3   p2 - p3      (p1-p3)(p2-p4)
                      ------- : --------  =  --------------
                      p1 - p4   p2 - p4      (p1-p4)(p2-p3)

If three of the given points coincide, the cross ratio is not defined.

In this implementation, a least-squares result is calculated when the points are not exactly collinear.

◆ midpoint()

template<class Type >
vgl_point_2d< Type > midpoint ( vgl_point_2d< Type > const &  p1,
vgl_point_2d< Type > const &  p2,
Type  f = (Type)0.5 
)
related

Return the point at a given ratio wrt two other points.

By default, the mid point (ratio=0.5) is returned. Note that the third argument is Type, not double, so the midpoint of e.g. two vgl_point_2d<int> is not a valid concept. But the reflection point of p2 wrt p1 is: in that case f=-1.

Definition at line 206 of file vgl_point_2d.h.

◆ operator+()

template<class Type >
vgl_point_2d< Type > operator+ ( vgl_point_2d< Type > const &  p,
vgl_vector_2d< Type > const &  v 
)
related

Adding a vector to a point gives a new point at the end of that vector.

Note that vector + point is not defined! It's always point + vector.

Definition at line 128 of file vgl_point_2d.h.

◆ operator+=()

template<class Type >
vgl_point_2d< Type > & operator+= ( vgl_point_2d< Type > &  p,
vgl_vector_2d< Type > const &  v 
)
related

Adding a vector to a point gives the point at the end of that vector.

Definition at line 135 of file vgl_point_2d.h.

◆ operator-() [1/2]

template<class Type >
vgl_vector_2d< Type > operator- ( vgl_point_2d< Type > const &  p1,
vgl_point_2d< Type > const &  p2 
)
related

The difference of two points is the vector from second to first point.

Definition at line 120 of file vgl_point_2d.h.

◆ operator-() [2/2]

template<class Type >
vgl_point_2d< Type > operator- ( vgl_point_2d< Type > const &  p,
vgl_vector_2d< Type > const &  v 
)
related

Subtracting a vector from a point is the same as adding the inverse vector.

Definition at line 142 of file vgl_point_2d.h.

◆ operator-=()

template<class Type >
vgl_point_2d< Type > & operator-= ( vgl_point_2d< Type > &  p,
vgl_vector_2d< Type > const &  v 
)
related

Subtracting a vector from a point is the same as adding the inverse vector.

Definition at line 149 of file vgl_point_2d.h.

◆ operator<<()

template<class Type >
std::ostream & operator<< ( std::ostream &  s,
vgl_point_2d< Type > const &  p 
)
related

Write "<vgl_point_2d x,y>" to stream.

◆ operator>>()

template<class Type >
std::istream & operator>> ( std::istream &  s,
vgl_point_2d< Type > &  p 
)
related

Read from stream, possibly with formatting.

Either just reads two blank-separated numbers, or reads two comma-separated numbers, or reads two numbers in parenthesized form "(123, 321)"

◆ ratio()

template<class Type >
double ratio ( vgl_point_2d< Type > const &  p1,
vgl_point_2d< Type > const &  p2,
vgl_point_2d< Type > const &  p3 
)
related

Return the relative distance to p1 wrt p1-p2 of p3.

The three points should be collinear and p2 should not equal p1. This is the coordinate of p3 in the affine 1D reference frame (p1,p2). If p3=p1, the ratio is 0; if p1=p3, the ratio is 1. The mid point of p1 and p2 has ratio 0.5. Note that the return type is double, not Type, since the ratio of e.g. two vgl_vector_2d<int> need not be an int.

Definition at line 194 of file vgl_point_2d.h.

◆ vgl_closest_point_origin()

template<class T >
vgl_point_2d< T > vgl_closest_point_origin ( vgl_line_2d< T > const &  l)
related

Return the point on the given line closest to the origin.

◆ vgl_distance()

template<class T >
double vgl_distance ( vgl_point_2d< T >const &  p1,
vgl_point_2d< T >const &  p2 
)
related

return the distance between two points.

Definition at line 104 of file vgl_distance.h.

◆ vgl_intersection() [1/4]

template<class T >
bool vgl_intersection ( vgl_point_2d< T > const &  p0,
vgl_point_2d< T > const &  p1 
)
related

Return true if the two points intersect, i.e., coincide.

Definition at line 36 of file vgl_intersection.h.

◆ vgl_intersection() [2/4]

template<class T >
bool vgl_intersection ( vgl_point_3d< T > const &  p0,
vgl_point_3d< T > const &  p1 
)
related

Return true if the two points intersect, i.e., coincide.

Definition at line 43 of file vgl_intersection.h.

◆ vgl_intersection() [3/4]

template<class T >
bool vgl_intersection ( vgl_point_2d< T > const &  p1,
vgl_point_2d< T > const &  p2,
vgl_point_2d< T > const &  q1,
vgl_point_2d< T > const &  q2,
double  tol = 1e-6 
)
related

Return true if any point on [p1,p2] is within tol of [q1,q2].

Tests two line segments for intersection or near intersection (within given tolerance).

Author
Dan jackson

◆ vgl_intersection() [4/4]

template<class T >
std::vector< vgl_point_2d< T > > vgl_intersection ( vgl_polygon< T > const &  poly,
vgl_line_2d< T > const &  line 
)
related

Find the intersections of a line with a polygon( can have multiple sheets).

Member Data Documentation

◆ x_

template<class Type>
Type vgl_point_2d< Type >::x_
private

Definition at line 30 of file vgl_point_2d.h.

◆ y_

template<class Type>
Type vgl_point_2d< Type >::y_
private

Definition at line 31 of file vgl_point_2d.h.


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