IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Téléchargez Discussion :

Graphique avec Hachures


Sujet :

Téléchargez

  1. #1
    Membre éprouvé

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2007
    Messages
    979
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 979
    Points : 1 256
    Points
    1 256
    Par défaut Graphique avec Hachures
    La fonction suivante trace les graphiques de deux fonctions, et hachure la surface entre les deux courbes :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
     
    function p_handle = hatching(f,g,xx,option)
    % Hatching Area between two graphics
    % f,g : functions 
    % xx  : graphic support  
    % option : ploting options
    % See 'DEMO MODE' for exemples
     
    % Hassan Ijtihadi
    % ijtihah6 at gmail dot com
    % v1.0  9/04/2008
     
     
    if nargin < 4
        % CHANGE OPTIONS HERE
        option.angle = 0.25*pi;  % 45°
        option.size = 40;  
        option.margin = 0.1;
        option.color = 'red';
    end
     
     
    if nargin < 3
        %---------------------------
        % DEMO MODE
        p = floor(3*rand()-eps)+1;
        switch p
            case 1
                f = @cos;
                g = @sin;
                xx = 0:0.05:2*pi;
            case 2
                f = @(x)(x.^1.5);
                g = @sin;
                xx = 0:0.05:2*pi;    
           case 3
                f = @(x)(ones(1,length(x)));
                g = @(x)(zeros(1,length(x)));
                xx = 0:0.05:2*pi;  
        end
    end
     
     
    % Bounds & variables
    d = [cos(option.angle) sin(option.angle)];
    FMin = min([f(xx) ; g(xx)]);
    FMax = max([f(xx) ; g(xx)]);
     
    dxx = max(xx) - min(xx);
    m = min(xx);
     
    % hatching
    Xmin = linspace(min(FMin)-(d(2)/d(1))*dxx,max(FMax),option.size);
    Xmax = linspace(min(FMin),max(FMax)+(d(2)/d(1))*dxx,option.size);
     
     
    % Local Functions
    DFMIN = @(x,x0) (min([f(x+m);g(x+m)])-(d(2)/d(1))*x-x0);
    DFMAX = @(x,x0) (max([f(x+m);g(x+m)])-(d(2)/d(1))*x-x0);
    ZF = @(x)(find(x(1:end-1).*x(2:end)<=0));
     
    H = [];
     
    XX = xx-m;
     
     
    Xstart = Xmin >= FMin(1) & Xmin <= FMax(1);
    Xend = Xmax >= FMin(end) & Xmax <= FMax(end);
     
    %------------------------------------
    % MAIN LOOP
    for i=1:length(Xmin)
     
        x_min = DFMIN(XX, Xmin(i));
        x_max = DFMAX(XX, Xmin(i));
     
        zx_min = ZF(x_min);
        zx_max = ZF(x_max);
     
        Xtmp = [xx(zx_min)' min([f(xx(zx_min));g(xx(zx_min))])'];
        Xtmp = [Xtmp; xx(zx_max)' max([f(xx(zx_max));g(xx(zx_max))])'];
     
        [tmp ,IX] = sort(Xtmp(:,1));
        Xtmp = Xtmp(IX,:);
     
        % Add Start Points
        if Xstart(i)
            Xtmp = [xx(1) Xmin(i); Xtmp];
        end
        % Add End Points
        if Xend(i)
            Xtmp = [Xtmp; xx(end) Xmax(i)];
        end
     
        for j=1:2:(size(Xtmp,1)-mod(size(Xtmp,1),2))
            H = [H; Xtmp(j,:) Xtmp(j+1,:)];
        end
    end
     
    %-----------------------------
    % Plot Lines
    m = option.margin;
    p_handle = plot(xx,f(xx),xx,g(xx));
    xlim([min(xx)-m*(max(xx)-min(xx)) max(xx)+m*(max(xx)-min(xx))])
    ylim([min(FMin)-m*(max(FMax)-min(FMin)) max(FMax)+m*(max(FMax)-min(FMin))])
    hold on
    for i=1:size(H,1)
        plot(H(i,[1 3]),H(i,[2 4]),'color',option.color)
    end

    Pour tester :

    Amusez vous bien
    ++
    Images attachées Images attachées  
    AlloSchool, votre école sur internet.

Discussions similaires

  1. Graphique avec Turbo Pascal 7
    Par Sagiro dans le forum Turbo Pascal
    Réponses: 3
    Dernier message: 21/12/2004, 09h52
  2. [Free Pascal] Graphique avec Dev-Pascal
    Par CompuTux dans le forum Free Pascal
    Réponses: 15
    Dernier message: 03/09/2004, 02h15
  3. Caractéristique des Graphiques avec Tchart
    Par bidson dans le forum XMLRAD
    Réponses: 5
    Dernier message: 19/01/2004, 11h01
  4. faire des graphiques avec Perl
    Par And_the_problem_is dans le forum Modules
    Réponses: 2
    Dernier message: 16/07/2003, 16h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo