Mathc gnuplot/Animation : Rosace

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]

Coordonnées polaires 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 rosace
/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fr.h"
/* ------------------------------------ */
int main(void)
{
double maxi;

 printf(" r : t-> %s\n\n", req);

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

 for(maxi=0;maxi<=2.*PI+.1;maxi+=.1)

     G_polar(i_WGnuplot(-1.,1.,-1.,1.),
             i_time(0,maxi,0.01),
             r);

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

Le résultat.

Résultat dans gnuplot
Curve03
Résultat dans gnuplot
Curve04


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_polar.h"


fr.h
La fonction à dessiner
/* ------------------------------------ */
/*  Save as :   fr.h                    */
/* ------------------------------------ */
double r(
double t)
{
double n=4;

        return( sin(n*t));
}
char  req[] =  "sin(n*t)";


kg_polar.h
La fonction graphique
/* ------------------------------------ */
/*  Save as :   kg_polar.h              */
/* ------------------------------------ */
void G_polar(
W_Ctrl W,
t_Ctrl T,
double (*P_r)(double k)
)
{
FILE   *fp;
double  t;

        fp = fopen("a_main.plt","w");
fprintf(fp," set size ratio -1\n"
           " set polar\n"
           " set grid polar\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " \"a_curve.plt\" with line lt 3, \\\n"
           " \"a_radius.plt\" with linesp lt 1 pt 1",
           0., 2.*PI,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.3f   %6.3f\n",t,(*P_r)(t));
 fclose(fp);

          fp = fopen("a_radius.plt","w");
  fprintf(fp," 0.  0. \n  %6.3f  %6.3f\n",
            t-T.step,(*P_r)(t-T.step));
 fclose(fp);

    Pause();
}