DGtal  1.5.beta
DGtal::SphericalTriangle< TSpace > Class Template Reference

Aim: Represent a triangle drawn onto a sphere of radius 1. More...

#include <DGtal/geometry/tools/SphericalTriangle.h>

Public Member Functions

 ~SphericalTriangle ()
 
 SphericalTriangle (const RealVector &va, const RealVector &vb, const RealVector &vc, bool normalize=true)
 Default constructor. The object is invalid. More...
 
 SphericalTriangle (const SphericalTriangle &other)=default
 
SphericalTriangleoperator= (const SphericalTriangle &other)=default
 
const RealVectorA () const
 
const RealVectorB () const
 
const RealVectorC () const
 
void setA (const RealVector &va, bool normalize=true)
 
void setB (const RealVector &vb, bool normalize=true)
 
void setC (const RealVector &vc, bool normalize=true)
 
bool isDegenerate () const
 
Self polarTriangle () const
 
void interiorAngles (Scalar &alpha, Scalar &beta, Scalar &gamma) const
 
Scalar area () const
 
Scalar algebraicArea () const
 

Protected Attributes

RealVector myA
 The point A of the triangle ABC, of unit length. More...
 
RealVector myB
 The point B of the triangle ABC, of unit length. More...
 
RealVector myC
 The point C of the triangle ABC, of unit length. More...
 

Private Types

typedef TSpace Space
 
typedef SphericalTriangle< SpaceSelf
 
typedef Space::RealPoint RealPoint
 
typedef Space::RealVector RealVector
 
typedef RealVector::Component Scalar
 

Private Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CSpace< TSpace >))
 
 BOOST_STATIC_ASSERT ((Space::dimension==3))
 

Detailed Description

template<typename TSpace>
class DGtal::SphericalTriangle< TSpace >

Aim: Represent a triangle drawn onto a sphere of radius 1.

Description of class 'SphericalTriangle'

Template Parameters
TSpaceany type of 3-dimensional digital space.

Definition at line 61 of file SphericalTriangle.h.

Member Typedef Documentation

◆ RealPoint

template<typename TSpace >
typedef Space::RealPoint DGtal::SphericalTriangle< TSpace >::RealPoint
private

Definition at line 66 of file SphericalTriangle.h.

◆ RealVector

template<typename TSpace >
typedef Space::RealVector DGtal::SphericalTriangle< TSpace >::RealVector
private

Definition at line 67 of file SphericalTriangle.h.

◆ Scalar

template<typename TSpace >
typedef RealVector::Component DGtal::SphericalTriangle< TSpace >::Scalar
private

Definition at line 68 of file SphericalTriangle.h.

◆ Self

template<typename TSpace >
typedef SphericalTriangle<Space> DGtal::SphericalTriangle< TSpace >::Self
private

Definition at line 65 of file SphericalTriangle.h.

◆ Space

template<typename TSpace >
typedef TSpace DGtal::SphericalTriangle< TSpace >::Space
private

Definition at line 64 of file SphericalTriangle.h.

Constructor & Destructor Documentation

◆ ~SphericalTriangle()

template<typename TSpace >
DGtal::SphericalTriangle< TSpace >::~SphericalTriangle ( )
inline

Destructor.

Definition at line 79 of file SphericalTriangle.h.

79 {}

◆ SphericalTriangle() [1/2]

template<typename TSpace >
DGtal::SphericalTriangle< TSpace >::SphericalTriangle ( const RealVector va,
const RealVector vb,
const RealVector vc,
bool  normalize = true 
)
inline

Default constructor. The object is invalid.

Definition at line 82 of file SphericalTriangle.h.

84  {
85  setA( va, normalize );
86  setB( vb, normalize );
87  setC( vc, normalize );
88  }
void setC(const RealVector &vc, bool normalize=true)
void setB(const RealVector &vb, bool normalize=true)
void setA(const RealVector &va, bool normalize=true)

