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:

advertisement
$ 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)
Press return to continue

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

Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
advertisement

Here’s the list of Best Books in C++ Programming, Data Structures and Algorithms.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.