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. So it can have two cases −

Case-1: A point (a, b) is transformed to the line (y = ax − b).

Case-2: A line D(y = cx + d) is transformed to the point D’(c, −d).

Functions and pseudocodes

Function LineTransformation(double c, double d)

Print C: (d / c)
D: (d * -1)

Function PointTransformation(double x, double y)

Print a = (-1 * y / x)
b = (-1 * y)

Example

#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
void LineTransformation(double c, double d) {
   cout << "C: " << (d / c) << ", D: " << (d * -1);
}
void PointTransformation(double x, double y) {
   cout << "y=" << (-1 * y / x) << "x +" << (-1 * y);
}
int main(int argc, char **argv) {
   cout << "\n1. Line Transformation\n2. Point Transformation";
   int c;
   cin >> c;
   switch (c) {
      case 1:
         cout << "Enter the coefficients of line y=ax-b:";
         double a, b;
         cin >> a >> b;
         LineTransformation(a, b);
         break;
      case 2:
         cout << "Enter the coordinate of point <a, b>";
         double x, y;
         cin >> x >> y;
         PointTransformation(x, y);
         break;
      default:
         break;
   }
}

Output

1. Line Transformation
2. Point Transformation
1
Enter the coefficients of line y=ax-b:
1
2
C: 2, D: -2

1. Line Transformation
2. Point Transformation
2
Enter the coordinate of point <a, b>
1
2
y=-2x +-2

Updated on: 30-Jul-2019

143 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements