0% found this document useful (0 votes)
23 views1 page

Write C++ Program To Implement Translation, Rotation and Scaling Transformations On Equilateral Triangle and Rhombus. Apply The Concept of Operator Overloading

The document contains C++ code that defines classes for geometric shapes, specifically Point, Triangle, and Rhombus. It includes methods for translating, scaling, and rotating these shapes, along with a main function that demonstrates these operations. The output displays the original shapes and their transformations after translation, scaling, and rotation.

Uploaded by

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

Write C++ Program To Implement Translation, Rotation and Scaling Transformations On Equilateral Triangle and Rhombus. Apply The Concept of Operator Overloading

The document contains C++ code that defines classes for geometric shapes, specifically Point, Triangle, and Rhombus. It includes methods for translating, scaling, and rotating these shapes, along with a main function that demonstrates these operations. The output displays the original shapes and their transformations after translation, scaling, and rotation.

Uploaded by

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

#include <iostream>

#include <cmath>
using namespace std;

class Point {
public:
float x, y;
Point(float x = 0, float y = 0) : x(x), y(y) {}
Point operator+(const Point &t) const { return Point(x + t.x, y + t.y); }
Point operator*(float s) const { return Point(x * s, y * s); }
Point operator*(const float a) const {
float r = a * (3.14159 / 180);
return Point(x * cos(r) - y * sin(r), x * sin(r) + y * cos(r));
}
void display() const { cout << "(" << x << ", " << y << ")"; }
};

class Triangle {
public:
Point p1, p2, p3;
Triangle(Point a, Point b, Point c) : p1(a), p2(b), p3(c) {}
void translate(Point t) { p1 = p1 + t, p2 = p2 + t, p3 = p3 + t; }
void scale(float s) { p1 = p1 * s, p2 = p2 * s, p3 = p3 * s; }
void rotate(float a) { p1 = p1 * a, p2 = p2 * a, p3 = p3 * a; }
void display() const { p1.display(), cout << ", ", p2.display(), cout << ", ",
p3.display(), cout << endl; }
};

class Rhombus {
public:
Point p1, p2, p3, p4;
Rhombus(Point a, Point b, Point c, Point d) : p1(a), p2(b), p3(c), p4(d) {}
void translate(Point t) { p1 = p1 + t, p2 = p2 + t, p3 = p3 + t, p4 = p4 + t; }
void scale(float s) { p1 = p1 * s, p2 = p2 * s, p3 = p3 * s, p4 = p4 * s; }
void rotate(float a) { p1 = p1 * a, p2 = p2 * a, p3 = p3 * a, p4 = p4 * a; }
void display() const { p1.display(), cout << ", ", p2.display(), cout << ", ",
p3.display(), cout << ", ", p4.display(), cout << endl; }
};

int main() {
Triangle t(Point(0, 1), Point(-0.866, -0.5), Point(0.866, -0.5));
Rhombus r(Point(-1, 0), Point(0, 1), Point(1, 0), Point(0, -1));
Point tr(2, 2);

cout << "Original Shapes:\n"; t.display(), r.display();


t.translate(tr), r.translate(tr);
cout << "\nAfter Translation:\n"; t.display(), r.display();
t.scale(2), r.scale(2);
cout << "\nAfter Scaling:\n"; t.display(), r.display();
t.rotate(30), r.rotate(30);
cout << "\nAfter Rotation:\n"; t.display(), r.display();
}

You might also like