グラフィックス・ユーティリティライブラリ 使用例



[ 簡単な説明 ]

グラフィックス・ユーティリティライブラリの使用例です。

プログラム・ソース("test22.c")           top (先頭に戻る)
/*		test22.c	*/
#include <stdio.h>
#include "sslib.h"

int main(void)
{
	double cr, cro, ct, cto, cz, czo;
	double deg, dx, dxo, dy, dyo, dz, dzo;
	double pr, pro, pe, peo, pp, ppo;
	double phai, psai, r, rad, ro, t, thet, to, trot;
	double x, xm, xo, y, ym, yo, z, zo;
	int error;

	printf("< 角度変換 (deg <-> rad) >\n");
	deg = 30.0;
	dtor(deg, &rad);
	printf(" Degree to Radian Transformation\n");
	printf("   deg = %10.6f\n", deg);
	printf("   rad = %19.16f\n", rad);
	printf(" Exact = %19.16f\n\n", M_PI / 6.0);
	rad = M_PI;
	rtod(rad, &deg);
	printf(" Radian to Degree Transformation\n");
	printf("   rad = %18.14f\n", rad);
	printf("   deg = %18.14f\n", deg);
	printf(" Exact = %18.14f\n\n", 180.0);

	printf("< 二次元座標変換 (デカルト座標 <-> 極座標(角度単位:deg) >\n");
	xo = 2.0;
	yo = 2.0;
	error = dtop2(xo, yo, &r, &t);
	printf(" Cartesian to Poler coordinate\n");
	printf(" x = %8.3f   y = %8.3f\n", xo, yo);
	printf(" r = %8.3f   t = %8.3f\n", r, t);
	printf(" error = %5d\n\n", error);
	error = ptod2(r, t, &x, &y);
	printf(" Poler to Cartesian coordinate\n");
	printf(" r = %8.3f   t = %8.3f\n", r, t);
	printf(" x = %8.3f   y = %8.3f\n", x, y);
	printf(" error = %5d\n\n", error);

	printf("< 二次元平行移動 (極座標系角度単位:deg)>\n");
	xo = 2.0;
	yo = 2.0;
	xm = 0.5;
	ym = 0.5;
	error = dmov2(xo, yo, xm, ym, &x, &y);
	printf(" Parallel move (cartesian coordinate)\n");
	printf(" xo = %8.3f   yo = %8.3f   dx = %8.3f   dy = %8.3f\n", xo, yo, xm, ym);
	printf(" x = %8.3f   y = %8.3f\n", x, y);
	printf(" error = %5d\n\n", error);
	ro = 1.0;
	to = 30.0;
	error = pmov2(ro, to, xm, ym, &r, &t);
	printf(" Parallel move (Poler coordinate)\n");
	printf(" ro = %8.3f   to = %8.3f   xm = %8.3f   ym = %8.3f\n", ro, to, xm, ym);
	printf(" r = %8.3f   t = %8.3f\n", r, t);
	printf(" error = %5d\n\n", error);

	printf("< 2次元回転移動 (極座標系角度単位:deg)>\n");
	xo = 2.0;
	yo = 2.0;
	ro = 1.0;
	to = 30.0;
	trot = 15.0;
	t = 45.0;
	error = drot2(xo, yo, t, &x, &y);
	printf(" Rotation (Cartesian coordinate)\n");
	printf(" xo = %8.3f   yo = %8.3f  rot = %8.3f(deg)\n", xo, yo, t);
	printf(" x  = %8.3f   y  = %8.3f\n", x, y);
	printf(" error = %5d\n", error);
	error = prot2(ro, to, trot, &r, &t);
	printf(" Rotation (Poler coordinate)\n");
	printf(" ro = %8.3f   to = %8.3f  trot = %8.3f(deg)\n", ro, to, trot);
	printf(" r  = %8.3f   t  = %8.3f\n", r, t);
	printf(" error = %5d\n\n", error);

	printf("< 三次元座標変換 (デカルト座標 <-> 円柱座標 <-> 極座標 角度単位:deg)\n");
	printf(" Exchange Coordinate ( 3-dimansion )\n");
	printf("   Decurtes <-> Cylindorical\n");
	dx = dy = 2.0;
	dz = 3.0;
	printf("    x = %10.4f   y = %10.4f   z = %10.4f\n", dx, dy, dz);
	dtoc3(dx, dy, dz, &cr, &ct, &cz);
	printf("   cr = %10.4f  ct = %10.4f  cz = %10.4f\n", cr, ct, cz);
	ctod3(cr, ct, cz, &dx, &dy, &dz);
	printf("    x = %10.4f   y = %10.4f   z = %10.4f\n\n", dx, dy, dz);
	printf("   Decurtes <-> Poler\n");
	printf("    x = %10.4f   y = %10.4f   z = %10.4f\n", dx, dy, dz);
	dtop3(dx, dy, dz, &pr, &pe, &pp);
	printf("   pr = %10.4f  pe = %10.4f  pp = %10.4f\n", pr, pe, pp);
	ptod3(pr, pe, pp, &dz, &dy, &dz);
	printf("    x = %10.4f   y = %10.4f   z = %10.4f\n\n", dx, dy, dz);
	printf("   Poler <-> Cylindorical\n");
	cr = 2.0;
	ct = 30.0;
	cz = 1.0;
	printf("   cr = %10.4f  ct = %10.4f  cz = %10.4f\n", cr, ct, cz);
	ctop3(cr, ct, cz, &pr, &pe, &pp);
	printf("   pr = %10.4f  pe = %10.4f  pp = %10.4f\n", pr, pe, pp);
	ptoc3(pr, pe, pp, &cr, &ct, &cz);
	printf("   cr = %10.4f  ct = %10.4f  cz = %10.4f\n\n", cr, ct, cz);

	printf("< 三次元平行移動 (角度単位:deg)\n");
	xo = dx = 1.0;
	yo = dy = 1.0;
	zo = dz = 1.0;
	error = dpmov3(xo, yo, zo, dx, dy, dz, &x, &y, &z);
	printf("Pallarel Move in 3-Dimensional coordinate\n");
	printf("  Decartes Coordinate\n");
	printf("    xo = %6.4f   yo = %6.4f   zo = %6.4f\n", xo, yo, zo);
	printf("    dx = %6.4f   dy = %6.4f   dz = %6.4f\n", dx, dy, dz);
	printf("    x  = %6.4f   y  = %6.4f   z  = %6.4f\n", x, y, z);
	printf("    Error = %5d\n\n", error);
	cro = 1.0;
	cto = 45.0;
	czo = 1.0;
	error = cpmov3(cro, cto, czo, dx, dy, dz, &cr, &ct, &cz);
	printf("  Cylindorical Coordinate\n");
	printf("   cro = %6.3f  cto = %6.3f  czo = %6.3f\n", cro, cto, czo);
	printf("    dx = %6.3f   dy = %6.3f   dz = %6.3f\n", dx, dy, dz);
	printf("    cr = %6.3f   ct = %6.3f   cz = %6.3f\n", cr, ct, cz);
	printf("    Error = %5d\n\n", error);
	pro = 1.0;
	peo = 45.0;
	ppo = 45.0;
	error = ppmov3(pro, peo, ppo, dx, dy, dz, &pr, &pe, &pp);
	printf("  Poler Coordinate\n");
	printf("   pro = %6.3f  peo = %6.3f  ppo = %6.3f\n", pro, peo, ppo);
	printf("    dx = %6.3f   dy = %6.3f   dz = %6.3f\n", dx, dy, dz);
	printf("    pr = %6.3f   pe = %6.3f   pp = %6.3f\n", pr, pe, pp);
	printf("    Error = %5d\n\n", error);

	printf("< 三次元回転移動 (角度単位:deg)\n");
	dxo = sqrt(6.0) / 4.0;
	dyo = sqrt(2.0) / 4.0;
	dzo = 1.0;
	phai = 30.0;
	thet = psai = 45.0;
	error = drot3(dxo, dyo, dzo, phai, thet, psai, &dx, &dy, &dz);
	printf(" Rotate Move in 3-Diensional Coordinate\n");
	printf("  Cartesian Coordinate\n");
	printf("   dxo = %7.4f    dyo = %7.4f    dzo = %7.4f\n", dxo, dyo, dzo);
	printf("  phai = %7.3f   thet = %7.3f   psai = %7.3f\n", phai, thet, psai);
	printf("   dx  = %7.4f    dy  = %7.4f    dz  = %7.4f\n", dx, dy, dz);
	printf("  Exact= %7.4f          %7.4f          %7.4f\n", 1.0, 0.0, M_SQRT_2);
	printf("  Error= %5d\n\n", error);
	cro = 1.0;
	cto = 90.0;
	czo = sqrt(3.0);
	phai = thet = 90.0;
	psai = -90.0;
	error = crot3(cro, cto, czo, phai, thet, psai, &cr, &ct, &cz);
	printf("  Cylindorical Coordinate\n");
	printf("   cro = %7.4f    cto = %7.4f    czo = %7.4f\n", cro, cto, czo);
	printf("  phai = %7.3f   thet = %7.3f   psai = %7.3f\n", phai, thet, psai);
	printf("   cr  = %7.4f    ct  = %7.4f    cz  = %7.4f\n", cr, ct, cz);
	printf("  Exact= %7.4f          %7.4f          %7.4f\n", 2.0, 150.0, 0.0);
	printf("  Error= %5d\n\n", error);
	pro = 1.0;
	peo = ppo = 0.0;
	phai = thet = psai = 90.0;
	error = prot3(pro, peo, ppo, phai, thet, psai, &pr, &pe, &pp);
	printf("  Polar Coordinate\n");
	printf("   pro = %7.4f    peo = %7.4f    ppo = %7.4f\n", pro, peo, ppo);
	printf("  phai = %7.3f   thet = %7.3f   psai = %7.3f\n", phai, thet, psai);
	printf("   pr  = %7.4f    pe  = %7.4f    pp  = %7.4f\n", pr, pe, pp);
	printf("  Exact= %7.4f          %7.4f          %7.4f\n", 1.0, 0.0, 90.0);
	printf("  Error= %5d\n\n", error);
	return 1;
}

