Exemple #1
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

Type 1 = Bezier. Type 2 = Hermite

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0, 
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {
  struct matrix *x_coef;
  struct matrix *y_coef;
  if (type == 1){
    x_coef=generate_curve_coefs(x0,x1,x2,x3,type);
    y_coef=generate_curve_coefs(y0,y1,y2,y3,type);
  }
  if (type == 2){
    x_coef=generate_curve_coefs(x0,x2,x1-x0,x3-x2,type);
    y_coef=generate_curve_coefs(y0,y2,y1-y0,y3-y2,type);
  }
  double t=0;
  step=1/step;
  for (t;t<=1;t+=step){
    x1=t*( t*(t*x_coef->m[0][0] + x_coef->m[1][0]) +x_coef->m[2][0])+x_coef->m[3][0];
    y1=t*( t*(t*y_coef->m[0][0] + y_coef->m[1][0]) +y_coef->m[2][0])+y_coef->m[3][0];
    add_edge(points,x0,y0,0,x1,y1,0);
    x0=x1;
    y0=y1;
  }
  free_matrix(x_coef);
  free_matrix(y_coef);
}
Exemple #2
0
/*======== void add_curve() ==========
  Inputs: struct matrix *points
  double x0
  double y0
  double x1
  double y1
  double x2
  double y2
  double x3
  double y3
  double step
  int type
  Returns:
  Adds the curve bounded by the 4 points passsed as parameters
  of type specified in type (see matrix.h for curve type constants)
  to the matrix points
  03/16/12 15:24:25
  jdyrlandweaver
  ====================*/
