Mathc gnuplot/Animation : Cycloïde

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

Livre d'or



Préambule[modifier | modifier le wikicode]

La cycloïde dans Wikipedia.

Présentation[modifier | modifier le wikicode]

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

Animer[modifier | modifier le wikicode]

c01.c
Animer une cycloide
/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
/* ------------------------------------ */
int main(void)
{
double x=0;

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

printf("\n\n Open the file \"a_main.plt\" with Gnuplot."
       "\n\n Use the \"replot\" command of gnuplot.\n\n");

 for(;x<4*PI;x+=.1)

   G_CurveA(i_WGnuplot(-1.,14,-1.,6.),
            i_time(0.,4.*PI,.01),
            f,g,
            x);

 printf(" Press return to continue\n");
 getchar();

 return 0;
}

Le résultat.

Résultat dans gnuplot
Curve01


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    "curve.h"
#include "kg_curve.h"


curve.h
La fonction à dessiner
/* ------------------------------------ */
/*  Save as :   curve.h                 */
/* ------------------------------------ */
double f(
double t)
{
        return(1*t-sin(t));
}
char  feq[] = "1*t-sin(t)";
/* ------------------------------------ */
double g(
double t)
{
        return(1-cos(t));
}
char  geq[] = "1-cos(t)";
/* ------------------------------------ */


kg_curve.h
La fonction graphique
/* ------------------------------------ */
/*  Save as :   kg_curve.h              */
/* ------------------------------------ */
void G_CurveA(
W_Ctrl W,
t_Ctrl T,
double (*P_f)(double t),
double (*P_g)(double t),
double x
)
{
FILE   *fp;
double  t;

        fp = fopen("a_main.plt","w");
fprintf(fp," reset\n"
           " set zeroaxis lt 8\n"
           " set size ratio -1\n"
           " set grid\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " \"a_curve.plt\" with line, \\\n"
           " \"a_circle.plt\" with line,\\\n"
           " \"a_radius.plt\" with linesp",
     W.xmini,W.xmaxi,W.ymini,W.ymaxi);
 fclose(fp);

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

        fp = fopen("a_radius.plt","w");
  fprintf(fp," %6.5f   1.000\n",x);
  fprintf(fp," %6.5f   %6.5f\n",(*P_f)(x),(*P_g)(x));
  fclose(fp);

        fp = fopen("a_circle.plt","w");
  for(t=0;t<2.01*PI;t+=.1)
     fprintf(fp," %6.5f %6.5f\n",cos(t)+x,sin(t)+1);
  fclose(fp);

  Pause();
}