Aller au contenu

Mathc initiation/a247

Un livre de Wikilivres.


Sommaire


Installer ce fichier dans votre répertoire de travail.

kbezier.h
/* --------------------------------- */
/* save as kbezier.h                 */
/* --------------------------------- */
void G_quadratic_Bezier_2d(
CTRL_splot w,

pt2d P0,
pt2d P1,
pt2d P2
)
{
tvalue t;

  t.min  =   0;  
  t.max  =   1;  
  t.step = .01;

FILE   *fp  = fopen("a_main.plt","w");
fprintf(fp," reset\n"
           " set zeroaxis lt 8\n"
           " set grid\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
//           " \"circle\"  with linesp lt 1 pt 1,\\\n"
           " \"curve\"  with linesp lt 3 pt 1,\\\n"
           " \"ctrlpt\" with linesp lt 4 pt 4 \n\n",
             w.xmin,w.xmax,w.ymin,w.ymax);
 fclose(fp);

        fp = fopen("curve","w");
 for(t.value=t.min; t.value<=t.max; t.value+=t.step)
     fprintf(fp," %6.5f   %6.5f\n",
                quadratic_Bezier_x_2d(t.value,P0,P1,P2),
                quadratic_Bezier_y_2d(t.value,P0,P1,P2));
             fclose(fp);

        fp = fopen("ctrlpt","w");
     fprintf(fp," %6.5f   %6.5f\n",P0.x,P0.y);
     fprintf(fp," %6.5f   %6.5f\n",P1.x,P1.y);
     fprintf(fp," %6.5f   %6.5f\n",P2.x,P2.y);
             fclose(fp);
             
 fp = fopen("circle","w");
    for(t.value=0;t.value<2.01*PI;t.value+=.05)
        fprintf(fp," %6.5f %6.5f\n",5*cos(t.value)+0,5*sin(t.value)+0);
 fclose(fp);
}

/* ----------------------------------------------------- */
void G_wp_quadratic_Bezier_2d(

CTRL_splot w,

pt2d P0,
pt2d P1,
pt2d P2
)
{
tvalue t;

  t.min  =   0;  
  t.max  =   1;  
  t.step = .01;

FILE   *fp = fopen("a_main.plt","w");
fprintf(fp," reset\n"
           " set zeroaxis lt 8\n"
           " set grid\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
//           " \"circle\"  with linesp lt 1 pt 1,\\\n"
           " \"curve\" with linesp lt 3 pt 1 \n\n",
             w.xmin,w.xmax,w.ymin,w.ymax);
 fclose(fp);

        fp = fopen("curve","w");
 for(t.value=t.min; t.value<=t.max; t.value+=t.step)
     fprintf(fp," %6.5f   %6.5f\n",
                quadratic_Bezier_x_2d(t.value,P0,P1,P2),
                quadratic_Bezier_y_2d(t.value,P0,P1,P2));
             fclose(fp);

 fp = fopen("circle","w");
    for(t.value=0;t.value<2.01*PI;t.value+=.05)
        fprintf(fp," %6.5f %6.5f\n",5*cos(t.value)+0,5*sin(t.value)+0);
 fclose(fp);
}
/* --------------------------------- */
/* --------------------------------- */