DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
                                   Experiment 6
Student Name: Bhumika                                    UID: 22BCS16875
Branch: BE-CSE                                           Section/Group: 626-A
Semester: 6                                              Date of Performance: 04/03/25
Subject Name: CG LAB                                     Subject Code: 22CSH-352
1. Aim:
   Analyze and implement the reflection of a triangle.
2. Objective:
   To implement and analyze the reflection of a point about a triangle.
3. Algorithm:
     Initialize Graphics Mode using initgraph().
     Take Input for triangle coordinates (x1,y1),(x2,y2),(x3,y3)(x1, y1), (x2, y2), (x3,
      y3)(x1,y1),(x2,y2),(x3,y3).
     Get Screen Dimensions (m = getmaxx(), n = getmaxy()).
     Draw Original Triangle and label it.
     Draw Coordinate Axes (X and Y).
     Reflect Along X-Axis: Update y values and draw the triangle.
           X=X and Y= -Y
     Reflect Along Y-Axis: Update x values and draw the triangle.
                     X= -X and Y= Y
4. Implementation/Code:
   #include <graphics.h>
   #include <conio.h>
   #include <iostream.h>
   int main() {
      int gd = DETECT, gm;
      initgraph(&gd, &gm, "c:\\turboc3\\bgi");
      cout << "Vikash Yadav 22BCS12274" << endl;
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
  int x1, y1, x2, y2, x3, y3;
  cout << "Enter the coordinates of the triangle:\n";
  cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
  int m = getmaxx();
  int n = getmaxy();
  setcolor(6);
  line(x1, y1, x2, y2);
  line(x2, y2, x3, y3);
  line(x3, y3, x1, y1);
  outtextxy(x1, y1 + 10, "Original Triangle");
  setcolor(4);
  line(m / 2, 0, m / 2, n);
  line(0, n / 2, m, n / 2);
  setcolor(3);
  int c1 = (n / 2) - y1;
  int c2 = (n / 2) - y2;
  int c3 = (n / 2) - y3;
  int ry1 = y1 + (c1 * 2);
  int ry2 = y2 + (c2 * 2);
  int ry3 = y3 + (c3 * 2);
  line(x1, ry1, x2, ry2);
  line(x2, ry2, x3, ry3);
  line(x3, ry3, x1, ry1);
  outtextxy(x1, ry1 + 10, "Reflection along X-axis");
  setcolor(9);
  int a1 = (m / 2) - x1;
  int a2 = (m / 2) - x2;
  int a3 = (m / 2) - x3;
  int rx1 = x1 + (a1 * 2);
  int rx2 = x2 + (a2 * 2);
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
      int rx3 = x3 + (a3 * 2);
      line(rx1, ry1, rx2, ry2);
      line(rx2, ry2, rx3, ry3);
      line(rx3, ry3, rx1, ry1);
      outtextxy(rx2 - 20, ry2 + 10, "Reflection along Y-axis");
      getch();
      closegraph();
  }
5. Output:
6. Learning Outcome:
      Understanding Reflection – Learning how reflection works.
      Coordinate System Reflection – Reflecting the triangle along x-axis and then alongy-axis
       to get the final coordinates of the reflected triangle.
      Using Graphics in C++ – Implementing graphics.h to visualize transformations.