void add_curve( struct matrix *points,
		double x0, double y0,
		double x1, double y1,
		double x2, double y2,
		double x3, double y3,
		double step, int type ) {

  //0===hermite
  //step <<1
  struct matrix *A;//A->x  , B->y 
  struct matrix *B;
  //int t;
  double t;
  if(type){//bezier curve
    A = generate_curve_coefs( x0, x1, x2, x3, type);
    B = generate_curve_coefs( y0, y1, y2, y3, type);

    for (t = 0; t < 1; t =t+ step) {
      add_edge(points, A->m[0][0]*t*t*t + A->m[1][0]*t*t + A->m[2][0]*t + A->m[3][0], B->m[0][0]*t*t*t + B->m[1][0]*t*t + B->m[2][0]*t + B->m[3][0], 0, A->m[0][0]*t*t*t + A->m[1][0]*t*t + A->m[2][0]*t + A->m[3][0], B->m[0][0]*t*t*t + B->m[1][0]*t*t + B->m[2][0]*t + B->m[3][0], 0);
    }
    
  }

  else{//hermite curve
    A = generate_curve_coefs( x0, x2, x1, x3,type);
    B = generate_curve_coefs( y0, y2, y1, y3,type);
    for(t=0;t<1 ;t =t+step){
add_edge(points, A->m[0][0]*t*t*t + A->m[1][0]*t*t + A->m[2][0]*t + A->m[3][0], B->m[0][0]*t*t*t + B->m[1][0]*t*t + B->m[2][0]*t + B->m[3][0], 0, A->m[0][0]*t*t*t + A->m[1][0]*t*t + A->m[2][0]*t + A->m[3][0], B->m[0][0]*t*t*t + B->m[1][0]*t*t + B->m[2][0]*t + B->m[3][0], 0);
    }

    
    
  }
}
Exemple #3
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0, 
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {

  struct matrix * x_cor;
  struct matrix * y_cor;

  x_cor = generate_curve_coefs(x0, x1, x2, x3, type);
  y_cor = generate_curve_coefs(y0, y1, y2, y3, type);

  double i;
  double x = x0;
  double y = y0;
  double xA, yA;

  for (i = 0.0; i < 1; i += step) {
    x = x_cor->m[0][0]*pow(i, 3) + x_cor->m[1][0]*pow(i, 2)
      + x_cor->m[2][0]*i + x_cor->m[3][0];
    xA = x_cor->m[0][0]*pow(i+step, 3) + x_cor->m[1][0]*pow(i+step, 2)
      + x_cor->m[2][0]*(i+step) + x_cor->m[3][0];
    
    y = y_cor->m[0][0]*pow(i, 3) + y_cor->m[1][0]*pow(i, 2)
      + y_cor->m[2][0]*i + y_cor->m[3][0];
    yA = y_cor->m[0][0]*pow(i+step, 3) + y_cor->m[1][0]*pow(i+step, 2)
      + y_cor->m[2][0]*(i+step) + y_cor->m[3][0];

    add_edge(points, x, y, 0, xA, yA, 0);
  }
}
Exemple #4
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve(struct matrix *points,
        double x0, double y0,
        double x1, double y1,
        double x2, double y2,
        double x3, double y3,
        double step, int type) {
      struct matrix * le_x = generate_curve_coefs( x0, x1, x2, x3, type );
  struct matrix * le_y = generate_curve_coefs( y0, y1, y2, y3, type );
  
  double x, y, t, xa, ya;
  double a_x = le_x->m[0][0]; 
  double b_x = le_x->m[1][0]; 
  double c_x = le_x->m[2][0]; 
  double d_x = le_x->m[3][0];
  double a_y = le_y->m[0][0]; 
  double b_y = le_y->m[1][0]; 
  double c_y = le_y->m[2][0]; 
  double d_y = le_y->m[3][0];
  xa = d_x;
  ya = d_y;
  for( t = step; t <= 1 + step; t+= step ) {
    x = a_x * pow(t, 3) + b_x * pow(t, 2) + c_x * t + d_x;
    y = a_y * pow(t, 3) + b_y * pow(t, 2) + c_y * t + d_y;
    add_edge( points, xa, ya, 0, x, y, 0 );
    xa = x;
    ya = y;
  }
  
  free_matrix(le_x);
  free_matrix(le_y);
}
Exemple #5
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0, 
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {
  struct matrix* coefx;
  struct matrix* coefy;
  if(type == HERMITE_MODE){
    coefx = generate_curve_coefs(x0,x2,x1-x0,x2-x3,type);
    coefy = generate_curve_coefs(y0,y2,y1-y1,y2-y3,type);
  }
  else if(type == BEZIER_MODE){
    coefx = generate_curve_coefs(x0,x1,x2,x3,type);
    coefy = generate_curve_coefs(y0,y1,y2,y3,type);
  }
  double t = 0;
  double x,y;
  while(t<1.0){
    x = t*(t*(coefx->m[0][0]*t+coefx->m[1][0])+coefx->m[2][0])+coefx->m[3][0];
    y = t*(t*(coefy->m[0][0]*t+coefy->m[1][0])+coefy->m[2][0])+coefy->m[3][0];
    add_point(points,x,y,0);
    t += 1.0/step;
    x = t*(t*(coefx->m[0][0]*t+coefx->m[1][0])+coefx->m[2][0])+coefx->m[3][0];
    y = t*(t*(coefy->m[0][0]*t+coefy->m[1][0])+coefy->m[2][0])+coefy->m[3][0];
    add_point(points,x,y,0);
  }
}
Exemple #6
0
/*======== void add_curve() ==========
Inputs: struct matrix *points
double x0
double y0
double x1
double y1
double x2
double y2
double x3
double y3
double step
int type
Returns:

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points,
double x0, double y0,
double x1, double y1,
double x2, double y2,
double x3, double y3,
double step, int type ) {

  struct matrix *x;
  struct matrix *y;
  double g;
  double z;
  z = g + step;
  x = generate_curve_coefs(x0,x1,x2,x3,type);
  y = generate_curve_coefs(y0,y1,y2,y3,type);
  for(g = 0; g < 1; g += step){
    add_edge(points,
	     g * g * g * x->m[0][0] + g * g * x->m[1][0] + g * x->m[2][0] + x->m[3][0],
	     g * g * g * y->m[0][0] + g * g * y->m[1][0] + g * y->m[2][0] + y->m[3][0],
	     0,
	     z * z * z * x->m[0][0] + z * z * x->m[1][0] + z * x->m[2][0] + x->m[3][0],
	     z * z * z * y->m[0][0] + z * z * y->m[1][0] + z * y->m[2][0] + y->m[3][0],	    
	     0
	     );
  }
  

}
Exemple #7
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type
Returns:

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points,
                double x0, double y0,
                double x1, double y1,
                double x2, double y2,
                double x3, double y3,
                double step, int type ) {
    struct matrix *x_coefs = generate_curve_coefs(x0, x1, x2, x3, type);
    struct matrix *y_coefs = generate_curve_coefs(y0, y1, y2, y3, type);
    double xa, xb, xc, xd, ya, yb, yc, yd;
    xa = x_coefs->m[0][0];
    xb = x_coefs->m[1][0];
    xc = x_coefs->m[2][0];
    xd = x_coefs->m[3][0];
    ya = y_coefs->m[0][0];
    yb = y_coefs->m[1][0];
    yc = y_coefs->m[2][0];
    yd = y_coefs->m[3][0];

    double t, x_0, y_0, x, y;

    x_0 = xd;
    y_0 = yd;
    for (t = step; t <= 1; t += step) {
        x = xa*t*t*t + xb*t*t + xc*t + xd;
        y = ya*t*t*t + yb*t*t + yc*t + yd;
        add_edge(points, x_0, y_0, 0, x, y, 0);
        x_0 = x;
        y_0 = y;
    }
}
Exemple #8
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void
add_curve (struct matrix *points,
	   double x0, double y0,
	   double x1, double y1,
	   double x2, double y2, double x3, double y3, double step, int type)
{

  double x, y, t;
  struct matrix *xcoefs;
  struct matrix *ycoefs;

  //generate the coeficients
  if (type == BEZIER_MODE)
    {
      ycoefs = generate_curve_coefs (y0, y1, y2, y3, BEZIER_MODE);
      xcoefs = generate_curve_coefs (x0, x1, x2, x3, BEZIER_MODE);
    }

  else
    {
      xcoefs = generate_curve_coefs (x0, x1, x2, x3, HERMITE_MODE);
      ycoefs = generate_curve_coefs (y0, y1, y2, y3, HERMITE_MODE);
    }

  /*
     printf("a = %lf b = %lf c = %lf d = %lf\n", xcoefs->m[0][0],
     xcoefs->m[1][0], xcoefs->m[2][0], xcoefs->m[3][0]);
   */

  for (t = step; t <= 1; t += step)
    {

      x = xcoefs->m[0][0] * t * t * t + xcoefs->m[1][0] * t * t
	+ xcoefs->m[2][0] * t + xcoefs->m[3][0];

      y = ycoefs->m[0][0] * t * t * t + ycoefs->m[1][0] * t * t
	+ ycoefs->m[2][0] * t + ycoefs->m[3][0];

      add_edge (points, x0, y0, 0, x, y, 0);
      x0 = x;
      y0 = y;
    }

  free_matrix (xcoefs);
  free_matrix (ycoefs);
}
Exemple #9
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0, 
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {

  struct matrix * xco;
  struct matrix * yco;
  xco = generate_curve_coefs(x0, x1, x2, x3, type);
  yco = generate_curve_coefs(y0, y1, y2, y3, type);
  
  double t,x,y;
  for (t = 0; t <= 1; t += step) {
    x = xco->m[0][0]*pow(t, 3) + xco->m[1][0]*pow(t, 2) + xco->m[2][0]*t + xco->m[3][0];
    y = yco->m[0][0]*pow(t, 3) + yco->m[1][0]*pow(t, 2) + yco->m[2][0]*t + yco->m[3][0];
    add_point(points, x, y, 0);
  }
}
Exemple #10
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0, 
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {
  struct matrix *xCor;
  struct matrix *yCor;
  xCor = generate_curve_coefs(x0,x1,x2,x3,type);
  yCor = generate_curve_coefs(y0,y1,y2,y3,type);
  double a;
  for(a = 0; a < 1; a+= step){
    add_edge(points, a * a * a * xCor->m[0][0] + a * a * xCor->m[1][0] + a * xCor->m[2][0] + xCor->m[3][0],
	     a * a * a * yCor->m[0][0] + a * a * yCor->m[1][0] + a * yCor->m[2][0] + yCor->m[3][0], 0,
	     (a+step)*(a+step)*(a+step)*xCor->m[0][0]+(a+step)*(a+step)*xCor->m[1][0]+(a+step)*xCor->m[2][0]+xCor->m[3][0],
	     (a+step)*(a+step)*(a+step)*yCor->m[0][0]+(a+step)*(a+step)*yCor->m[1][0]+(a+step)*yCor->m[2][0]+yCor->m[3][0],0);
  }
 
}
Exemple #11
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0, 
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {
  struct matrix *cox = generate_curve_coefs(x0,x1,x2,x3,type);
  struct matrix *coy = generate_curve_coefs(y0,y1,y2,y3,type);

  double t;
  for(t = 0; t < 1; t = t + step)  {
    add_edge(points,
	     cox->m[0][0] * pow(t,3) + cox->m[1][0] * pow(t,2) + cox->m[2][0] * t + cox->m[3][0],
	     coy->m[0][0] * pow(t,3) + coy->m[1][0] * pow(t,2) + coy->m[2][0] * t + coy->m[3][0], 0,
	     cox->m[0][0] * pow(t+step,3) + cox->m[1][0] * pow(t+step,2) + cox->m[2][0] * (t+step) + cox->m[3][0],
	     coy->m[0][0] * pow(t+step,3) + coy->m[1][0] * pow(t+step,2) + coy->m[2][0] * (t+step) + coy->m[3][0], 0);
  }

  free_matrix(cox);
  free_matrix(coy);
}
Exemple #12
0
/*======== void add_curve() ==========
Inputs: struct matrix *points
double x0
double y0
double x1
double y1
double x2
double y2
double x3
double y3
double step
int type
Returns:

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points,
		double x0, double y0,
		double x1, double y1,
		double x2, double y2,
		double x3, double y3,
		double step, int type ) {
  struct matrix * x = generate_curve_coefs(x0, x1, x2, x3, type);
  struct matrix * y = generate_curve_coefs(y0, y1, y2, y3, type);
  double i, d, f;
  double d0 = x->m[3][0];
  double f0 = y->m[3][0];
  for(i = step; i < 1; i += step){
    d = x->m[0][0]*pow(i, 3) + x->m[1][0]*pow(i,2) + x->m[2][0]*i + x->m[3][0];
    f = y->m[0][0]*pow(i, 3) + y->m[1][0]*pow(i,2) + y->m[2][0]*i + y->m[3][0];
    add_edge(points, d0, f0, 0, d, f, 0);
    d = d0;
    f = f0;
  }
  free_matrix(x);
  free_matrix(y);
}
Exemple #13
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type
Returns:

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points,
                double x0, double y0,
                double x1, double y1,
                double x2, double y2,
                double x3, double y3,
                double step, int type ) {
    struct matrix * mx;
    struct matrix * my;
    mx = generate_curve_coefs(x0, x1, x2, x3, type);
    my = generate_curve_coefs(y0, y1, y2, y3, type);
    double t, x, y;
    x = x0;
    y = y0;

    for (t = 0; t <= 1; t += step) {
        add_point(points, x, y, 0);
        x = mx->m[0][0] * t * t * t + mx->m[1][0] * t * t + mx->m[2][0] * t + mx->m[3][0];
        y = my->m[0][0] * t * t * t + my->m[1][0] * t * t + my->m[2][0] * t + my->m[3][0];
        add_point(points, x, y, 0);
    }

}
Exemple #14
0
/*======== void add_curve() ==========
	Inputs:   struct matrix *points
	double x0
	double y0
	double x1
	double y1
	double x2
	double y2
	double x3
	double y3
	double step
	int type  
	Returns: 

	Adds the curve bounded by the 4 points passsed as parameters
	of type specified in type (see matrix.h for curve type constants)
	to the matrix points

	03/16/12 15:24:25
	jdyrlandweaver
	====================*/
