Exemple #1
0
void rotacionaPoint(int x, int y, char imagem[MAXIMO][MAXIMO]){
    x = (x * cos(PI/4)) + (y * (- sin(PI/4))) ;
    y = (x * sin(PI/4)) + (y * cos(PI/4));
    printf("\n\nAntes da transposicao: %d %d\n", x, y);
    transPoint(x,y, imagem);
}
Exemple #2
0
int main(void) {

	float x1, y1, x2, y2, a, b, x, y;
	int i,j;

	char imagem[MAXIMO][MAXIMO];

	printf("Digite as coordenadas do ponto A:\n");
	scanf("%f %f", &x1, &y1);
	printf("Digite as coordenadas do ponto B:\n");
	scanf("%f %f", &x2, &y2);

	/*if(x1 == x2) exit(1);
	else {
		a = (y2-y1)/(x2-x1);
		b = y1 - a*x1;
	}*/

	for(j=0; j < MAXIMO; j++){
		for(i=0; i < MAXIMO; i++){
			imagem[i][j] = '.';
		}
	}

	/*i = x1;
	j = MAXIMO - y1;

	imagem[j][i] = 219;

	i = x2;
	j = MAXIMO - y2;

	imagem[j][i] = 219;

	x = x1+1;
	y = a*x + b;*/

	/*while (y < y2 - 1.0){
		i = x;
		j = MAXIMO - y;
		
		imagem[j][i] = 219;

		y = a*(++x) + b;
	}*/

	/*for(j=0; j < MAXIMO; j++){
		for(i=0; i < MAXIMO; i++){
			printf("%c ",imagem[j][i]);
		}
		printf("\n");
	}*/
	
	printf("\n");

    printf("\n");
    
    printf("Hoje eh dia de CQC!\n\n");
	
	transPoint(x1,y1, imagem);
	transPoint(x2,y2, imagem);
	
    rotacionaPoint(x1,y1, imagem);
    rotacionaPoint(x2,y2, imagem);
    
    for(j=0; j < MAXIMO; j++){
		for(i=0; i < MAXIMO; i++){
			printf("%c ",imagem[j][i]);
		}
		printf("\n");
	}
    printf("\n");
    printf("\n");
    getchar();
	getchar();
}
int testCoordTransToCart(FILE * f)
{
     fprintf (f, "\t+++++ Enter testCoordTransToCart() +++++\n");
     int ntests=0, res=0;
     Point Points[] = {
          Point(1, 2),
          Point(0, 0),
          Point(1, 0),
          Point(cos(pi/3), sin(pi/3)),
          Point(cos(pi/2), sin(pi/2)),
          Point(1,0),
          Point(cos(-pi/3), sin(-pi/3)),
          Point(cos(-pi/6), sin(-pi/6)),
          Point(cos(5*pi/6), sin(-2*pi/6)),
     };

     const int NPOINTS = sizeof(Points) / sizeof(*Points);
     double cosphi=1, sinphi=0;
     Point transPoint(0,0), expectedPoint(0,0);
     Point Center(0,0);
     fprintf (f, "\t\tcosphi=%.2f, sinphi=%.2f, Center(%.2f, %.2f)\n", cosphi, sinphi, Center._x, Center._y);
     for(int i=0; i<NPOINTS-1; i++) {
          transPoint = Points[i].TransformToCartesianCoordinates(Center, cosphi, sinphi);
          res += ( transPoint == Points[i] )?1:0; //phi==0!
          ntests++;
          fprintf (f, "%2d. res=%2d, P(%.2f, %.2f), T(%.2f, %.2f)\n", ntests, res, Points[i]._x, Points[i]._y, transPoint._x, transPoint._y);
     }
//--------------------------------------------------------------------------------------
     cosphi = 0.5; //  pi/3
     sinphi = 0.8660254037844386; //pi/3
     fprintf (f, "\t\tcosphi=%.2f, sinphi=%.2f, Center(%.2f, %.2f)\n", cosphi, sinphi, Center._x, Center._y);
     for(int i=0; i<NPOINTS-1; i++) {
          transPoint = Points[i].TransformToCartesianCoordinates(Center, cosphi, sinphi);
          expectedPoint = Points[i].Rotate(cosphi, sinphi);
          res += ( transPoint == expectedPoint )?1:0; //phi==0!
          ntests++;
          fprintf (f, "%2d. res=%2d, P(%.2f, %.2f), T(%.2f, %.2f), E(%.2f, %.2f)\n", ntests, res, Points[i]._x, Points[i]._y, transPoint._x, transPoint._y, expectedPoint._x, expectedPoint._y);
     }
//--------------------------------------------------------------------------------------
     cosphi = 0.5; //  -pi/3
     sinphi = -0.8660254037844386; //  -pi/3
     fprintf (f, "\t\tcosphi=%.2f, sinphi=%.2f, Center(%.2f, %.2f)\n", cosphi, sinphi, Center._x, Center._y);



     for(int i=0; i<NPOINTS-1; i++) {
          transPoint = Points[i].TransformToCartesianCoordinates(Center, cosphi, sinphi);
          expectedPoint = Points[i].Rotate(cosphi, sinphi);
          res += ( transPoint == expectedPoint )?1:0; //phi==0!
          ntests++;

          fprintf (f, "%2d. res=%2d, P(%.2f, %.2f), T(%.2f, %.2f), E(%.2f, %.2f)\n", ntests, res, Points[i]._x, Points[i]._y, transPoint._x, transPoint._y, expectedPoint._x, expectedPoint._y);

     }
//--------------------------------------------------------------------------------------

     Center._x =(1);
     Center._y =(1);
     cosphi = 0.5; //  pi/3

     sinphi = 0.8660254037844386; //pi/3

     fprintf (f, "\t\tcosphi=%.2f, sinphi=%.2f, Center(%.2f, %.2f)\n", cosphi, sinphi, Center._x, Center._y);
     for(int i=0; i<NPOINTS-1; i++) {
          transPoint = Points[i].TransformToCartesianCoordinates(Center, cosphi, sinphi);

          expectedPoint = Points[i].Rotate(cosphi, sinphi)+Center;
          res += ( transPoint == expectedPoint )?1:0; //phi==0!
          ntests++;

          fprintf (f, "%2d. res=%2d, P(%.2f, %.2f), T(%.2f, %.2f), E(%.2f, %.2f)\n", ntests, res, Points[i]._x, Points[i]._y, transPoint._x, transPoint._y, expectedPoint._x, expectedPoint._y);
     }

     fprintf (f, "\t+++++ Leave testCoordTransToCart() +++++\n\n");
     return (res==ntests)?1:0;
}