Précédent   Forum du club des développeurs et IT Pro > Environnements de développement > MATLAB > Téléchargez
Téléchargez Récupérez et commentez les sources et outils mis à disposition par la rubrique MATLAB
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 07/09/2009, 11h34   #1
Dut
Responsable MATLAB & Hardware/PC

 
Avatar de Dut
 
Inscription : novembre 2006
Messages : 15 079
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 15 079
Points : 31 130
Points : 31 130
Par défaut [Fractales 3/5] Arbre de Pythagore - Pythagoras tree



un petit code rapide qui génère un arbre de Pythagore (Pythagoras Tree en anglais) pour un nombre d'itérations donné :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function [v,th,L] = pythagorastree(N)
%PYTHAGORASTREE
%
%

% Author : Jerome Briot (Dut)
% Contact : dutmatlab#yahoo#fr -or- briot#cict#fr
% Profil : www.mathworks.com/matlabcentral/newsreader/author/94805
%        : www.developpez.net/forums/u125006/dut/
%
% Version : 1.0 - 07 Sep 2009
%

% MATLAB : 7.6.0.324 (R2008a)
% System : Linux 2.6.24-24-generic
%

error(nargchk(1,1,nargin));

a = sqrt(2)/2;
xy = [0 -a 0 a 2*a 3*a 2*a; 0 a 2*a a 2*a a 0].';

v{1} = [-.5 1];
th{1} = 0;
L = ones(1,N+1);

for n = 1:N
    L(n+1) = a;
    xy = xy*L(n+1);

    for q = 1:size(v{n},1)

        temp = [xy ones(size(xy,1),1)] * [cos(th{n}(q)) sin(th{n}(q)) 0 ; -sin(th{n}(q)) cos(th{n}(q)) 0 ; v{n}(q,:) 1];

        v{n+1}((q-1)*2+1,:) = temp(2,1:2);
        v{n+1}(2*q,:) = temp(5,1:2);

        th{n+1}((q-1)*2+1) = th{n}(q)+pi/4;
        th{n+1}(2*q) = th{n}(q)+-pi/4;

    end

end
et une fonction permettant d'afficher cet arbre pour un nombre d'itérations donné :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function drawpythagorastree(N)
%DRAWPYTHAGORASTREE
%
%

% Author : Jerome Briot (Dut)
% Contact : dutmatlab#yahoo#fr -or- briot#cict#fr
% Profil : www.mathworks.com/matlabcentral/newsreader/author/94805
%        : www.developpez.net/forums/u125006/dut/
%
% Version : 1.0 - 07 Sep 2009
%

% MATLAB : 7.6.0.324 (R2008a)
% System : Linux 2.6.24-24-generic
%

if nargin == 0
    N = 10;
end

[v,th,L] = pythagorastree(N);

a = sqrt(2)/2;
xy = [0 -a 0 a 2*a 3*a 2*a; 0 a 2*a a 2*a a 0].';

col = flipud(summer(N+1));

figure('color','w','numbertitle','off')

vertices = [-.5 .5 .5 -.5 ; 0 0 1 1].';
patch('vertices',vertices,'faces',1:4,'facecolor',col(1,:),'edgecolor',col(1,:));

hold on

for n = 1:N
    
    xy = xy*L(n+1);

    for q = 1:size(v{n},1)

        temp = [xy ones(size(xy,1),1)] * [cos(th{n}(q)) sin(th{n}(q)) 0 ; -sin(th{n}(q)) cos(th{n}(q)) 0 ; v{n}(q,:) 1];
        patch('vertices',temp,'faces',[1:7 4],'facecolor',col(n+1,:),'edgecolor',col(n+1,:));

    end

end

str = sprintf('Pythagoras Tree (%d iterations)',N);
title(str)

axis equal off
Voila... si vous avez des remarques, des questions ou des suggestions, n'hésitez pas

Mais rappelez-vous que je ne suis pas un spécialiste dans ce domaine

Note : Ne sachant pas si ces codes sont justes, je ne les ai pas optimisés (et donc pas commentés)
Images attachées
Type de fichier : gif pythagorastree.gif (14,5 Ko, 34 affichages)
Fichiers attachés
Type de fichier : zip pythagorastree.zip (1,6 Ko, 3 affichages)
__________________
Identification de processeur sous MATLAB (3/3) Identification de processeur sous MATLAB (2/3) Mes contributions MATLAB (R2009a - Windows & Linux)

J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" (Saint Huck)
Dut est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2010, 09h31   #2
Dut
Responsable MATLAB & Hardware/PC

 
Avatar de Dut
 
Inscription : novembre 2006
Messages : 15 079
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 15 079
Points : 31 130
Points : 31 130
Pour infos, une version plus complète vient d'être postée sur le FEX : Pythagoras tree par Guillaume JACQUENOT

Elle permet, entre autre, d'obtenir un arbre non-symétrique et d'exporter le résultat au format http://fr.wikipedia.org/wiki/Svg
__________________
Identification de processeur sous MATLAB (3/3) Identification de processeur sous MATLAB (2/3) Mes contributions MATLAB (R2009a - Windows & Linux)

J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" (Saint Huck)
Dut est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 21h53.


 
 
 
 
Partenaires

Hébergement Web