0% found this document useful (0 votes)
33 views

Experiment Title-2.1: To Rotate A Given Triangle Clockwise and Anticlockwise About A Given Point

The document describes an experiment to rotate a triangle clockwise and anticlockwise about a given point. It includes the aim of the experiment, the algorithm and flowchart. The algorithm uses trigonometric functions like cosine, sine to calculate the new x and y coordinates of the rotated triangle vertices and draws the rotated triangle by passing the new coordinates to the drawpoly function. It provides the C code to rotate the triangle clockwise and anticlockwise by changing the signs in the trigonometric functions.

Uploaded by

Samridh Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Experiment Title-2.1: To Rotate A Given Triangle Clockwise and Anticlockwise About A Given Point

The document describes an experiment to rotate a triangle clockwise and anticlockwise about a given point. It includes the aim of the experiment, the algorithm and flowchart. The algorithm uses trigonometric functions like cosine, sine to calculate the new x and y coordinates of the rotated triangle vertices and draws the rotated triangle by passing the new coordinates to the drawpoly function. It provides the C code to rotate the triangle clockwise and anticlockwise by changing the signs in the trigonometric functions.

Uploaded by

Samridh Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment Title-2.

Student Name: Samridh Garg UID: 19BCS1815


Branch:BE-CSE Section/Group: CSE-5/C

Semester:5th Date of Performance:21/9/21


Subject Name:CG LAB Subject Code:CST-305

1. Aim/Overview of the practical:

To rotate a given triangle clockwise and anticlockwise about a given point.

2. Task to be done/ Which logistics used:

3. Algorithm/Flowchart (For programming based labs):

Aim: -To rotate a given triangle clockwise and anticlockwise about a given

point.

(a) To rotate clockwise

#include<iostream.h>

#include<conio.h>

#include<graphics.h>
#include<math.h>

void main()

clrscr();

int gd=DETECT,gm;

initgraph(&gd,&gm,"");

int x1,y1,x2,y2,x3,y3;

cout<<"Enter (x1,y1),(x2,y2),(x3,y3) for triangle : ";

cin>>x1>>y1>>x2>>y2>>x3>>y3;

int a[]={x1,y1,x2,y2,x3,y3,x1,y1};

drawpoly(4,a);

int xf=(x1+x2+x3)/3;

int yf=(y1+y2+y3)/3;

float ang;

cout<<"Enter the rotation angle :";

cin>>ang;

float rad=ang*3.1428/180;

int X1=(x1-xf)*cos(rad)-(y1-yf)*sin(rad)+xf;

int Y1=(x1-xf)*sin(rad)+(y1-yf)*cos(rad)+yf;

int X2=(x2-xf)*cos(rad)-(y2-yf)*sin(rad)+xf;

int Y2=(x2-xf)*sin(rad)+(y2-yf)*cos(rad)+yf;

int X3=(x3-xf)*cos(rad)-(y3-yf)*sin(rad)+xf;

int Y3=(x3-xf)*sin(rad)+(y3-yf)*cos(rad)+yf;

int b[]={X1,Y1,X2,Y2,X3,Y3,X1,Y1};

drawpoly(4,b);
getch();

(b) To rotate anti-clockwise

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

void main()

clrscr();

int gd=DETECT,gm;

initgraph(&gd,&gm,"");

int x1,y1,x2,y2,x3,y3;

cout<<"Enter (x1,y1),(x2,y2),(x3,y3) for triangle : ";

cin>>x1>>y1>>x2>>y2>>x3>>y3;
int a[]={x1,y1,x2,y2,x3,y3,x1,y1};

drawpoly(4,a);

int xf=(x1+x2+x3)/3;

int yf=(y1+y2+y3)/3;

float ang;

cout<<"Enter the rotation angle :";

cin>>ang;

float rad=ang*3.1428/180;

int X1=(x1-xf)*cos(rad)+(y1-yf)*sin(rad)+xf;

int Y1=-(x1-xf)*sin(rad)+(y1-yf)*cos(rad)+yf;

int X2=(x2-xf)*cos(rad)+(y2-yf)*sin(rad)+xf;

int Y2=-(x2-xf)*sin(rad)+(y2-yf)*cos(rad)+yf;

int X3=(x3-xf)*cos(rad)+(y3-yf)*sin(rad)+xf;

int Y3=-(x3-xf)*sin(rad)+(y3-yf)*cos(rad)+yf;

int b[]={X1,Y1,X2,Y2,X3,Y3,X1,Y1};

drawpoly(4,b);

getch();

}
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like