Write a program for 2D Rotation in Anti Clock Wise direction program in C

/*
    2D Rotation
    Anti Clock Wise Rotation
*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
  int gd=DETECT,gm;
  int x1,y1,x2,y2;
  float angle,r11,r12,r21,r22,xn,yn;

  clrscr();

  printf("\n\n Enter the points of line: ");
  scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

  printf("\n\n Enter the angle to rotate :  ");
  scanf("%f",&angle);
  initgraph(&gd,&gm,"C:\\turboc3\\bgi");

  line(x1,y1,x2,y2);

  r11=  cos(angle);
  r12=  sin(angle);
  r21=  -sin(angle);
  r22=  cos(angle);

  xn=(x1*r11) + (y1*r21);
  yn=(y1*r11) + (x1*r12);

  line(x1,y1,xn,yn);

  getch();
  closegraph();
}

Previous
Next Post »