# C++ Program to Show the Duality Transformation of Line and Point

«
»
This is a C++ program to show the duality transformation of line and point. The transformation corresponds from line to point and point to line.

Here is source code of the C++ Program to Show the Duality Transformation of Line and Point. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

1. #include <iostream>
2. #include <time.h>
3. #include <stdlib.h>
4.
5. using namespace std;
6.
7. void performLineTransformation(double a, double b)
8. {
9.     cout << "X: " << (b / a) << ", Y: " << (b * -1);
10. }
11.
12. void performPointTransformation(double x, double y)
13. {
14.     cout << "y=" << (-1 * y / x) << "x +" << (-1 * y);
15. }
16.
17. int main(int argc, char **argv)
18. {
19.     cout
20.             << "Perform what transformation.\n1. Line Transformation\n2. Point Transformation";
21.
22.     int option;
23.     cin >> option;
24.     switch (option)
25.     {
26.         case 1:
27.             cout << "Enter the coefficients of line <y=ax-b>";
28.             double a, b;
29.             cin >> a >> b;
30.             performLineTransformation(a, b);
31.             break;
32.         case 2:
33.             cout << "Enter the coordinate of point <x, y>";
34.             double x, y;
35.             cin >> x >> y;
36.             performPointTransformation(x, y);
37.             break;
38.         default:
39.             break;
40.     }
41. }

Output:

\$ g++ DualityTransformation.cpp
\$ a.out

Perform what transformation.
1. Line Transformation
2. Point Transformation
1
Enter the coefficients of line <y=ax-b>
1 2
X: 2.0, Y: -2.0

Perform what transformation.
1. Line Transformation
2. Point Transformation
2
Enter the coordinate of point <x, y>
2 -2
y=1.0x +2.0
------------------
(program exited with code: 0)

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

Note: Join free Sanfoundry classes at Telegram or Youtube