References DGtal::SphericalTriangle< TSpace >::setA(), DGtal::SphericalTriangle< TSpace >::setB(), and DGtal::SphericalTriangle< TSpace >::setC().

◆ SphericalTriangle() [2/2]

template<typename TSpace >
DGtal::SphericalTriangle< TSpace >::SphericalTriangle ( const SphericalTriangle< TSpace > &  other)
default

Copy constructor.

Parameters
otherthe object to clone.

Member Function Documentation

◆ A()

template<typename TSpace >
const RealVector& DGtal::SphericalTriangle< TSpace >::A ( ) const
inline
Returns
the point A of the spherical triangle.

Definition at line 104 of file SphericalTriangle.h.

104 { return myA; }
RealVector myA
The point A of the triangle ABC, of unit length.

References DGtal::SphericalTriangle< TSpace >::myA.

Referenced by DGtal::SphericalTriangle< TSpace >::interiorAngles().

◆ algebraicArea()

template<typename TSpace >
Scalar DGtal::SphericalTriangle< TSpace >::algebraicArea ( ) const
inline
Returns
the (signed) area of the spherical triangle (below 2pi).

Definition at line 217 of file SphericalTriangle.h.

218  {
219  Scalar S = area();
220  RealVector M = myA + myB + myC;
221  RealVector X = ( myB - myA ).crossProduct( myC - myA );
222  if ( M.norm1() <= 1e-8 || X.norm1() <= 1e-8 ) return 0.0;
223  return M.dot( X ) < 0.0 ? -S : S;
224  }
RealVector myC
The point C of the triangle ABC, of unit length.
RealVector myB
The point B of the triangle ABC, of unit length.
auto crossProduct(PointVector< 3, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< 3, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Cross product of two 3D Points/Vectors.

References DGtal::SphericalTriangle< TSpace >::area(), DGtal::crossProduct(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::dot(), DGtal::SphericalTriangle< TSpace >::myA, DGtal::SphericalTriangle< TSpace >::myB, DGtal::SphericalTriangle< TSpace >::myC, and DGtal::PointVector< dim, TEuclideanRing, TContainer >::norm1().

Referenced by DGtal::CorrectedNormalCurrentFormula< TRealPoint, TRealVector >::mu2InterpolatedU().

◆ area()

template<typename TSpace >
Scalar DGtal::SphericalTriangle< TSpace >::area ( ) const
inline
Returns
the (unsigned) area of the spherical triangle (below 2pi).

Definition at line 207 of file SphericalTriangle.h.

208  {
209  Scalar alpha, beta, gamma;
210  if ( isDegenerate() ) return 0.0;
211  interiorAngles( alpha, beta, gamma );
212  return ( (alpha == 0.0) || (beta == 0.0) || (gamma == 0.0) )
213  ? 0.0 : 2.0*M_PI - alpha - beta - gamma;
214  }
void interiorAngles(Scalar &alpha, Scalar &beta, Scalar &gamma) const

References DGtal::SphericalTriangle< TSpace >::interiorAngles(), and DGtal::SphericalTriangle< TSpace >::isDegenerate().

Referenced by DGtal::SphericalTriangle< TSpace >::algebraicArea().

◆ B()

template<typename TSpace >
const RealVector& DGtal::SphericalTriangle< TSpace >::B ( ) const
inline
Returns
the point B of the spherical triangle.

Definition at line 106 of file SphericalTriangle.h.

106 { return myB; }

References DGtal::SphericalTriangle< TSpace >::myB.

Referenced by DGtal::SphericalTriangle< TSpace >::interiorAngles().

◆ BOOST_CONCEPT_ASSERT()

template<typename TSpace >
DGtal::SphericalTriangle< TSpace >::BOOST_CONCEPT_ASSERT ( (concepts::CSpace< TSpace >)  )
private

◆ BOOST_STATIC_ASSERT()

template<typename TSpace >
DGtal::SphericalTriangle< TSpace >::BOOST_STATIC_ASSERT ( (Space::dimension==3)  )
private

◆ C()

template<typename TSpace >
const RealVector& DGtal::SphericalTriangle< TSpace >::C ( ) const
inline
Returns
the point C of the spherical triangle.

Definition at line 108 of file SphericalTriangle.h.

108 { return myC; }

References DGtal::SphericalTriangle< TSpace >::myC.

Referenced by DGtal::SphericalTriangle< TSpace >::interiorAngles().

◆ interiorAngles()

template<typename TSpace >
void DGtal::SphericalTriangle< TSpace >::interiorAngles ( Scalar alpha,
Scalar beta,
Scalar gamma 
) const
inline

Returns the interior angles of the spherical triangle ABC.

Parameters
[out]alphathe interior angle at vertex A.
[out]betathe interior angle at vertex B.
[out]gammathe interior angle at vertex C.

Definition at line 190 of file SphericalTriangle.h.

191  {
192  Self T = polarTriangle();
193  if ( T.A() == RealVector::zero || T.B() == RealVector::zero || T.C() == RealVector::zero )
194  alpha = beta = gamma = 0.0;
195  else
196  {
197  Scalar ca = std::max( -1.0, std::min( 1.0, T.B().dot( T.C() ) ) );
198  Scalar cb = std::max( -1.0, std::min( 1.0, T.C().dot( T.A() ) ) );
199  Scalar cc = std::max( -1.0, std::min( 1.0, T.A().dot( T.B() ) ) );
200  alpha = acos( ca );
201  beta = acos( cb );
202  gamma = acos( cc );
203  }
204  }
static Self zero
Static const for zero PointVector.
Definition: PointVector.h:1595
SphericalTriangle< Space > Self
const RealVector & B() const
const RealVector & C() const
int max(int a, int b)

References DGtal::SphericalTriangle< TSpace >::A(), DGtal::SphericalTriangle< TSpace >::B(), DGtal::SphericalTriangle< TSpace >::C(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::dot(), max(), DGtal::SphericalTriangle< TSpace >::polarTriangle(), and DGtal::PointVector< dim, TEuclideanRing, TContainer >::zero.

Referenced by DGtal::SphericalTriangle< TSpace >::area().

◆ isDegenerate()

template<typename TSpace >
bool DGtal::SphericalTriangle< TSpace >::isDegenerate ( ) const
inline
Returns
'true' if the spherical triangle is too small or too thin.

Definition at line 158 of file SphericalTriangle.h.

159  {
160  Scalar d[ 3 ] = { ( myA - myB ).norm(),
161  ( myA - myC ).norm(),
162  ( myB - myC ).norm() };
163  // Checks that the spherical triangle is small or thin.
164  if ( ( d[ 0 ] < 1e-8 ) || ( d[ 1 ] < 1e-8 ) || ( d[ 2 ] < 1e-8 ) )
165  return true;
166  // Checks that the spherical triangle is flat.
167  Dimension m = 0;
168  if ( d[ 1 ] > d[ m ] ) m = 1;
169  if ( d[ 2 ] > d[ m ] ) m = 2;
170  return ( fabs( d[ m ] - d[ (m+1)%3 ] - d[ (m+2)%3 ] ) < 1e-8 );
171  }
DGtal::uint32_t Dimension
Definition: Common.h:136

References DGtal::SphericalTriangle< TSpace >::myA, DGtal::SphericalTriangle< TSpace >::myB, and DGtal::SphericalTriangle< TSpace >::myC.

Referenced by DGtal::SphericalTriangle< TSpace >::area().

◆ operator=()

template<typename TSpace >
SphericalTriangle& DGtal::SphericalTriangle< TSpace >::operator= ( const SphericalTriangle< TSpace > &  other)
default

Assignment.

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

◆ polarTriangle()

template<typename TSpace >
Self DGtal::SphericalTriangle< TSpace >::polarTriangle ( ) const
inline
Returns
the polar triangle associated with this triangle.

Definition at line 174 of file SphericalTriangle.h.

175  {
176  auto Ap = myB.crossProduct(myC);
177  auto Bp = myC.crossProduct(myA);
178  auto Cp = myA.crossProduct(myB);
179  // Reorient points.
180  if ( Ap.dot( myA ) < 0.0 ) Ap = -Ap;
181  if ( Bp.dot( myB ) < 0.0 ) Bp = -Bp;
182  if ( Cp.dot( myC ) < 0.0 ) Cp = -Cp;
183  return Self( Ap, Bp, Cp, true );
184  }
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.

References DGtal::PointVector< dim, TEuclideanRing, TContainer >::crossProduct(), DGtal::SphericalTriangle< TSpace >::myA, DGtal::SphericalTriangle< TSpace >::myB, and DGtal::SphericalTriangle< TSpace >::myC.

Referenced by DGtal::SphericalTriangle< TSpace >::interiorAngles().

◆ setA()

template<typename TSpace >
void DGtal::SphericalTriangle< TSpace >::setA ( const RealVector va,
bool  normalize = true 
)
inline

Sets the point A of the triangle.

Parameters
vathe new point A
normalizeif true, force normalization, otherwise va should be of unit length.

Definition at line 115 of file SphericalTriangle.h.

116  {
117  myA = va;
118  if ( normalize )
119  {
120  Scalar n = myA.norm();
121  if ( fabs( n ) > 1e-8 ) myA /= n;
122  else myA = RealVector::zero;
123  }
124  }
double norm(const NormType type=L_2) const

References DGtal::SphericalTriangle< TSpace >::myA, DGtal::PointVector< dim, TEuclideanRing, TContainer >::norm(), and DGtal::PointVector< dim, TEuclideanRing, TContainer >::zero.

Referenced by DGtal::SphericalTriangle< TSpace >::SphericalTriangle().

◆ setB()

template<typename TSpace >
void DGtal::SphericalTriangle< TSpace >::setB ( const RealVector vb,
bool  normalize = true 
)
inline

Sets the point B of the triangle.

Parameters
vbthe new point B
normalizeif true, force normalization, otherwise vb should be of unit length.

Definition at line 131 of file SphericalTriangle.h.

132  {
133  myB = vb;
134  if ( normalize )
135  {
136  Scalar n = myB.norm();
137  if ( fabs( n ) > 1e-8 ) myB /= n;
138  else myB = RealVector::zero;
139  }
140  }

References DGtal::SphericalTriangle< TSpace >::myB, DGtal::PointVector< dim, TEuclideanRing, TContainer >::norm(), and DGtal::PointVector< dim, TEuclideanRing, TContainer >::zero.

Referenced by DGtal::SphericalTriangle< TSpace >::SphericalTriangle().

◆ setC()

template<typename TSpace >
void DGtal::SphericalTriangle< TSpace >::setC ( const RealVector vc,
bool  normalize = true 
)
inline

Sets the point C of the triangle.

Parameters
vcthe new point C
normalizeif true, force normalization, otherwise vc should be of unit length.

Definition at line 146 of file SphericalTriangle.h.

147  {
148  myC = vc;
149  if ( normalize )
150  {
151  Scalar n = myC.norm();
152  if ( fabs( n ) > 1e-8 ) myC /= n;
153  else myC = RealVector::zero;
154  }
155  }

References DGtal::SphericalTriangle< TSpace >::myC, DGtal::PointVector< dim, TEuclideanRing, TContainer >::norm(), and DGtal::PointVector< dim, TEuclideanRing, TContainer >::zero.

Referenced by DGtal::SphericalTriangle< TSpace >::SphericalTriangle().

Field Documentation

◆ myA

◆ myB

◆ myC


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