出力結果           top (先頭に戻る)
< 角度変換 (deg <-> rad) >
 Degree to Radian Transformation
   deg =  30.000000
   rad =  0.5238987755982989
 Exact =  0.5235987755982988

 Radian to Degree Transformation
   rad =   3.14159265358979
   deg = 180.00000000000000
 Exact = 180.00000000000000

< 二次元座標変換 (デカルト座標 <-> 極座標(角度単位:deg) >
 Cartesian to Poler coordinate
 x =    2.000   y =    2.000
 r =    2.828   t =   45.000
 error =     0

 Poler to Cartesian coordinate
 r =    2.828   t =   45.000
 x =    2.000   y =    2.000
 error =     0

< 二次元平行移動 (極座標系角度単位:deg)>
 Parallel move (cartesian coordinate)
 xo =    2.000   yo =    2.000   dx =    0.500   dy =    0.500
 x =    2.500   y =    2.500
 error =     0

 Parallel move (Poler coordinate)
 ro =    1.000   to =   30.000   xm =    0.500   ym =    0.500
 r =    1.693   t =   36.206
 error =     0

< 2次元回転移動 (極座標系角度単位:deg)>
 Rotation (Cartesian coordinate)
 xo =    2.000   yo =    2.000  rot =   45.000(deg)
 x  =    0.000   y  =    2.828
 error =     0
 Rotation (Poler coordinate)
 ro =    1.000   to =   30.000  trot =   15.000(deg)
 r  =    1.000   t  =   45.000
 error =     0

< 三次元座標変換 (デカルト座標 <-> 円柱座標 <-> 極座標 角度単位:deg)
 Exchange Coordinate ( 3-dimansion )
   Decurtes <-> Cylindorical
    x =     2.0000   y =     2.0000   z =     3.0000
   cr =     2.8284  ct =    45.0000  cz =     3.0000
    x =     2.0000   y =     2.0000   z =     3.0000

   Decurtes <-> Poler
    x =     2.0000   y =     2.0000   z =     3.0000
   pr =     4.1231  pe =    45.0000  pp =    43.3139
    x =     2.0000   y =     2.0000   z =     3.0000

   Poler <-> Cylindorical
   cr =     2.0000  ct =    30.0000  cz =     1.0000
   pr =     2.2361  pe =    30.0000  pp =    63.4349
   cr =     2.0000  ct =    30.0000  cz =     1.0000

< 三次元平行移動 (角度単位:deg)
Pallarel Move in 3-Dimensional coordinate
  Decartes Coordinate
    xo = 1.0000   yo = 1.0000   zo = 1.0000
    dx = 1.0000   dy = 1.0000   dz = 1.0000
    x  = 2.0000   y  = 2.0000   z  = 2.0000
    Error =     0

  Cylindorical Coordinate
   cro =  1.000  cto = 45.000  czo =  1.000
    dx =  1.000   dy =  1.000   dz =  1.000
    cr =  2.414   ct = 45.000   cz =  2.000
    Error =     0

  Poler Coordinate
   pro =  1.000  peo = 45.000  ppo = 45.000
    dx =  1.000   dy =  1.000   dz =  1.000
    pr =  2.723   pe = 45.000   pp = 51.175
    Error =     0

< 三次元回転移動 (角度単位:deg)
 Rotate Move in 3-Diensional Coordinate
  Cartesian Coordinate
   dxo =  0.6124    dyo =  0.3536    dzo =  1.0000
  phai =  30.000   thet =  45.000   psai =  45.000
   dx  =  1.0000    dy  =  0.0000    dz  =  0.7071
  Exact=  1.0000           0.0000           0.7071
  Error=     0

  Cylindorical Coordinate
   cro =  1.0000    cto = 90.0000    czo =  1.7321
  phai =  90.000   thet =  90.000   psai = -90.000
   cr  =  2.0000    ct  = 150.0000    cz  =  0.0000
  Exact=  2.0000          150.0000           0.0000
  Error=     0

  Polar Coordinate
   pro =  1.0000    peo =  0.0000    ppo =  0.0000
  phai =  90.000   thet =  90.000   psai =  90.000
   pr  =  1.0000    pe  =  0.0000    pp  = 90.0000
  Exact=  1.0000           0.0000          90.0000
  Error=     0