Mathc gnuplot/Animation : Vecteur unitaire
Préambule
modifierPrésentation
modifierN'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.
Animer
modifierc01.c Animer a un vecteur normale unitaire et un vecteur tangent unitaire. |
---|
/* ------------------------------------ */
/* Save as : c01.c */
/* ------------------------------------ */
#include "x_ahfile.h"
#include "fb.h"
/* ------------------------------------ */
int main(void)
{
double t=0.;
printf(" r(t) = f(t)i + g(t)j \n\n"
" With \n\n"
" f : t-> %s \n"
" g : t-> %s\n\n",feq,geq);
printf("\n\n Open the file \"a_main.plt\" with Gnuplot."
"\n\n Use the \"replot\" command of gnuplot.\n\n");
for(;t<4.*PI;t+=.05)
G_Curve_2d(i_WGnuplot(-2,2,-2,2),
i_time( 0.,4.*PI,.05),
f,g,Tf,Tg,
t);
printf(" Press return to continue\n");
getchar();
return 0;
}
Le résultat.
Résultat dans gnuplot |
---|
Les fichiers h partagés
modifierx_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 "xfx_x.h"
/* ------------------------------------ */
#include "knfx_x.h"
#include "kg_ctan1.h"
knfx_x.h Normalisé |
---|
/* ------------------------------------ */
/* Save as : knfx_x.h */
/* ------------------------------------ */
double fx_x_Normalize(
double (*P_f)(double x),
double (*P_g)(double x),
double t,
double e
)
{
double Df=fx_x((*P_f),t,e);
double Dg=fx_x((*P_g),t,e);
return(Df/sqrt(Df*Df+Dg*Dg));
}
fb.h La fonction à dessiner |
---|
/* ------------------------------------ */
/* Save as : fb.h */
/* ------------------------------------ */
double f(
double t)
{
return( cos(t)*cos(t));
}
char feq[] = "cos(t)**2";
/* ------------------------------------ */
double g(
double t)
{
return( 2*sin(t));
}
char geq[] = "2*sin(t)";
/* ------------------------------------ */
double Tf(
double t)
{
return(
(-cos(t)*sin(t))
/
sqrt(pow(cos(t),2)*pow(sin(t),2)+pow(cos(t),2)));
}
/* ------------------------------------ */
double Tg(
double t)
{
return(
cos(t)
/
sqrt(pow(cos(t),2)*pow(sin(t),2)+pow(cos(t),2)));
}
/* ------------------------------------ */
kg_ctan1.h La fonction graphique |
---|
/* ------------------------------------ */
/* Save as : kg_ctan1.h */
/* ------------------------------------ */
void G_Curve_2d(
W_Ctrl W,
t_Ctrl T,
double (*P_f)(double t),
double (*P_g)(double t),
double (*P_Tf)(double t),
double (*P_Tg)(double t),
double t
)
{
FILE *fp;
double i;
double e=.001;
fp = fopen("a_main.plt","w");
fprintf(fp," reset\n"
" set zeroaxis lt 8\n"
" set grid\n\n"
" set size ratio -1\n"
" plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
" \"a_curve.plt\" with line lt 3,\\\n"
" \"a_radius.plt\" with line lt 2,\\\n"
" \"a_vector.plt\" with line lt 4,\\\n"
" \"a_normal.plt\" with line lt 1 \n",
W.xmini,W.xmaxi,W.ymini,W.ymaxi);
fclose(fp);
fp = fopen("a_curve.plt","w");
for(i=T.mini; i<=T.maxi+T.step; i+=T.step)
fprintf(fp," %6.3f %6.3f\n",(*P_f)(i),(*P_g)(i));
fclose(fp);
fp = fopen("a_radius.plt","w");
fprintf(fp," 0 0 \n %6.5f %6.5f \n",
(*P_f)(t),(*P_g)(t));
fclose(fp);
fp = fopen("a_vector.plt","w");
fprintf(fp," %6.5f %6.5f \n %6.5f %6.5f \n",
(*P_f)(t),
(*P_g)(t),
(*P_f)(t)+fx_x_Normalize((*P_f),(*P_g),t,e),
(*P_g)(t)+fx_x_Normalize((*P_g),(*P_f),t,e) );
fclose(fp);
fp = fopen("a_normal.plt","w");
fprintf(fp," %6.5f %6.5f \n %6.5f %6.5f \n",
(*P_f)(t),
(*P_g)(t),
(*P_f)(t)+fx_x_Normalize((*P_Tf),(*P_Tg),t,e),
(*P_g)(t)+fx_x_Normalize((*P_Tg),(*P_Tf),t,e) );
fclose(fp);
Pause();
}