Example #1
0
void	create_rz_matrix(matrix mtx, float angle)
{
	angle = toradian(angle);
	mtx[0][0] = cos(angle);
	mtx[0][1] = sin(angle);
	mtx[0][2] = 0;
	mtx[0][3] = 0;
	mtx[1][0] = sin(angle) * -1;
	mtx[1][1] = cos(angle);
	mtx[1][2] = 0;
	mtx[1][3] = 0;
	mtx[2][0] = 0;
	mtx[2][1] = 0;
	mtx[2][2] = 1;
	mtx[2][3] = 0;
	mtx[3][0] = 0;
	mtx[3][1] = 0;
	mtx[3][2] = 0;
	mtx[3][3] = 1;
}
Example #2
0
void create_projection_matrix(matrix mtx, t_camconfig cfg)
{
	float focal_length;

	focal_length = 1.f / tanf(toradian(cfg.fov) / 2.f);
	mtx[0][0] = focal_length / (float)cfg.ratio;
	mtx[0][1] = 0.0;
	mtx[0][2] = 0.0;
	mtx[0][3] = 0.0;
	mtx[1][0] = 0.0;
	mtx[1][1] = focal_length;
	mtx[1][2] = 0.0;
	mtx[1][3] = 0.0;
	mtx[2][0] = 0.0;
	mtx[2][1] = 0.0;
	mtx[2][2] = ((cfg.far + cfg.near) / (cfg.near - cfg.far));
	mtx[3][2] = ((2.f * cfg.far * cfg.near) / (cfg.near - cfg.far));
	mtx[3][0] = 0.0;
	mtx[3][1] = 0.0;
	mtx[2][3] = -1.f;
	mtx[3][3] = 0.0;
}
void main(void) {

  int nv, p, i;
  const double xmax = 180.0;
  ofstream res("res.out");
  car2d xy;

  p = 3;
  nv = 7;
  xy.setdimsize(nv, 2);

  double delx = xmax / double(nv-1);

  for(i = 0; i < nv; i++) {
    xy[i][0] = double(i)*delx;
    xy[i][1] = sin(toradian(xy[i][0]));
  }
/*
	xy[0][0] = -4.000;
	xy[1][0] = 0.000;  
	xy[2][0] = 3.037; 
	xy[3][0] = 5.941;  
	xy[4][0] = 7.769;
	xy[5][0] = 8.406; 
	xy[6][0] = 8.948;  
	xy[7][0] = 9.075;
	xy[8][0] = 8.789;   
	xy[9][0] = 7.705;
	xy[10][0] = 5.941;
	xy[11][0] = 3.037;
	xy[12][0] = 0.000; 
	xy[13][0] = 0.000; 
	xy[14][0] = 0.034; 
	xy[15][0] = 0.524;  
	xy[16][0] = 1.267;  
	xy[17][0] = 3.037;
	xy[18][0] = 5.941; 
	
	xy[0][1] = 0.000;
	xy[1][1] = 1.252;  
	xy[2][1] = 2.340; 
	xy[3][1] = 4.206;  
	xy[4][1] = 6.000;
	xy[5][1] = 7.000; 
	xy[6][1] = 8.000;  
	xy[7][1] = 9.000;
	xy[8][1] = 10.000;   
	xy[9][1] = 11.000;
	xy[10][1] = 11.198;
	xy[11][1] = 11.516;
	xy[12][1] = 11.947; 
	xy[13][1] = 12.300; 
	xy[14][1] = 13.000; 
	xy[15][1] = 14.500;  
	xy[16][1] = 16.000;  
	xy[17][1] = 18.640;
	xy[18][1] = 23.013;
*/
  res << "\nXY data\n" << xy << endl;
	
  // polygonal arc length
  cvecd s(nv);
  s[0] = 0.0;
  for(int j = 1; j < nv; j++) {
    s[j] = s[j-1] + sqrt(square(xy[j][0] - xy[j-1][0]) + 
                         square(xy[j][1] - xy[j-1][1]));

  }
  res << "\nPolygonal arc length\n"
      << s << endl;

  cvecd u(nv);
  for(j = 0; j < nv; j++) {
    u[j] = ( double(nv) - double(p)) / s[nv-1] * s[j];
}
  res << "parameter u\n" << u << endl;

  cvecd U(nv + p + 1);
  ComputeUniformKnotVector(nv-1, p, U);
  for(i=0;i<nv+p+1;i++)
  {
}
  res << "\nKnot vector\n" << U << endl;

  car2d A(nv, nv);
  cvecd N(p+1);
  for(j = 0; j < nv; j++) {
    int span = FindSpan(nv-1, p, u[j], U);
    BasisFuns(span, u[j], p, U, N); 
    for(int a=0; a<=p; a++) {
      A[j][span-p+a] = N[a];
   }
  }


  res << "\nCoefficient matrix\n" << A << endl;

  car2d ALUD(nv, nv);
  car2d P(nv, 2);
  cvecd rhs(nv);
  cveci pivot(nv);
  double plusminusone;
  // Xi  *P = Y(ui)
  // Etai*P = Y(ui) 
  //..solve simultaneous equation by LU Decomposition..
  ludcmp(A, ALUD, nv, pivot, plusminusone);  


  for(j = 0; j < 2; j++) {
    for(i = 0; i < nv; i++) rhs[i] = xy[i][j];
    lubksb(ALUD, nv, pivot, rhs);
    for(i = 0; i < nv; i++) P[i][j] = rhs[i];
  }

  res << "\nGCV\n" << P << endl;
  res.close();

  ofstream fig60("fig60.dat");
  fig60.setf(ios::showpoint | ios::right | ios::fixed);
  fig60.precision(6);
  fig60 << "variables = x, y\n"
        << "zone t = \"Input Points\", i = " << nv << endl;
  for(j = 0; j < nv; j++) 
    fig60 << setw(10) << xy[j][0] << ' '
          << setw(10) << xy[j][1] << endl;

  fig60 << "zone t = \"B-spline Control Polygon\", i = " << nv << endl;
  for(j = 0; j < nv; j++) 
    fig60 << setw(10) << P[j][0] << ' '
          << setw(10) << P[j][1] << endl;


  int nuout = 50;
  cvecd uout(nuout), point(2);
  double maxu = double(nv - p);
  double delu = maxu / double(nuout-1);
//  printf("%lf, %lf\n", maxu, double(nuout-1));
  for(i = 0; i < nuout; i++)
  {
   uout[i] = double(i) * delu;
 }

  fig60 << "zone t = \"Evaluated B-spline\", i = " << nuout << endl;
  for(i = 0; i < nuout; i++) {
    CurvePoint1P (
      nv-1, 
      p, 
      U, 
      P, 
      uout[i], 
      point, 
      2
    );
    fig60 << setw(10) << point[0] << ' '
          << setw(10) << point[1] << endl;
  }
}