« Mathc gnuplot/Animation : Fonction vectorielle 3D » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 8 :
* Fonction vectorielle 3D [[ wikipédia]].
* Dans Wikiversité [[http://fr.wikiversity.org/wiki/Mathc_Home_Edition_c15 Mathc Home Edition c15]], une approche empirique.
 
 
= Présentation =
 
* Un exemple à tester.
* (nN'oubliez pas les fichiers *.h) partagés.
* Recuperer aussi ceux du chapitre Dessiner : '''"Fonction vectorielle 3D"'''.
* Pour l'animation il faut cliquer sur l'icône replot de gnuplot.
 
=== Animer ===
Ligne 38 ⟶ 40 :
"\n\n Use the \"replot\" command of gnuplot.\n\n");
 
for(;t<6.*PI;t+=.0105)
 
G_Curve_3d(i_time(0.,6.*PI,.01),
Ligne 67 ⟶ 69 :
|[[File:Curve07.svg|Curve07]]
|}
 
== Les fichiers h partagés ==
 
=== Appel des fichiers standards ===
 
<source lang="c">
/* ------------------------------------ */
/* Save as : x_ahfile.h */
/* ------------------------------------ */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <string.h>
/* ------------------------------------ */
#include "xa_def.h"
#include "xa_strct.h"
#include "kfx_x.h"
#include "kg_ctan1.h"
</source>
 
=== Les defines ===
 
<source lang="c">
/* ------------------------------------ */
/* Save as : xa_def.h */
/* ------------------------------------ */
#ifndef PI
#define PI 3.14159265359
#endif
/* ------------------------------------ */
void clrscrn(void)
{
printf("\n\n\n\n\n\n\n\n\n\n\n"
"\n\n\n\n\n\n\n\n\n\n\n"
"\n\n\n\n\n\n\n\n\n\n\n");
}
/* ------------------------------------ */
void Pause(void)
{
int i=300;
int j;
 
while(--i){j=600000;while(--j);} }
</source>
 
=== Déclaration et initialisation des structures ===
 
<source lang="c">
/* ------------------------------------ */
/* Save as : xa_strct.h */
/* ------------------------------------ */
typedef struct
{
double mini;
double maxi;
double step;
 
}t_Ctrl, *Pt_Ctrl;
/* ------------------------------------ */
t_Ctrl i_time(
double mini,
double maxi,
double step
)
{
t_Ctrl t = {mini,maxi,step};
 
return (t);
}
</source>
 
=== Fonction dérivé ===
 
<source lang="c">
/* ------------------------------------ */
/* Save as : kfx_x.h */
/* ------------------------------------ */
double fx_x(
double (*P_f)(double x),
double a,
double h
)
{
return( ((*P_f)(a+h)-(*P_f)(a-h))/(2.*h) );
}
/* ------------------------------------ */
double fx_x_Normalize(
double (*P_f)(double x),
double (*P_g)(double x),
double (*P_h)(double x),
double t,
double e
)
{
double Df=fx_x((*P_f),t,e);
double Dg=fx_x((*P_g),t,e);
double Dh=fx_x((*P_h),t,e);
 
return(Df/sqrt(Df*Df+Dg*Dg+Dh*Dh));
}
</source>
 
=== La fonction à dessiner ===
 
<source lang="c">
/* ------------------------------------ */
/* Save as : fa.h */
/* ------------------------------------ */
double f(
double t)
{
return( cos(t));
}
char feq[] = "cos(t)";
/* ------------------------------------ */
double g(
double t)
{
return( sin(t));
}
char geq[] = "sin(t)";
/* ------------------------------------ */
double h(
double t)
{
return( t);
}
char heq[] = "t";
/* ------------------------------------ */
double Tf(
double t)
{
return(
-(sin(t)/sqrt(2))
);
}
/* ------------------------------------ */
double Tg(
double t)
{
return(
cos(t)/sqrt(2)
);
}
/* ------------------------------------ */
double Th(
double t)
{
return(
1/sqrt(2)
);
}
</source>
 
=== La fonction graphique ===
 
<source lang="c">
/* ------------------------------------ */
/* Save as : kg_ctan1.h */
/* ------------------------------------ */
void G_Curve_3d(
t_Ctrl T,
double (*P_f)(double t),
double (*P_g)(double t),
double (*P_h)(double t),
double (*P_Tf)(double t),
double (*P_Tg)(double t),
double (*P_Th)(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"
" splot \\\n"
" \"a_curve.plt\" with line lt 3,\\\n"
" \"a_radius.plt\" with line lt 2,\\\n"
" \"atangent.plt\" with line lt 4,\\\n"
" \"anormal.plt\" with line lt 1 ");
fclose(fp);
 
fp = fopen("a_curve.plt","w");
for(i=T.mini; i<=T.maxi; i+=T.step)
fprintf(fp," %6.3f %6.3f %6.3f\n",
(*P_f)(i),
(*P_g)(i),
(*P_h)(i));
fclose(fp);
 
fp = fopen("a_radius.plt","w");
fprintf(fp," 0 0 0 \n %6.5f %6.5f %6.5f \n",
(*P_f)(t),
(*P_g)(t),
(*P_h)(t));
fclose(fp);
 
fp = fopen("atangent.plt","w");
fprintf(fp," %6.5f %6.5f %6.5f \n"
" %6.5f %6.5f %6.5f \n",
(*P_f)(t),
(*P_g)(t),
(*P_h)(t),
(*P_f)(t)+fx_x_Normalize((*P_f),(*P_g),(*P_h),t,e),
(*P_g)(t)+fx_x_Normalize((*P_g),(*P_f),(*P_h),t,e),
(*P_h)(t)+fx_x_Normalize((*P_h),(*P_f),(*P_g),t,e) );
fclose(fp);
 
fp = fopen("anormal.plt","w");
fprintf(fp," %6.5f %6.5f %6.5f \n"
" %6.5f %6.5f %6.5f \n",
(*P_f)(t),
(*P_g)(t),
(*P_h)(t),
(*P_f)(t)+fx_x_Normalize((*P_Tf),(*P_Tg),(*P_Th),t,e),
(*P_g)(t)+fx_x_Normalize((*P_Tg),(*P_Tf),(*P_Th),t,e),
(*P_h)(t)+fx_x_Normalize((*P_Th),(*P_Tf),(*P_Tg),t,e));
fclose(fp);
 
Pause();
}
 
</source>
 
= Algorithme =
 
r(t) = f(t) i + g(t) j + h(t) k
T(t) = r'(t) / ||r'(t)||
N(t) = T'(t) / ||T'(t)||