void add_curve( struct matrix *points, 
								double x0, double y0, 
								double x1, double y1, 
								double x2, double y2, 
								double x3, double y3, 
								double step, int type ) {

	struct matrix* coefs_x, *coefs_y;
	double h0, v0, h, v, t;

	if (type == HERMITE_MODE){
		coefs_x = generate_curve_coefs(x0, x1, x2, x3, HERMITE_MODE);
		coefs_y = generate_curve_coefs(y0, y1, y2, y3, HERMITE_MODE);
	}
	else if (type == BEZIER_MODE){
		coefs_x = generate_curve_coefs(x0, x1, x2, x3, BEZIER_MODE);
		coefs_y = generate_curve_coefs(y0, y1, y2, y3, BEZIER_MODE);
	}
	else {
		printf("Not a valid type. Must be either 0 or 1\n");
		return;
	}

	h0 = coefs_x -> m[3][0];
	v0 = coefs_y -> m[3][0];
	for (t = step; t < 1.0000001; t+= step){
		h = t * (t * (coefs_x -> m[0][0] * t +
									coefs_x -> m[1][0]) +
						 coefs_x -> m[2][0]) + coefs_x -> m[3][0];
		v = t * (t * (coefs_y -> m[0][0] * t +
									coefs_y -> m[1][0]) +
						 coefs_y -> m[2][0]) + coefs_y -> m[3][0]; 
	
		add_edge(points, h0, v0, 0, h, v, 0);
		h0 = h;
		v0 = v;
	}
}
Exemple #15
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0,
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {
    
    double t, xi, yi, x, y, ax, bx, cx, dx, ay, by, cy, dy;
    
    struct matrix * xcoef = new_matrix(4, 4);
    xcoef = generate_curve_coefs(x0, x1, x2, x3, type);
    
    struct matrix * ycoef = new_matrix(4, 4);
    ycoef = generate_curve_coefs(y0, y1, y2, y3, type);
    
    xi = xcoef -> m[3][0];
    yi = ycoef -> m[3][0];
    
    for(t = step; t < 1; t += step) {
        ax = xcoef -> m[0][0];
        bx = xcoef -> m[1][0];
        cx = xcoef -> m[2][0];
        dx = xcoef -> m[3][0];
        x = ax*t*t*t + bx*t*t + cx*t + dx;
        
        ay = ycoef -> m[0][0];
        by = ycoef -> m[1][0];
        cy = ycoef -> m[2][0];
        dy = ycoef -> m[3][0];
        y = ay*t*t*t + by*t*t + cy*t + dy;
        
        add_edge(points, xi, yi, 0, x, y, 0);
        
        xi = x;
        yi = y;
    }
}
Exemple #16
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0, 
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {
  double t;

	// For Hermite Curve
  if (type == HERMITE_MODE) {

    struct matrix * x_val = generate_curve_coefs( x0, x2, x1, x3, HERMITE_MODE);
    struct matrix * y_val = generate_curve_coefs( y0, y2, y1, y3, HERMITE_MODE);

    for (t = 0; t < 1; t += 1/step) {
      add_edge(points,
							 // X
							 x_val->m[0][0]*t*t*t +
							 x_val->m[1][0]*t*t +
							 x_val->m[2][0]*t +
							 x_val->m[3][0],
							 // Y
							 y_val->m[0][0]*t*t*t +
							 y_val->m[1][0]*t*t +
							 y_val->m[2][0]*t +
							 y_val->m[3][0],
							 
							 0,
							 
							 // X
							 x_val->m[0][0]*t*t*t +
							 x_val->m[1][0]*t*t +
							 x_val->m[2][0]*t +
							 x_val->m[3][0],
							 // Y
							 y_val->m[0][0]*t*t*t +
							 y_val->m[1][0]*t*t +
							 y_val->m[2][0]*t +
							 y_val->m[3][0],
							 
							 0);
    }


  } else {

		//For Bezier Curve
		struct matrix * x_val = generate_curve_coefs( x0, x1, x2, x3, BEZIER_MODE);
    struct matrix * y_val = generate_curve_coefs( y0, y1, y2, y3, BEZIER_MODE);

    for (t = 0; t < 1; t += 1/step) {
      add_edge(points,
							 // X
							 x_val->m[0][0]*t*t*t +
							 x_val->m[1][0]*t*t +
							 x_val->m[2][0]*t +
							 x_val->m[3][0],
							 // Y
							 y_val->m[0][0]*t*t*t +
							 y_val->m[1][0]*t*t +
							 y_val->m[2][0]*t +
							 y_val->m[3][0],
							 
							 0,

							 // X
							 x_val->m[0][0]*t*t*t +
							 x_val->m[1][0]*t*t +
							 x_val->m[2][0]*t +
							 x_val->m[3][0],
							 // Y
							 y_val->m[0][0]*t*t*t +
							 y_val->m[1][0]*t*t +
							 y_val->m[2][0]*t +
							 y_val->m[3][0],
							 
							 0);
		}
    
  }
}
Exemple #17
0
/*======== void add_curve() ==========
Inputs:   struct matrix *points
         double x0
         double y0
         double x1
         double y1
         double x2
         double y2
         double x3
         double y3
         double step
         int type  
Returns: 

Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points

03/16/12 15:24:25
jdyrlandweaver
====================*/
void add_curve( struct matrix *points, 
		double x0, double y0, 
		double x1, double y1, 
		double x2, double y2, 
		double x3, double y3, 
		double step, int type ) {
  printf("curve\n");
  /*double t,currx0,curry0,currx1,curry1;
    currx0 = x0;
    curry0 = y0;

    struct matrix * coefx = new_matrix(4,1);
    struct matrix * coefy = new_matrix(4,1);
    coefx = generate_curve_coefs(x0,x1,x2,x3,type);
    coefy = generate_curve_coefs(y0,y1,y2,y3,type);

    for (t = 0; t <= 1-step; t += step) {
    currx0 = coefx->m[0][0]*t*t*t + coefx->m[1][0]*t*t + coefx->m[2][0]*t + coefx->m[3][0];
    curry0 = coefy->m[0][0]*t*t*t + coefy->m[1][0]*t*t + coefy->m[2][0]*t + coefy->m[3][0];
    currx1 = coefx->m[0][0]*(t+step)*(t+step)*(t+step) + coefx->m[1][0]*(t+step)*(t+step) + coefx->m[2][0]*(t+step) + coefx->m[3][0];
    curry1 = coefy->m[0][0]*(t+step)*(t+step)*(t+step) + coefy->m[1][0]*(t+step)*(t+step) + coefy->m[2][0]*(t+step) + coefy->m[3][0];
    add_edge(points, currx0, curry0, 0, currx1, curry1, 0);
    }*/

  /*if (type) { //bezier



  }
  else { //hermit

    double m0,m1,x,y,t;

    m0 = (y1-y0)/(x1-x0);
    m1 = (y3-y2)/(x3-x2);

    struct matrix * poly = new_matrix(4,1);
    struct matrix * paramx = new_matrix(4,1);
    struct matrix * paramy = new_matrix(4,1);
    struct matrix * herm;

    add_point(points, x0, y0, 0);
    for (t = step; t <= 1; t+=step) {
      poly->m[0][0] = t * t * t;
      poly->m[0][1] = t * t;
      poly->m[0][2] = t;
      poly->m[0][3] = 1;    

      paramx->m[0][0] = x0;
      paramx->m[0][1] = x2;
      paramx->m[0][2] = m0;
      paramx->m[0][3] = m1;

      paramy->m[0][0] = y0;
      paramy->m[0][1] = y2;
      paramy->m[0][2] = m0;
      paramy->m[0][3] = m1;

      herm = make_hermite();
      matrix_mult(poly, paramx);
      matrix_mult(paramx, herm);
      x = herm->m[0][0] + herm->m[0][1] + herm->m[0][2] + herm->m[0][3];

      herm = make_hermite();
      matrix_mult(poly, paramy);
      matrix_mult(paramy, herm);
      y = herm->m[0][0] + herm->m[0][1] + herm->m[0][2] + herm->m[0][3];

      add_point(points, x, y, 0);
      add_point(points, x, y, 0);
    }
    add_point(points, x2, y2, 0);
    free(poly);
    free(paramx);
    free(paramy);
    free(herm);

    }*/
  printf("Hello1\n");
  struct matrix * coefx = generate_curve_coefs(x0,x1,x2,x3,type);
  struct matrix * coefy = generate_curve_coefs(y0,y1,y2,y3,type);
  printf("Hello2\n");
  double t,x,y;

  add_point(points,x0,y0,0);
  for (t = step; t <= 1; t+= step) {
    x = coefx->m[0][0] * t * t * t + coefx->m[1][0] * t * t + coefx->m[2][0] * t + coefx->m[3][0];
    y = coefy->m[0][0] * t * t * t + coefy->m[1][0] * t * t + coefy->m[2][0] * t + coefy->m[3][0];
    add_point(points,x,y,0);
    add_point(points,x,y,0);
  }
  add_point(points,x3,y3,0);

}