DGtal 1.3.0
Loading...
Searching...
No Matches
Lemniscate2D.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 Lemniscate2D.ih
19 * @author Chouaib Fellah, Adrien Krähenbühl (\c krahenbuhl@unistra.fr )
20 * Laboratoire des sciences de l'ingénieur, de l'informatique et de l'imagerie - ICube (UMR 7357), France
21 *
22 * @date 2018/06/12
23 *
24 * Implementation of inline methods defined in Lemniscate2D.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29///////////////////////////////////////////////////////////////////////////////
30#include <cstdlib>
31///////////////////////////////////////////////////////////////////////////////
32
33#define LEMNISCATE2D_3_PI_2 (3. * M_PI / 2.)
34
35///////////////////////////////////////////////////////////////////////////////
36// IMPLEMENTATION of inline methods.
37///////////////////////////////////////////////////////////////////////////////
38
39///////////////////////////////////////////////////////////////////////////////
40// ----------------------- Standard services ----------------------------------
41
42template <typename T>
43inline
44DGtal::Lemniscate2D<T>::Lemniscate2D( const double x0, const double y0,
45 const double a ) : myCenter(x0,y0), myA(fabs(a))
46{}
47
48template <typename T>
49inline
50DGtal::Lemniscate2D<T>::Lemniscate2D( const RealPoint &aPoint,
51 const double a ) : myCenter(aPoint), myA(fabs(a))
52{}
53
54template <typename T>
55inline
56DGtal::Lemniscate2D<T>::Lemniscate2D(const Lemniscate2D& other ) :
57 myCenter(other.myCenter), myA(other.myA)
58{}
59
60///////////////////////////////////////////////////////////////////////////////
61// ------------- Implementation of 'StarShaped' services ----------------------
62
63/**
64 * @param pp any point in the plane.
65 *
66 * @return the angle parameter between 0 and 2*Pi corresponding to
67 * this point for the shape.
68 */
69template <typename T>
70inline
71double
72DGtal::Lemniscate2D<T>::parameter( const RealPoint& pp ) const
73{
74 const RealPoint p( pp-myCenter );
75 double angle;
76
77 if ( fabs(p[0]) < fabs(p[1]) )
78 angle = 0.;
79 else if ( isAlmostEqual(p[0],0.) )
80 angle = p[1] < 0. ? M_PI : 0.;
81 else if ( isAlmostEqual(p[1],0.) )
82 angle = p[0] > 0. ? M_PI_2 : LEMNISCATE2D_3_PI_2;
83 else
84 angle = acos(p[1]/p[0]);
85
86 return angle;
87}
88
89/**
90 * @param t any angle between 0 and 2*Pi.
91 *
92 * @return the vector (x(t),y(t)) which is the position on the
93 * shape boundary.
94 */
95template <typename T>
96inline
97typename DGtal::Lemniscate2D<T>::RealPoint
98DGtal::Lemniscate2D<T>::x( const double t ) const
99{
100 const double cost = cos(t);
101 const double sint = sin(t);
102 const double cos2t = pow(cost,2);
103 return RealPoint(
104 myA * sint / (1. + cos2t) + myCenter[0],
105 myA * sint * cost / (1. + cos2t) + myCenter[1]
106 );
107}
108
109
110/**
111 * @param t any angle between 0 and 2*Pi.
112 *
113 * @return the vector (x'(t),y'(t)) which is the tangent to the
114 * shape boundary.
115 */
116template <typename T>
117inline
118typename DGtal::Lemniscate2D<T>::RealVector
119DGtal::Lemniscate2D<T>::xp( const double t ) const
120{
121 const double cost = cos(t);
122 const double cos2t = pow(cost,2);
123 const double sin2t = pow(sin(t),2);
124
125 return RealVector(
126 myA * (cost + 2*sin2t*cost+pow(cost,3)) / pow(1+cos2t,2),
127 myA * (pow(cost,4) + cos2t - sin2t + sin2t * cos2t)
128 / pow(1+cos2t,2) );
129}
130
131template <typename T>
132inline
133typename DGtal::Lemniscate2D<T>::RealVector
134DGtal::Lemniscate2D<T>::xpp( const double t ) const
135{
136 const double cost = cos(t);
137 const double cos2t = pow(cost,2);
138 const double sint = sin(t);
139 const double sin3t = pow(sint,3);
140
141 return RealVector(
142 myA * ( 4 * sin3t * cos2t +
143 6 * sin3t * pow(cost,4) +
144 3 * sint * cos2t -
145 sint +
146 9 * sint * pow(cost,4) +
147 5 * pow(cost,6) * sint -
148 2 * sin3t )
149 / pow(1+cos2t,4),
150
151 myA * ( -4* sin3t * pow(cost,3) -
152 6 * sin3t * cost +
153 2 * sin3t * pow(cost,5) -
154 4 * sint * cost -
155 6 * sint * pow(cost,3) +
156 2 * sint * pow(cost,7) )
157 / pow(1+cos2t,4)
158 );
159}
160
161
162///////////////////////////////////////////////////////////////////////////////
163// Interface - public :
164
165/**
166 * Writes/Displays the object on an output stream.
167 * @param out the output stream where the object is written.
168 */
169template <typename T>
170inline
171void
172DGtal::Lemniscate2D<T>::selfDisplay ( std::ostream & out ) const
173{
174 out << "[Lemniscate2D] center= " << myCenter
175 << " a=" << myA;
176}
177
178/**
179 * Checks the validity/consistency of the object.
180 * @return 'true' if the object is valid, 'false' otherwise.
181 */
182template <typename T>
183inline
184bool
185DGtal::Lemniscate2D<T>::isValid() const
186{
187 return true;
188}
189
190
191///////////////////////////////////////////////////////////////////////////////
192// Implementation of inline functions //
193
194template <typename T>
195inline
196std::ostream&
197DGtal::operator<< ( std::ostream & out,
198 const Lemniscate2D<T> & object )
199{
200 object.selfDisplay( out );
201 return out;
202}
203
204// //
205///////////////////////////////////////////////////////////////////////////////