This document discusses rotating a 2D line by a specified angle. It includes the necessary header files, declares variables to store the line endpoints and rotation values, initializes graphics mode, gets user input for the initial line and rotation angle, performs the rotation calculations, draws the original and rotated lines, and closes the graphics window. The key steps are: 1) getting user input for an initial line and rotation angle, 2) performing matrix calculations to rotate the line endpoints by the input angle, and 3) drawing the original and rotated lines.
1 of 1
Download to read offline
More Related Content
2 d rotation
1. 2D Rotation:
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
void main()
{
int graphdriver=DETECT,graphmode,errorcode;
int i;
int x2,y2,x1,y1,x,y,xn,yn;
double r11,r12,r21,r22,th;
clrscr();
printf("Enter the 2 line end points:");
printf("x1,y1,x2,y2");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
initgraph(&graphdriver,&graphmode,"c:tcbgi");
line(x1,y1,x2,y2);
printf("nnn[ Enter the angle");
scanf("%lf",&th);
r11=cos((th*3.1428)/180);
r12=sin((th*3.1428)/180);
r21=(-sin((th*3.1428)/180));
r22=cos((th*3.1428)/180);
xn=((x2*r11)-(y2*r21));
(x1*r11)-(y1*r21) (x1*r12)+(y1*r22) (x2*r11)-(y2*r21) (x2*r12)+(y2*r22)
yn=((x2*r12)+(y2*r22));
line(x1,y1,xn,yn);
getch();
closegraph();