Mathc gnuplot/Animation : Cardioïde
Apparence
Préambule
[modifier | modifier le wikicode]La cardioï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 cardioïde |
---|
/* ------------------------------------ */
/* Save as : c01.c */
/* ------------------------------------ */
#include "x_ahfile.h"
/* ------------------------------------ */
int main(void)
{
double x;
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=0;x<2.01*PI;x+=.03)
G_C_2d(i_WGnuplot(-10.,10,-5.,5.),
i_time(0.,2.*PI,.1),
f,g,x);
printf(" Press return to continue\n");
getchar();
return 0;
}
Le résultat.
Résultat dans gnuplot |
---|
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)
{
double a=1;
return( a*(2*cos(t)-cos(2*t)));
}
char feq[] = "a*(2*cos(t)-cos(2*t))";
/* ------------------------------------ */
double g(
double t)
{
double a=1.;
return( a*(2*sin(t)-sin(2*t)));
}
char geq[] = "a*(2*sin(t)-sin(2*t))";
kg_curve.h La fonction graphique |
---|
/* ------------------------------------ */
/* Save as : kg_curve.h */
/* ------------------------------------ */
void G_C_2d(
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_circle.plt\" with line,\\\n"
" \"b_circle.plt\" with line,\\\n"
" \"a_curve.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 %6.5f\n",2*cos(x)+0,2*sin(x)+0);
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)+0,sin(t)+0);
fclose(fp);
fp = fopen("b_circle.plt","w");
for(t=0;t<2.01*PI;t+=.1)
fprintf(fp," %6.5f %6.5f\n",
cos(t)+2*cos(x),sin(t)+2*sin(x));
fclose(fp);
Pause();
}