Aller au contenu

Mathc gnuplot/Application : Cercle de courbure d'une courbe

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


N'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.

c01.c
Dessiner un cercle de courbure pour une fonction (f(t),g(t))
/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fb.h"
/* ------------------------------------ */
int main(void)
{
double t = PI;
double e = .001;
char   Name[FILENAME_MAX] = "a_circle.plt";

     circle(Name,
               1./fabs(Kt_2d(f,g,t,e)),
                  cx_2d(f,g,t,e),
                  cy_2d(f,g,t,e));

     G_C_2d(i_WGnuplot(-4,8,-2,4),
            i_time(0.,2*PI,.03),
             f,g,t,
             e);

 printf(" The curvature K of a smooth parametric"
        " curve C is :\n\n\n"

        " K = |f' g'' - g' f''| / "
        "[ (f')^2 - (g')^2 ]^(3/2)\n\n"

        " If P(f(t),g(t)) is a point on the curve  \n"
        " at which K != 0. The point M(h,k)"
        " is the center\n"
        " of the cuvature for P if   \n\n\n"
        " h = f - g'[f'^2 + g'^2] / [f'g''-f''g']\n"
        " k = g + f'[f'^2 + g'^2] / [f'g''-f''g']\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
Tangente23
Résultat dans gnuplot
Tangente24
Résultat dans gnuplot
Tangente25


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 Kt_2d(
double (*P_f)(double t),
double (*P_g)(double t),
double t,
double e
)
{
double K;
double a;
double b;

a = fx_x((*P_f),t,e);
b = fx_x((*P_g),t,e);

K = fabs(a*fx_xx((*P_g),t,e)-b*fx_xx((*P_f),t,e))
                /
     pow(a*a+b*b,3./2.);

 return(K);
}
/* ------------------------------------ */
double cx_2d(
double (*P_f)(double t),
double (*P_g)(double t),
double t,
double e
)
{
double Num,Den;

 Num =( pow(fx_x((*P_f),t,e),2)
       +pow(fx_x((*P_g),t,e),2)
      )
      *fx_x((*P_g),t,e);

 Den = fx_x((*P_f),t,e)*fx_xx((*P_g),t,e)-
       fx_x((*P_g),t,e)*fx_xx((*P_f),t,e);

 return((*P_f)(t)-Num/Den);
}
/* ------------------------------------ */
double cy_2d(
double (*P_f)(double t),
double (*P_g)(double t),
double t,
double e
)
{
double Num,Den;

 Num =( pow(fx_x((*P_f),t,e),2)
       +pow(fx_x((*P_g),t,e),2)
      )
      *fx_x((*P_f),t,e);

 Den = fx_x((*P_f),t,e)*fx_xx((*P_g),t,e)-
       fx_x((*P_g),t,e)*fx_xx((*P_f),t,e);

 return((*P_g)(t)+Num/Den);
}


fb.h
La fonction à dessiner
/* ------------------------------------ */
/*  Save as :   fb.h                    */
/* ------------------------------------ */
double f(
double t)
{
        return( 4+sin(2*t) );
}
char  feq[] =  "4+sin(2*t)";
/* ------------------------------------ */
double g(
double t)
{
        return( 1-2*cos(3*t) );
}
char  geq[] =  "1-2*cos(3*t)";


kg_c.h
La fonction graphique
/* ------------------------------------ */
/*  Save as :   kg_c.h                  */
/* ------------------------------------ */
void G_C_2d(
W_Ctrl W,
t_Ctrl T,
double (*P_f)(double x),
double (*P_g)(double x),
double x,
double e
)
{
FILE *fp;
double i;

        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_curve.plt\" with line,\\\n"
           " \"a_circle.plt\" with line\n",
           W.xmini,W.xmaxi,W.ymini,W.ymaxi);
 fclose(fp);

        fp = fopen("a_curve.plt","w");
for(i=T.mini; i<=T.maxi; 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," %6.5f   %6.5f\n",cx_2d((*P_f),(*P_g),x,e),
                              cy_2d((*P_f),(*P_g),x,e));
fprintf(fp," %6.5f   %6.5f\n",(*P_f)(x),(*P_g)(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);
}