Mathc gnuplot/Application : Cercle de courbure
Apparence
Préambule
[modifier | modifier le wikicode]Le cercle de courbure dans Wikipedia.
Présentation
[modifier | modifier le wikicode]N'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.
Dessiner
[modifier | modifier le wikicode]c01.c Dessiner un cercle de courbure pour une fonction f(x). |
---|
/* ------------------------------------ */
/* Save as : c01.c */
/* ------------------------------------ */
#include "x_ahfile.h"
#include "fb.h"
/* ------------------------------------ */
int main(void)
{
double x = 0.;
double e = .001;
char Name[FILENAME_MAX] = "a_circle.plt";
circle(Name,
1./K_y_2d(f,x,e),
h_y_2d(f,x,e),
k_y_2d(f,x,e));
G_C_2d(i_WGnuplot(-4.,4.,-2.,2.),
f,x,e,
feq);
clrscrn();
printf(" If a smooth curve C is the graph of y = f(x),\n"
" then the curvature K at P(x,y) is\n\n\n"
" K = |y''| / [1 + y'^2]^(3/2) \n\n\n"
" If P(x,y) is a point on the graph "
"of y = f(x) \n"
" at which K != 0. The point M(h,k)"
" is the center\n"
" of the cuvature for P if \n\n\n"
" h = x - y'[1 + y'^2] / y'' \n"
" k = y + [1 + y'^2] / y'' \n\n\n"
" The radius is r = 1/K \n\n\n"
" Open the file \"a_main.plt\" with Gnuplot.\n\n");
printf("\n Press return to continue");
getchar();
return 0;
}
Le résultat.
Résultat dans gnuplot |
---|
Résultat dans gnuplot |
---|
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 "xfx_x.h"
/* ------------------------------------ */
#include "kradius.h"
#include "kg_c.h"
#include "kcircle.h"
kradius.h Coordonnées du cercle |
---|
/* ------------------------------------ */
/* Save as : kradius.h */
/* ------------------------------------ */
double K_y_2d(
double (*P_f)(double x),
double x,
double e
)
{
double a = fx_x((*P_f),x,e);
return(fabs(fx_xx((*P_f),x,e))
/
pow(1+a*a,3./2.));
}
/* ------------------------------------ */
double h_y_2d(
double (*P_f)(double x),
double x,
double e
)
{
double a = fx_x((*P_f),x,e);
return(x - ( ( a*(1+a*a) )
/
fx_xx((*P_f),x,e)));
}
/* ------------------------------------ */
double k_y_2d(
double (*P_f)(double x),
double x,
double e
)
{
double a = fx_x((*P_f),x,e);
return((*P_f)(x) + ( (1+a*a)
/
fx_xx((*P_f),x,e)));
}
fb.h La fonction à dessiner |
---|
/* ------------------------------------ */
/* Save as : fb.h */
/* ------------------------------------ */
double f(
double x)
{
return( cos(x));
}
char feq[] = "cos(x)";
kg_c.h La fonction graphique |
---|
/* ------------------------------------ */
/* Save as : kg_c.h */
/* ------------------------------------ */
void G_C_2d(
W_Ctrl W,
double (*P_f)(double x),
double x,
double e,
char feq[]
)
{
FILE *fp;
fp = fopen("a_main.plt","w");
fprintf(fp," reset\n"
" set zeroaxis lt 8\n"
" set size ratio -1\n"
" set grid\n\n"
" plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
" \"a_radius.plt\" with linespoints,\\\n"
" \"a_circle.plt\" with line,\\\n"
" %s with line\n",
W.xmini,W.xmaxi,W.ymini,W.ymaxi,feq);
fclose(fp);
fp = fopen("a_radius.plt","w");
fprintf(fp," %6.5f %6.5f\n",h_y_2d((*P_f),x,e),
k_y_2d((*P_f),x,e));
fprintf(fp," %6.5f %6.5f\n",x,(*P_f)(x));
fclose(fp);
Pause();
}
kcircle.h Le cercle |
---|
/* ------------------------------------ */
/* Save as : kcircle.h */
/* ------------------------------------ */
void circle(
char Name[FILENAME_MAX],
double r,
double x,
double y
)
{
FILE *fp = fopen(Name,"w");
double t = 0.;
for(;t<2.01*PI;t+=.1)
fprintf(fp," %6.5f %6.5f\n",r*cos(t)+x,r*sin(t)+y);
fclose(fp);
}