00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef GFRACTALE_H
00023 #define GFRACTALE_H
00024 #include "Commun.hpp"
00032 namespace Fractale
00033 {
00034
00039 struct GFractale
00040 {
00041 std::vector<point> sequence;
00042 unsigned int sequenceSizeMax;
00049 GFractale(unsigned int sequenceSizeMax = 1000)
00050 : sequenceSizeMax(sequenceSizeMax)
00051 {
00052 }
00053
00057 virtual ~GFractale() {};
00058
00067 virtual point initialisation(const point & pInit) = 0;
00068
00078 virtual point suivant(const point & Zn) = 0;
00079
00090 virtual bool fin(const point & Zn) = 0;
00091
00100 virtual std::vector<point> & genererSequence(const point &pInit)
00101 {
00102 sequence.clear();
00103
00104 point z = initialisation(pInit);
00105 for ( unsigned int i = 0; !fin(z) && i < sequenceSizeMax ; ++i)
00106 {
00107
00108 z = suivant(z);
00109 sequence.push_back(z);
00110 }
00111
00112 if(!fin(z))
00113 {
00114 sequence.clear();
00115 }
00116 return sequence;
00117 }
00118
00119 };
00120
00129 class Mandelbrot : public GFractale
00130 {
00131 const point z0;
00132 point c;
00133 public:
00134
00135 Mandelbrot(const point & z0 = point())
00136 : z0(z0)
00137 {}
00138 point initialisation(const point & pInit)
00139 {
00140 c = pInit;
00141 return z0;
00142 }
00143
00144 point suivant(const point &Zn)
00145 {
00146 return Zn * Zn + c;
00147 }
00155 bool fin(const point & Zn)
00156 {
00157 return Zn.real() * Zn.real() + Zn.imag() * Zn.imag() > 4;
00158 }
00159 };
00168 struct BateauEnFeu : public GFractale
00169 {
00170 point c;
00171 public:
00172
00173 point initialisation(const point & pInit)
00174 {
00175 c = pInit;
00176 return point();
00177 }
00178 point suivant(const point & Zn)
00179 {
00180 point Znt = point(fabs(Zn.real()), fabs(Zn.imag()));
00181 return Znt * Znt + c;
00182 }
00186 bool fin(const point & Zn)
00187 {
00188 return Zn.real() * Zn.real() + Zn.imag() * Zn.imag() > 4;
00189 }
00190 };
00199 struct Tricorn : public GFractale
00200 {
00201 point c;
00202 public:
00203
00204 point initialisation(const point & pInit)
00205 {
00206 c = pInit;
00207 return point();
00208 }
00209
00210 point suivant(const point &Zn)
00211 {
00212 point Znt = point(-Zn.real(), Zn.imag());
00213 return Znt * Znt + c;
00214 }
00218 bool fin(const point & Zn)
00219 {
00220 return Zn.real() * Zn.real() + Zn.imag() * Zn.imag() > 4;
00221 }
00222 };
00223
00231 class Julian : public GFractale
00232 {
00233 const point c;
00234 public:
00235 Julian( const point & c = point())
00236 : c(c)
00237 {}
00238
00239 point initialisation(const point & pInit)
00240 {
00241 return pInit;
00242 }
00243 point suivant(const point &Zn)
00244 {
00245 return Zn * Zn + c;
00246 }
00250 bool fin(const point & Zn)
00251 {
00252 return Zn.real() * Zn.real() + Zn.imag() * Zn.imag() > 4;
00253 }
00254
00255 };
00256
00265 struct Newton : public GFractale
00266 {
00267 point initialisation(const point & pInit)
00268 {
00269 return pInit;
00270 }
00271 point suivant(const point &Zn)
00272 {
00273 return Zn - (Zn * Zn * Zn - 1.) / (3. * Zn * Zn );
00274 }
00275 bool fin(const point & Zn)
00276 {
00277 return std::abs(Zn * Zn * Zn - 1.) < 0.01;
00278 }
00279 };
00280
00292 struct Nova : public GFractale
00293 {
00294 point old;
00295 point c;
00296 public:
00297 Nova(unsigned int sequenceSizeMax = 1000)
00298 :GFractale(sequenceSizeMax)
00299 {
00300
00301 }
00302 point initialisation(const point & pInit)
00303 {
00304 old =point();
00305 c = pInit;
00306 return point(1.);
00307 }
00308
00309 point suivant(const point &Zn)
00310 {
00311 old = Zn;
00312 return Zn - 2. * (Zn * Zn * Zn - 1.) / (3. * Zn * Zn ) + c;
00313 }
00314
00324 bool fin(const point &z)
00325 {
00326 return std::abs(z - old) <0.05;
00327 }
00328 };
00329
00339 struct CliffordAttractors : public GFractale
00340 {
00341 const double a;
00342 const double b;
00343 const double c;
00344 const double d;
00345 CliffordAttractors(double a =-1.4, double b = 1.6, double c = 1.0,double d = 0.7)
00346 :GFractale(10000),a(a),b(b),c(c),d(d){}
00347
00348 point initialisation(const point & pInit)
00349 {
00350 return pInit;
00351 }
00352
00353 point suivant(const point &Zn)
00354 {
00355
00356 return point
00357 (
00358 sin(a * Zn.imag()) + c * cos(a * Zn.real()),
00359 sin(b * Zn.real()) + d * cos(b * Zn.imag())
00360 );
00361 }
00362
00371 bool fin(const point &Zn)
00372 {
00373 return false;
00374 }
00375
00376 virtual std::vector<point> & genererSequence(const point & c)
00377 {
00378 sequence.clear();
00379 sequence.push_back(c);
00380
00381 point z = initialisation(c);
00382 for ( unsigned int i = 0; i < sequenceSizeMax ; ++i)
00383 {
00384 z = suivant(z);
00385 sequence.push_back(z);
00386 }
00387 return sequence;
00388 }
00389 };
00390 }
00391 #endif