Mathc matrices/Fichiers c : ckd01

Un livre de Wikilivres.
Sauter à la navigation Sauter à la recherche


Installer et compiler ces fichiers c dans votre répertoire de travail.


Vous trouverez le code source et le fichier graphique correspondant à chaque transformation.

L'étude des matrices de transformation fait partie d'un cours de mathématiques et sort du cadre de ce livre.


Reflection about the x-axis
Crystal Clear mimetype source c.png ckd01.c
'
/* ------------------------------------ */
/*  Save as :   ckd01.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]   ={    1,  0,
                        0, -1 };
double u[R2*C5]   ={    1,  2,  2,  1,  1,
                        1,  1,  2,  2,  1 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Reflection about the x-axis :                  \n");
  printf("\n                |  1  0 |                         ");
  printf("\n           v  = |       |  u                      ");
  printf("\n                |  0 -1 |                     \n\n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,0,C6);

  G_points2D_mR(i_WGnuplot(-3,3,-3,3),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);

  stop();

  return 0;
}
Reflection about the y-axis
Crystal Clear mimetype source c.png ckd02.c
'
/* ------------------------------------ */
/*  Save as :   ckd02.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={   -1,  0,
                      0,  1 };
double u[R2*C5]   ={    1,  2,  2,  1,  1,
                        1,  1,  2,  2,  1 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Reflection about the y-axis :                  \n");
  printf("\n                | -1  0 |                         ");
  printf("\n           v  = |       |  u                      ");
  printf("\n                |  0  1 |                     \n\n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,0,C6);

  G_points2D_mR(i_WGnuplot(-3,3,-3,3),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);
  
  stop();

  return 0;
}
Reflection about the line y = x
Crystal Clear mimetype source c.png ckd03.c
reflexion
/* ------------------------------------ */
/*  Save as :   ckd03.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={    0,  1,
                       1,  0 };
double u[R2*C5]   ={   1,  1, -1, -1,  1,
                       2,  3,  3,  2,  2 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Reflection about the line y = x :              \n");
  printf("\n                | 0  1 |                          ");
  printf("\n           v  = |      |  u                       ");
  printf("\n                | 1  0 |                      \n\n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,0,C6);

  G_points2D_mR(i_WGnuplot(-5,5,-5,5),
                U,V);
                
  f_mR(U);
  f_mR(V);
  f_mR(T);
  
  stop();

  return 0;
}
Orthogonal projection on the x-axis
Crystal Clear mimetype source c.png ckd04.c
'
/* ------------------------------------ */
/*  Save as :   ckd04.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]   ={    1,  0,
                        0,  0 };
double u[R2*C5]   ={    1,  2,  2,  1,  1,
                        1,  1,  2,  2,  1 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =            i_mR(R2,C5);

  clrscrn();

  printf("\n Orthogonal projection on the x-axis :           \n");
  printf("\n                |  1  0 |                          ");
  printf("\n           v  = |       |  u                       ");
  printf("\n                |  0  0 |                      \n\n");
  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,0,C6);

  G_points2D_mR(i_WGnuplot(-.5,2.5,-.5,2.5),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);

  stop();

  return 0;
}
Orthogonal projection on the y-axis
Crystal Clear mimetype source c.png ckd05.c
'
/* ------------------------------------ */
/*  Save as :   ckd05.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={    0,  0,
                       0,  1 };
double u[R2*C5]   ={    1,  2,  2,  1,  1,
                        1,  1,  2,  2,  1 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =            i_mR(R2,C5);

  clrscrn();

  printf("\n Orthogonal projection on the y-axis :           \n");
  printf("\n                |  0  0 |                          ");
  printf("\n           v  = |       |  u                       ");
  printf("\n                |  0  1 |                      \n\n");
  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,0,C6);

 G_points2D_mR(i_WGnuplot(-1,3,-1,3),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);

  stop();

  return 0;
}
Dilation
Crystal Clear mimetype source c.png ckd06.c
'
/* ------------------------------------ */
/*  Save as :   ckd06.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={    2,  0,
                       0,  2 };
double u[R2*C5]  ={    0,  1,  1,  0,  0,
                       0,  0,  1,  1,  0 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Dilation                    :                  \n");
  printf("\n                |  2  0 |                         ");
  printf("\n           v  = |       |  u                      ");
  printf("\n                |  0  2 |                     \n\n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,0,C6);

  G_points2D_mR(i_WGnuplot(-1,3,-1,3),
                U,V);
                
  f_mR(U);
  f_mR(V);
  f_mR(T);

  stop();

  return 0;
}
Contraction
Crystal Clear mimetype source c.png ckd07.c
'
/* ------------------------------------ */
/*  Save as :   ckd07.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={   .5,  0,
                       0,  .5 };
double u[R2*C5]  ={    0,  1,  1,  0,  0,
                       0,  0,  1,  1,  0 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Contraction :                                  \n");
  printf("\n                | .5  0 |                         ");
  printf("\n           v  = |       |  u                      ");
  printf("\n                |  0 .5 |                     \n\n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,3,C6);

  G_points2D_mR(i_WGnuplot(-.5,1.5,-.5,1.5),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);

  stop();

  return 0;
}
Shear in the x-direction with factor k (right)
Crystal Clear mimetype source c.png ckd08.c
'
/* ------------------------------------ */
/*  Save as :   ckd08.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={    1,  2,
                       0,  1 };
double u[R2*C5]  ={    0,  1,  1,  0,  0,
                       0,  0,  1,  1,  0 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Shear in the x-direction with factor k (right):\n");
  printf("\n                |  1  2 |                         ");
  printf("\n        v     = |       |  u                      ");
  printf("\n                |  0  1 |                       \n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,3,C6);

  G_points2D_mR(i_WGnuplot(-.5,3.5,-.5,3.5),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);

  stop();

  return 0;
}
Shear in the x-direction with factor k (left)
Crystal Clear mimetype source c.png ckd09.c
'
/* ------------------------------------ */
/*  Save as :   ckd09.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={    1, -2,
                       0,  1 };
double u[R2*C5]  ={    0,  1,  1,  0,  0,
                       0,  0,  1,  1,  0 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Shear in the x-direction with factor k (left) :\n");
  printf("\n                |  1 -2 |                         ");
  printf("\n        v[n]  = |       |  u[n]                   ");
  printf("\n                |  0  1 |                       \n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,3,C6);

  G_points2D_mR(i_WGnuplot(-2.5,1.5,-1.5,2.5),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);

  stop();

  return 0;
}
Shear in the y-direction with factor k (up)
Crystal Clear mimetype source c.png ckd10.c
'
/* ------------------------------------ */
/*  Save as :   ckd10.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={    1,  0,
                       2,  1 };
double u[R2*C5]  ={    0,  1,  1,  0,  0,
                       0,  0,  1,  1,  0 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Shear in the y-direction with factor k (up) :  \n");
  printf("\n                |  1  0 |                         ");
  printf("\n        v     = |       |  u                      ");
  printf("\n                |  2  1 |                       \n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,3,C6);

  G_points2D_mR(i_WGnuplot(-.5,3.4,-.5,3.5),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);

  stop();

  return 0;
}
Shear in the x-direction with factor k (down)
Crystal Clear mimetype source c.png ckd11.c
'
/* ------------------------------------ */
/*  Save as :   ckd11.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
int main(void)
{
double t[R2*C2]  ={    1,  0,
                      -2,  1 };
double u[R2*C5]  ={    0,  1,  1,  0,  0,
                       0,  0,  1,  1,  0 };

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = ca_A_mR(t,i_mR(R2,C2));
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Shear in the x-direction with factor k (down): \n");
  printf("\n                |  1  0 |                         ");
  printf("\n           v  = |       |  u                      ");
  printf("\n                | -2  1 |                       \n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,3,C6);

  G_points2D_mR(i_WGnuplot(-2,2,-2.5,1.5),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);
  
  stop();

  return 0;
}
Rotation
Crystal Clear mimetype source c.png ckd12.c
'
/* ------------------------------------ */
/*  Save as :   ckd12.c                 */
/* ------------------------------------ */
#include "v_a.h"
#include "dstrct.h"
#include "dg_uv.h"
/* ------------------------------------ */
void fun(void)
{
double u[R2*C5]  ={ 0,  1,  1,  0,  0,
                    0,  0,  1,  1,  0 };

double alpha = rp_I(360);

double **U = ca_A_mR(u,i_mR(R2,C5));
double **T = rot2D_mR( i_mR(R2,C2),PI/180.*alpha);
double **V =           i_mR(R2,C5);

  clrscrn();

  printf("\n Rotation (%.f degree) : \n",alpha);
  printf("\n                | cos(alpha)  -sin(alpha) |    ");
  printf("\n           v  = |                         |  u ");
  printf("\n                | sin(alpha)  cos(alpha)  |  \n");

  printf(" U: ");
  p_mR(U,5,0,C6);
  mul_mR(T,U,V);
  printf(" V: ");
  p_mR(V,5,3,C6);

  G_points2D_mR(i_WGnuplot(-2,2,-2,2),
                U,V);

  f_mR(U);
  f_mR(V);
  f_mR(T);
}
/* ------------------------------------ */
int main(void)
{
  
do
{
  fun();
  printf("\n Press 'X' Return to stop\r");
  fflush(stdout);
} while(stop_w());

  return 0;
}