DGtal  1.2.0
EllipticHelix.ih
1 /**
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU Lesser General Public License as
4  * published by the Free Software Foundation, either version 3 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  **/
16 
17 /**
18  * @file EllipticHelix.ih
19  * @author Kacper Pluta (\c kacper.pluta@esiee.fr )
20  * Laboratoire d'Informatique Gaspard-Monge - LIGM, A3SI, France
21  *
22  * @date 2014/10/01
23  *
24  * Implementation of inline methods defined in EllipticHelix.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 // IMPLEMENTATION of inline methods.
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 //////////////////////////////////////////////////////////////////////////////
34 //////////////////////////////////////////////////////////////////////////////
35 
36 
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // Implementation of inline methods //
40 
41 template <typename T>
42 inline
43 DGtal::EllipticHelix<T>::EllipticHelix ( long double rr, long double rl, long double bb ) : r1 ( rr ), r2 ( rl ) , b ( bb ) {}
44 
45 template < typename T>
46 inline
47 typename DGtal::EllipticHelix<T>::RealPoint DGtal::EllipticHelix<T>::x ( const long double t ) const
48 {
49  return RealPoint ( r1 * std::cos ( t ), r2 * std::sin ( t ), b * t );
50 }
51 
52 template < typename T>
53 inline
54 typename DGtal::EllipticHelix<T>::RealPoint DGtal::EllipticHelix<T>::xp ( const long double t ) const
55 {
56  return RealPoint ( -r1 * std::sin ( t ), r2 * std::cos ( t ), b );
57 }
58 
59 template < typename T>
60 inline
61 long double DGtal::EllipticHelix<T>:: f ( const RealPoint & p ) const
62 {
63  if ( p[1] >= 0. )
64  {
65  long double value = std::acos ( p[0] / r1 );
66  if ( std::isnan ( value ) )
67  throw std::runtime_error ( "Out of range!" );
68  return value;
69  }
70  else if ( p[1] < 0. )
71  {
72  long double value = std::acos ( p[0] / r1 );
73  if ( std::isnan ( value ) )
74  throw std::runtime_error ( "Out of range!" );
75  return 2.0 * M_PI - value;
76  }
77  else
78  throw std::runtime_error ( "Out of range!" );
79 }
80 
81 template < typename T>
82 inline
83 long double DGtal::EllipticHelix<T>:: g ( const RealPoint & p ) const
84 {
85  if ( p[0] >= 0. && p[1] >= 0. )
86  {
87  long double value = std::asin ( p[1] / r2 );
88  if ( std::isnan ( value ) )
89  throw std::runtime_error ( "Out of range!" );
90  return value;
91  }
92  else if ( p[0] < 0. )
93  {
94  long double value = std::asin ( p[1] / r2 );
95  if ( std::isnan ( value ) )
96  throw std::runtime_error ( "Out of range!" );
97  return M_PI - value;
98  }
99  else if ( p[0] >= 0. && p[1] < 0. )
100  {
101  long double value = std::asin ( p[1]/ r2 );
102  if ( std::isnan ( value ) )
103  throw std::runtime_error ( "Out of range!" );
104  return 2. * M_PI + value;
105  }
106  else
107  throw std::runtime_error ( "Out of range!" );
108 }
109 
110 template < typename T>
111 inline
112 long double DGtal::EllipticHelix<T>:: h ( const RealPoint & p ) const
113 {
114  if ( std::abs ( b ) < 1E-20 )
115  return 0.;
116  else
117  return p[2]/b;
118 }
119 
120 template < typename T>
121 inline
122 double DGtal::EllipticHelix<T>::getPeriod()
123 {
124  return PERIOD;
125 }
126 
127 
128 template < typename T>
129 inline
130 void DGtal::EllipticHelix<T>::selfDisplay ( std::ostream & out ) const
131 {
132  out << "[EllipticHelix]";
133 }
134 
135 ///////////////////////////////////////////////////////////////////////////////
136 // Implementation of inline functions and external operators //
137 
138 /**
139  * Overloads 'operator<<' for displaying objects of class 'EllipticHelix'.
140  * @param out the output stream where the object is written.
141  * @param object the object of class 'EllipticHelix' to write.
142  * @return the output stream after the writing.
143  */
144 template <typename T>
145 inline
146 std::ostream&
147 DGtal::operator<< ( std::ostream & out,
148  const EllipticHelix<T> & object )
149 {
150  object.selfDisplay ( out );
151  return out;
152 }
153 
154 // //
155 ///////////////////////////////////////////////////////////////////////////////
156 
157