00001 #ifndef __GFRACTALE_HPP__
00002 #define __GFRACTALE_HPP__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "Commun.hpp"
00034 namespace Fractale
00035 {
00036
00041 struct GFractale
00042 {
00043 std::vector<point> sequence;
00044 unsigned int sequenceSizeMax;
00051 GFractale(unsigned int sequenceSizeMax = 1000)
00052 : sequenceSizeMax(sequenceSizeMax)
00053 {
00054 }
00055
00059 virtual ~GFractale() {};
00060
00069 virtual point initialisation(const point & pInit) = 0;
00070
00080 virtual point suivant(const point & Zn) = 0;
00081
00092 virtual bool fin(const point & Zn) = 0;
00093
00102 virtual std::vector<point> & genererSequence(const point &pInit)
00103 {
00104 sequence.clear();
00105
00106 point z = initialisation(pInit);
00107 for ( unsigned int i = 0; !fin(z) && i < sequenceSizeMax ; ++i)
00108 {
00109
00110 z = suivant(z);
00111 sequence.push_back(z);
00112 }
00113
00114 if(!fin(z))
00115 {
00116 sequence.clear();
00117 }
00118 return sequence;
00119 }
00120
00121 };
00122
00131 class Mandelbrot : public GFractale
00132 {
00133 const point z0;
00134 point c;
00135 public:
00136
00137 Mandelbrot(const point & z0 = point())
00138 : z0(z0)
00139 {}
00140 point initialisation(const point & pInit)
00141 {
00142 c = pInit;
00143 return z0;
00144 }
00145
00146 point suivant(const point &Zn)
00147 {
00148 return Zn * Zn + c;
00149 }
00157 bool fin(const point & Zn)
00158 {
00159 return Zn.real() * Zn.real() + Zn.imag() * Zn.imag() > 4;
00160 }
00161 };
00170 struct BateauEnFeu : public GFractale
00171 {
00172 point c;
00173 public:
00174
00175 point initialisation(const point & pInit)
00176 {
00177 c = pInit;
00178 return point();
00179 }
00180 point suivant(const point & Zn)
00181 {
00182 point Znt = point(fabs(Zn.real()), fabs(Zn.imag()));
00183 return Znt * Znt + c;
00184 }
00188 bool fin(const point & Zn)
00189 {
00190 return Zn.real() * Zn.real() + Zn.imag() * Zn.imag() > 4;
00191 }
00192 };
00201 struct Tricorn : public GFractale
00202 {
00203 point c;
00204 public:
00205
00206 point initialisation(const point & pInit)
00207 {
00208 c = pInit;
00209 return point();
00210 }
00211
00212 point suivant(const point &Zn)
00213 {
00214 point Znt = point(-Zn.real(), Zn.imag());
00215 return Znt * Znt + c;
00216 }
00220 bool fin(const point & Zn)
00221 {
00222 return Zn.real() * Zn.real() + Zn.imag() * Zn.imag() > 4;
00223 }
00224 };
00225
00233 class Julian : public GFractale
00234 {
00235 const point c;
00236 public:
00237 Julian( const point & c = point())
00238 : c(c)
00239 {}
00240
00241 point initialisation(const point & pInit)
00242 {
00243 return pInit;
00244 }
00245 point suivant(const point &Zn)
00246 {
00247 return Zn * Zn + c;
00248 }
00252 bool fin(const point & Zn)
00253 {
00254 return Zn.real() * Zn.real() + Zn.imag() * Zn.imag() > 4;
00255 }
00256
00257 };
00258
00267 struct Newton : public GFractale
00268 {
00269 point initialisation(const point & pInit)
00270 {
00271 return pInit;
00272 }
00273 point suivant(const point &Zn)
00274 {
00275 return Zn - (Zn * Zn * Zn - 1.) / (3. * Zn * Zn );
00276 }
00277 bool fin(const point & Zn)
00278 {
00279 return std::abs(Zn * Zn * Zn - 1.) < 0.01;
00280 }
00281 };
00282
00294 struct Nova : public GFractale
00295 {
00296 point old;
00297 point c;
00298 public:
00299 Nova(unsigned int sequenceSizeMax = 1000)
00300 :GFractale(sequenceSizeMax)
00301 {
00302
00303 }
00304 point initialisation(const point & pInit)
00305 {
00306 old =point();
00307 c = pInit;
00308 return point(1.);
00309 }
00310
00311 point suivant(const point &Zn)
00312 {
00313 old = Zn;
00314 return Zn - 2. * (Zn * Zn * Zn - 1.) / (3. * Zn * Zn ) + c;
00315 }
00316
00326 bool fin(const point &z)
00327 {
00328 return std::abs(z - old) <0.05;
00329 }
00330 };
00331
00341 struct CliffordAttractors : public GFractale
00342 {
00343 const double a;
00344 const double b;
00345 const double c;
00346 const double d;
00347 CliffordAttractors(double a =-1.4, double b = 1.6, double c = 1.0,double d = 0.7)
00348 :GFractale(10000),a(a),b(b),c(c),d(d){}
00349
00350 point initialisation(const point & pInit)
00351 {
00352 return pInit;
00353 }
00354
00355 point suivant(const point &Zn)
00356 {
00357
00358 return point
00359 (
00360 sin(a * Zn.imag()) + c * cos(a * Zn.real()),
00361 sin(b * Zn.real()) + d * cos(b * Zn.imag())
00362 );
00363 }
00364
00373 bool fin(const point &)
00374 {
00375 return false;
00376 }
00377
00378 virtual std::vector<point> & genererSequence(const point & c)
00379 {
00380 sequence.clear();
00381 sequence.push_back(c);
00382
00383 point z = initialisation(c);
00384 for ( unsigned int i = 0; i < sequenceSizeMax ; ++i)
00385 {
00386 z = suivant(z);
00387 sequence.push_back(z);
00388 }
00389 return sequence;
00390 }
00391 };
00392 }
00393
00394 #endif