DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::CircleFrom3Points< TPoint > Class Template Reference

#include <CircleFrom3Points.h>

Inheritance diagram for DGtal::CircleFrom3Points< TPoint >:
Inheritance graph
[legend]
Collaboration diagram for DGtal::CircleFrom3Points< TPoint >:
Collaboration graph
[legend]

Public Types

typedef TPoint::Coordinate Coordinate
typedef Coordinate Distance
typedef TPoint Point
typedef TPoint Vector

Public Member Functions

 CircleFrom3Points ()
 CircleFrom3Points (const Point &aFirstPoint, const Point &aSecondPoint, const Point &aThirdPoint)
void init (const Point &aFirstPoint, const Point &aSecondPoint, const Point &aThirdPoint)
 CircleFrom3Points (const CircleFrom3Points &other)
CircleFrom3Pointsoperator= (const CircleFrom3Points &other)
 ~CircleFrom3Points ()
Distance signedDistance (const Point &aP) const
bool isValid () const
void getParameters (double &cx, double &cy, double &rr) const
double getCurvature () const
const Pointp () const
const Pointq () const
const Pointr () const
void selfDisplay (std::ostream &out) const
std::string className () const

Private Member Functions

 BOOST_STATIC_ASSERT ((TPoint::dimension==2))

Private Attributes

Point myP
Point myQ
Point myR

Detailed Description

template<typename TPoint>
class DGtal::CircleFrom3Points< TPoint >

Aim: Represents a circle uniquely defined by three 2D points and that is able to return for any given 2D point its signed distance to itself.

Template Parameters:
TPointa type of points.

Definition at line 66 of file CircleFrom3Points.h.


Member Typedef Documentation

template<typename TPoint>
typedef TPoint::Coordinate DGtal::CircleFrom3Points< TPoint >::Coordinate

Definition at line 74 of file CircleFrom3Points.h.

template<typename TPoint>
typedef Coordinate DGtal::CircleFrom3Points< TPoint >::Distance

Definition at line 75 of file CircleFrom3Points.h.

template<typename TPoint>
typedef TPoint DGtal::CircleFrom3Points< TPoint >::Point

Definition at line 76 of file CircleFrom3Points.h.

template<typename TPoint>
typedef TPoint DGtal::CircleFrom3Points< TPoint >::Vector

Definition at line 77 of file CircleFrom3Points.h.


Constructor & Destructor Documentation

template<typename TPoint >
DGtal::CircleFrom3Points< TPoint >::CircleFrom3Points ( )
inline

Default constructor.

Definition at line 49 of file CircleFrom3Points.ih.

{
}
template<typename TPoint >
DGtal::CircleFrom3Points< TPoint >::CircleFrom3Points ( const Point aFirstPoint,
const Point aSecondPoint,
const Point aThirdPoint 
)
inline

Constructor.

Parameters:
aFirstPointa point
aSecondPointa second point
aThirdPointa third point

Definition at line 69 of file CircleFrom3Points.ih.

