0% found this document useful (0 votes)
6 views3 pages

Harcg 5

The document outlines Experiment 5 for a Computer Graphics course, focusing on implementing clockwise and anticlockwise rotations of a triangle using C++. It includes code snippets for both rotations, demonstrating how to calculate new coordinates based on user input for angles. The learning outcomes emphasize understanding graphics programming, coordinate transformations, and practical applications in visual demonstrations.

Uploaded by

netsolutions.org
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)
6 views3 pages

Harcg 5

The document outlines Experiment 5 for a Computer Graphics course, focusing on implementing clockwise and anticlockwise rotations of a triangle using C++. It includes code snippets for both rotations, demonstrating how to calculate new coordinates based on user input for angles. The learning outcomes emphasize understanding graphics programming, coordinate transformations, and practical applications in visual demonstrations.

Uploaded by

netsolutions.org
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/ 3

DEPARTMENTOF

COMPUTERSCIENCE&ENGINEERING

Experiment 5
Student Name: Harshit Singh Chandel UID: 22BCS10013
Branch: BE CSE Section/Group:IOT-608-A
Semester: 6th Date of Performance: 17-02-2025
Subject Name: Computer Graphics Subject Code: 22CSH-352

1. Aim: Implement clockwise and anticlockwise rotation of a triangle about a specified


point and evaluate the results.

2. Objective: To perform and visualize clockwise and anticlockwise rotations of a triangle


about a specified point.

3. Implementation/Code:
a) To rotate clockwise:
#include <iostream.h>
#include <graphics.h>
#include <math.h>
#include <conio.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
int x1, y1, x2, y2, x3, y3;
cout << "Enter the coordinates (x1, y1), (x2, y2), (x3, y3) for the triangle: ";
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
int points[] = {x1, y1, x2, y2, x3, y3, x1, y1};
drawpoly(4, points);
outtextxy(50,70,"22BCS10013_Harshit");
int xf = (x1 + x2 + x3) / 3;
int yf = (y1 + y2 + y3) / 3;
float ang;
cout << "Enter the clockwise 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;

22BCS10013_HARSHIT
DEPARTMENTOF
COMPUTERSCIENCE&ENGINEERING
int rotatedPoints[] = {X1, Y1, X2, Y2, X3, Y3, X1, Y1};
drawpoly(4, rotatedPoints);

getch();
closegraph();

return 0;
}

Output

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,"C:\\Turboc3\\BGI");
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);
outtextxy(50,70,"22BCS10013_Harshit");
int xf=(x1+x2+x3)/3;
int yf=(y1+y2+y3)/3;
float ang;
cout<<"Enter the anticlockwise rotation angle :";
cin>>ang;
float rad=ang*3.1428/180;
int X1=(x1-xf)*cos(rad)+(y1-yf)*sin(rad)+xf;
22BCS10013_HARSHIT
DEPARTMENTOF
COMPUTERSCIENCE&ENGINEERING
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();
}

Output

4. Learning Outcomes

1. Learn how to implement and apply the rotation in clockwise and anti-clockwise
for efficiently rotating a triangle on a 2D graphics window.
2. Learn how to work with coordinate transformations for graphical objects,
3. Understand the process of initializing and closing the graphics mode in C++ using
initgraph() and closegraph() functions.
4. Apply graphics programming to create visual demonstrations, which can be further
extended to develop simple games, animations, or user interfaces.
5. Recognize the role of rotation in triangle drawing.

22BCS10013_HARSHIT

You might also like