0% found this document useful (0 votes)
9 views8 pages

CG4

The provided C++ code defines a class 'Transform' that handles geometric transformations such as translation, scaling, and rotation of a graphical object based on user input. The program initializes a graphics window, accepts the coordinates of the object's edges, and applies the selected transformation before displaying the transformed object. The user can choose the type of transformation and input the necessary parameters to manipulate the object's position or size.

Uploaded by

abhinavsargar1
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)
9 views8 pages

CG4

The provided C++ code defines a class 'Transform' that handles geometric transformations such as translation, scaling, and rotation of a graphical object based on user input. The program initializes a graphics window, accepts the coordinates of the object's edges, and applies the selected transformation before displaying the transformed object. The user can choose the type of transformation and input the necessary parameters to manipulate the object's position or size.

Uploaded by

abhinavsargar1
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/ 8

CODE:

#include <iostream>

#include <graphics.h>

#include <math.h>

using namespace std;

class Transform {

public:

int m, a[20][20], c[20][20];

void accept() {

cout << "\nEnter the Number Of Edges: ";

cin >> m;

cout << "\nEnter The Coordinates: ";

for (int i = 0; i < m; i++) {

for (int j = 0; j < 3; j++) {

if (j >= 2)

a[i][j] = 1;

else

cin >> a[i][j];

void object() {
int gd, gm;

gd = DETECT;

initgraph(&gd, &gm, NULL);

line(300.0, 0.0, 300.0, 600.0);

line(0, 300, 600, 300);

for (int i = 0; i < m - 1; i++) {

line(300 + a[i][0], 300 - a[i][1], 300 + a[i + 1][0], 300 - a[i + 1][1]);

line(300 + a[0][0], 300 - a[0][1], 300 + a[m - 1][0], 300 - a[m - 1][1]);

for (int i = 0; i < m - 1; i++) {

line(300 + c[i][0], 300 - c[i][1], 300 + c[i + 1][0], 300 - c[i + 1][1]);

line(300 + c[0][0], 300 - c[0][1], 300 + c[m - 1][0], 300 - c[m - 1][1]);

cout << "Press 1 to continue";

int temp;

cin >> temp;

closegraph();

void multiply(float b[20][20]) {

for (int i = 0; i < m; i++) {

for (int j = 0; j < m; j++) {


c[i][j] = 0;

for (int k = 0; k < m; k++) {

c[i][j] += (a[i][k] * b[k][j]);

void translate(float tx, float ty) {

float b[20][20] = {

{1, 0, 0},

{0, 1, 0},

{tx, ty, 1}

};

multiply(b);

object();

void scale(float sx, float sy) {

float b[20][20] = {

{sx, 0, 0},

{0, sy, 0},

{0, 0, 1}

};
multiply(b);

object();

void rotate(float deg) {

float theta = deg * (3.14 / 180);

float b[20][20] = {

{cos(theta), sin(theta), 0},

{sin(-theta), cos(theta), 0},

{0, 0, 1}

};

multiply(b);

object();

};

int main() {

Transform t;

t.accept();

int ch;

cout << "\nEnter your choice"

<< "\n1. Translation"

<< "\n2. Scaling"

<< "\n3. Rotation: ";


cin >> ch;

float tx, ty, sx, sy;

float deg;

if (ch == 1) {

cout << "\nTRANSLATION OPERATION\nEnter value for tx and ty: ";

cin >> tx >> ty;

t.translate(tx, ty);

} else if (ch == 2) {

cout << "\nSCALING OPERATION\nEnter value for sx, sy: ";

cin >> sx >> sy;

t.scale(sx, sy);

} else if (ch == 3) {

cout << "\nROTATION OPERATION\nEnter value for angle: ";

cin >> deg;

t.rotate(deg);

} else {

cout << "\nInvalid choice";

getch();

return 0;

}
USER INPUT:

OUTPUT:
USER INPUT:

OUTPUT:
USER INPUT:

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy