Aller au contenu

Mathc gnuplot/Animation : Tangente d'une courbe

Un livre de Wikilivres.
Mathc gnuplot
Mathc gnuplot
Mathc gnuplot
Sommaire

I - Dessiner

Fichiers h partagés :

Application :

II - Animer

Application :

III - Géométrie de la tortue standard

Application :

IV - Géométrie de la tortue vectorielle

Application :

Annexe


La tangente dans Wikipedia.

Voir l'introduction pour créer une animation avec gnuplot sous windows ou linux.


N'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.

Animer la tangente

[modifier | modifier le wikicode]

Nous utilisons ici la méthode avec la commande "pause 1" de gnuplot.


c01.c
Animer la tangente
/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fe.h"
/* ------------------------------------ */
int main(void)
{

 printf(" Let C be the curve consisting of all"
        " ordered pairs (f(t),g(t)).\n\n"
        " With\n\n"
        " f : t-> %s\n\n"
        " g : t-> %s\n\n", feq, geq);

  G_NormalA( i_WGnuplot(-10.,10.,-5.,5.),
             i_time( .1,2.*PI,.05),
             i_time(0.0,2.*PI,.05),
             f,
             g,
          DgDf);

 printf(" To see the curve C, open the file \"a_main.plt\""
        " with Gnuplot.\n\n"
        "\n Press return to continue");
 getchar();

 return 0;
}


Le résultat dans a_main.plt

 # Gnuplot file : load "a_main.plt"

 set zeroaxis
 set size ratio -1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -0.052250*x +3.015895, 19.138612*x -8.326680
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -0.082980*x +3.038500, 12.051102*x -7.517315
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -0.120357*x +3.076117, 8.308636*x -6.442618
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -0.169064*x +3.137218, 5.914933*x -5.156957
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -0.237705*x +3.238412, 4.206886*x -3.724725
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -0.344572*x +3.415897, 2.902154*x -2.216673
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -0.537340*x +3.764826, 1.861020*x -0.705905
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -0.993042*x +4.639209, 1.007007*x +0.736221
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 -3.388779*x +9.393329, 0.295092*x +2.044043
 pause 1
 plot [-10.000:10.000] [-5.000:5.000]\
 "data.plt" with linesp lt 3 pt 1,\
 3.303093*x -4.027901, -0.302747*x +3.161169
 pause 1
 reset


Résultat dans gnuplot
Tangente15
Résultat dans gnuplot
Tangente16


Les fichiers h de ce chapitre

[modifier | modifier le wikicode]
x_ahfile.h
Appel des fichiers
/* ------------------------------------ */
/*  Save as :   x_ahfile.h              */
/* ------------------------------------ */
#include    <stdio.h>
#include   <stdlib.h>
#include    <ctype.h>
#include     <time.h>
#include     <math.h>
#include   <string.h>
/* ------------------------------------ */
#include     "xdef.h"
#include     "xplt.h"
/* ------------------------------------ */
#include   "kg_tan.h"


fe.h
La fonction à dessiner
/* ------------------------------------ */
/*  Save as :   fe.h                    */
/* ------------------------------------ */
double f(
double t)
{
double a=2;
double k1=3;

        return( a*sin(k1*t) );
}
char  feq[] =  "a*sin(k1*t)";
/* ------------------------------------ */
double Df(
double t)
{
double a=2;
double k1=3;

        return( a*cos(k1*t)*k1);
}
char  Dfeq[] =  "a*cos(k1*t)*k1";
/* ------------------------------------ */
double g(
double t)
{
double b =3;
double k2=1;
        return( b*cos(k2*t) );
}
char  geq[] =  "b*cos(k2*t)";
/* ------------------------------------ */
double Dg(
double t)
{
double b =3;
double k2=1;
        return(  -b*sin(k2*t)*k2 );
}
char  Dgeq[] =  "-b*sin(k2*t)*k2";
/* ------------------------------------ */
double DgDf(
double t)
{
        return(Dg(t)/Df(t));
}


kg_tan.h
La fonction graphique
/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
void G_NormalA(
W_Ctrl W,
t_Ctrl C,
t_Ctrl T,
double (*P_f)  (double t),
double (*P_g)  (double t),
double (*PDgDf)(double t)
)
{
FILE   *fp;
double c;
double t;

        fp = fopen("a_main.plt","w");
fprintf(fp,"# Gnuplot file : load \"a_main.plt\" \n\n"
           " set zeroaxis\n"
           " set size ratio -1\n");

for(c=C.mini; c<C.maxi; c+=C.step)
{
fprintf(fp," plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
           " \"data.plt\" with linesp lt 3 pt 1,\\\n"
           " %0.6f*x %+0.6f,"
           " %0.6f*x %+0.6f\n"
           " pause 1\n",
        W.xmini,W.xmaxi,W.ymini,W.ymaxi,
    (*PDgDf)(c),
            (-(*PDgDf)(c)*(*P_f)(c)+(*P_g)(c)),
-1./(*PDgDf)(c),
        -1./(-(*PDgDf)(c))*(*P_f)(c)+(*P_g)(c));
}
fprintf(fp," reset");
 fclose(fp);

        fp = fopen("data.plt","w");
 for(t=T.mini; t<=T.maxi; t+=T.step)
     fprintf(fp," %6.6f   %6.6f\n",
                (*P_f)(t),(*P_g)(t));
 fclose(fp);
}