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 <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. void performLineTransformation(double a, double b) {
  6.     printf("X: %lf, Y: %lf", (b / a), (b * -1));
  7. }
  8.  
  9. void performPointTransformation(double x, double y) {
  10.     printf("y=%lfx + %lf", (-1 * y / x), (-1 * y));
  11. }
  12.  
  13. int main(int argc, char **argv) {
  14.     printf("Perform what transformation.\n1. Line Transformation\n2. Point Transformation");
  15.  
  16.     int option;
  17.     scanf("%d", &option);
  18.     switch (option) {
  19.     case 1:
  20.         printf("Enter the coefficients of line <y=ax-b>");
  21.         double a, b;
  22.         scanf("%lf", &a);
  23.         scanf("%lf", &b);
  24.         performLineTransformation(a, b);
  25.         break;
  26.     case 2:
  27.         printf("Enter the coordinate of point <x, y>");
  28.         double x, y;
  29.         scanf("%lf", &x);
  30.         scanf("%lf", &y);
  31.         performPointTransformation(x, y);
  32.         break;
  33.     default:
  34.         break;
  35.     }
  36.     return 0;
  37. }

Output:

$ gcc DualityTransform.c
$ ./a.out
 
Perform what transformation.
1. Line Transformation
2. Point Transformation
1
Enter the coefficients of line <y=ax-b>: 1 2 3
X: 2.000000, Y: -2.000000

Sanfoundry Global Education & Learning Series – 1000 C Programs.

advertisement
advertisement

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

If you find any mistake above, kindly email to [email protected]

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 & discussions at Telegram SanfoundryClasses.