:
myP(aFirstPoint),
myQ(aSecondPoint),
myR(aThirdPoint)
{
}
template<typename TPoint >
DGtal::CircleFrom3Points< TPoint >::CircleFrom3Points ( const CircleFrom3Points< TPoint > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 82 of file CircleFrom3Points.ih.

:
myP(other.myP),
myQ(other.myQ),
myR(other.myR)
{
}
template<typename TPoint >
DGtal::CircleFrom3Points< TPoint >::~CircleFrom3Points ( )
inline

Destructor. Does nothing

Definition at line 43 of file CircleFrom3Points.ih.

{
}

Member Function Documentation

template<typename TPoint>
DGtal::CircleFrom3Points< TPoint >::BOOST_STATIC_ASSERT ( (TPoint::dimension==2)  )
private
template<typename TPoint >
std::string DGtal::CircleFrom3Points< TPoint >::className ( ) const
inline
Returns:
the style name used for drawing this object.

Definition at line 196 of file CircleFrom3Points.ih.

Referenced by DGtal::Display2DFactory::draw().

{
return "CircleFrom3Points";
}
template<typename TPoint >
double DGtal::CircleFrom3Points< TPoint >::getCurvature ( ) const
inline
Returns:
circle curvature

Definition at line 167 of file CircleFrom3Points.ih.

References DGtal::NumberTraits< T >::castToDouble().

{
Vector u(myP - myQ);
Vector v(myR - myP);
//4 times the area of the triangle
Coordinate area = (u[0] * v[1]) - (u[1] * v[0]);
double areaD = NumberTraits<Coordinate>::castToDouble(area)*2.0;
//length of the sides of the triangle
double a, b, c;
a = std::pow( NumberTraits<Coordinate>::castToDouble(myQ[0]-myP[0]),2.0 )
+std::pow( NumberTraits<Coordinate>::castToDouble(myQ[1]-myP[1]),2.0 );
b = std::pow( NumberTraits<Coordinate>::castToDouble(myR[0]-myQ[0]),2.0 )
+std::pow( NumberTraits<Coordinate>::castToDouble(myR[1]-myQ[1]),2.0 );
c = std::pow( NumberTraits<Coordinate>::castToDouble(myR[0]-myP[0]),2.0 )
+std::pow( NumberTraits<Coordinate>::castToDouble(myR[1]-myP[1]),2.0 );
//curvature
return -( areaD/ (std::sqrt(a)*std::sqrt(b)*std::sqrt(c)) );
}
template<typename TPoint >
void DGtal::CircleFrom3Points< TPoint >::getParameters ( double &  cx,
double &  cy,
double &  rr 
) const
inline

Computes the parameters of the circle

Parameters:
cxreturned x-coordinate of the circle
cyreturned y-coordinate of the circle
rreturned radius of the circle

Definition at line 121 of file CircleFrom3Points.ih.

References DGtal::abs(), and DGtal::NumberTraits< T >::castToDouble().

Referenced by DGtal::Display2DFactory::draw(), DGtal::Display2DFactory::drawAnnulus(), DGtal::Display2DFactory::drawArc(), DGtal::Display2DFactory::drawSector(), and DGtal::CircleFrom2Points< TPoint >::getParameters().

{
Vector u(myP - myQ);
Vector v(myR - myP);
Coordinate area = (u[0] * v[1]) - (u[1] * v[0]);
if (area == 0) {
std::cerr << "Infinite radius detected in method getParameters() of CircleFrom3Points" << std::endl;
throw InfiniteNumberException();
} else {
//center
double areaD = NumberTraits<Coordinate>::castToDouble(area)*2.0;
double pz, qz, rz;
pz = std::pow( NumberTraits<Coordinate>::castToDouble(myP[0]),2.0 )/areaD
+ std::pow( NumberTraits<Coordinate>::castToDouble(myP[1]),2.0 )/areaD;
qz = std::pow( NumberTraits<Coordinate>::castToDouble(myQ[0]),2.0 )/areaD
+ std::pow( NumberTraits<Coordinate>::castToDouble(myQ[1]),2.0 )/areaD;
rz = std::pow( NumberTraits<Coordinate>::castToDouble(myR[0]),2.0 )/areaD
+ std::pow( NumberTraits<Coordinate>::castToDouble(myR[1]),2.0 )/areaD;
cx = NumberTraits<Coordinate>::castToDouble(myP[1])*(qz-rz)
-NumberTraits<Coordinate>::castToDouble(myQ[1])*(pz-rz)
+NumberTraits<Coordinate>::castToDouble(myR[1])*(pz-qz);
cy = -NumberTraits<Coordinate>::castToDouble(myP[0])*(qz-rz)
+NumberTraits<Coordinate>::castToDouble(myQ[0])*(pz-rz)
-NumberTraits<Coordinate>::castToDouble(myR[0])*(pz-qz);
//radius
double a, b, c;
a = std::pow( NumberTraits<Coordinate>::castToDouble(myQ[0]-myP[0]),2.0 )
+std::pow( NumberTraits<Coordinate>::castToDouble(myQ[1]-myP[1]),2.0 );
b = std::pow( NumberTraits<Coordinate>::castToDouble(myR[0]-myQ[0]),2.0 )
+std::pow( NumberTraits<Coordinate>::castToDouble(myR[1]-myQ[1]),2.0 );
c = std::pow( NumberTraits<Coordinate>::castToDouble(myR[0]-myP[0]),2.0 )
+std::pow( NumberTraits<Coordinate>::castToDouble(myR[1]-myP[1]),2.0 );
rr = ( ( std::sqrt(a)/std::abs(areaD) )*std::sqrt(b)*std::sqrt(c) );
}
}
template<typename TPoint >
void DGtal::CircleFrom3Points< TPoint >::init ( const Point aFirstPoint,
const Point aSecondPoint,
const Point aThirdPoint 
)
inline

Init.

Parameters:
aFirstPointa point
aSecondPointa second point
aThirdPointa third point

Definition at line 56 of file CircleFrom3Points.ih.

{
myP = aFirstPoint;
myQ = aSecondPoint;
myR = aThirdPoint;
}
template<typename TPoint >
bool DGtal::CircleFrom3Points< TPoint >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 213 of file CircleFrom3Points.ih.

{
return true;
}
template<typename TPoint >
DGtal::CircleFrom3Points< TPoint > & DGtal::CircleFrom3Points< TPoint >::operator= ( const CircleFrom3Points< TPoint > &  other)
inline

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Definition at line 94 of file CircleFrom3Points.ih.

References DGtal::CircleFrom3Points< TPoint >::myP, DGtal::CircleFrom3Points< TPoint >::myQ, and DGtal::CircleFrom3Points< TPoint >::myR.

{
myP = other.myP;
myQ = other.myQ;
myR = other.myR;
return *this;
}
template<typename TPoint>
const Point& DGtal::CircleFrom3Points< TPoint >::p ( ) const
inline
Returns:
the first point through which the circle passes.

Definition at line 157 of file CircleFrom3Points.h.

Referenced by DGtal::Display2DFactory::draw(), DGtal::Display2DFactory::drawAnnulus(), DGtal::Display2DFactory::drawArc(), and DGtal::Display2DFactory::drawSector().

{
return myP;
};
template<typename TPoint>
const Point& DGtal::CircleFrom3Points< TPoint >::q ( ) const
inline
Returns:
the second point through which the circle passes.

Definition at line 165 of file CircleFrom3Points.h.

Referenced by DGtal::Display2DFactory::draw(), DGtal::Display2DFactory::drawAnnulus(), DGtal::Display2DFactory::drawArc(), and DGtal::Display2DFactory::drawSector().

{
return myQ;
};
template<typename TPoint>
const Point& DGtal::CircleFrom3Points< TPoint >::r ( ) const
inline
Returns:
the third point through which the circle passes.

Definition at line 173 of file CircleFrom3Points.h.

Referenced by DGtal::Display2DFactory::draw(), DGtal::Display2DFactory::drawAnnulus(), DGtal::Display2DFactory::drawArc(), and DGtal::Display2DFactory::drawSector().

{
return myR;
};
template<typename TPoint >
void DGtal::CircleFrom3Points< TPoint >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 204 of file CircleFrom3Points.ih.

{
out << "[CircleFrom3Points] passing through:\n";
out << myP << myQ << myR;
}
template<typename TPoint >
DGtal::CircleFrom3Points< TPoint >::Distance DGtal::CircleFrom3Points< TPoint >::signedDistance ( const Point aP) const
inline

Computes the signed distance of to the circle

Parameters:
aPthe point to be tested.
Returns:
the signed distance.

Definition at line 108 of file CircleFrom3Points.ih.

Referenced by DGtal::CircleFrom2Points< TPoint >::signedDistance().

{
Vector u( (myP[0]-aP[0])*(myR[1]-aP[1])-(myR[0]-aP[0])*(myP[1]-aP[1]),
(myR[0]-aP[0])*(myR[0]-myP[0])+(myR[1]-aP[1])*(myR[1]-myP[1]) );
Vector v( (myP[0]-aP[0])*(myQ[1]-aP[1])-(myQ[0]-aP[0])*(myP[1]-aP[1]),
(myQ[0]-aP[0])*(myQ[0]-myP[0])+(myQ[1]-aP[1])*(myQ[1]-myP[1]) );
return -( (u[0] * v[1]) - (u[1] * v[0]) );
}

Field Documentation

template<typename TPoint>
Point DGtal::CircleFrom3Points< TPoint >::myP
private

First point through which the circle passes

Definition at line 201 of file CircleFrom3Points.h.

Referenced by DGtal::Display2DFactory::draw(), DGtal::CircleFrom3Points< TPoint >::operator=(), and DGtal::CircleFrom3Points< Point >::p().

template<typename TPoint>
Point DGtal::CircleFrom3Points< TPoint >::myQ
private

Second point through which the circle passes

Definition at line 205 of file CircleFrom3Points.h.

Referenced by DGtal::CircleFrom3Points< TPoint >::operator=(), and DGtal::CircleFrom3Points< Point >::q().

template<typename TPoint>
Point DGtal::CircleFrom3Points< TPoint >::myR
private

Third point through which the circle passes

Definition at line 209 of file CircleFrom3Points.h.

Referenced by DGtal::Display2DFactory::draw(), DGtal::CircleFrom3Points< TPoint >::operator=(), and DGtal::CircleFrom3Points< Point >::r().


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