Java Program to Show the Duality Transformation of Line and Point

This is a java program to show the duality transformation of line and point. The transformation corresponds from line to point and point to line.

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

  1.  
  2. package com.sanfoundry.computationalgeometry;
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class DualityTransformationofPointandLine
  7. {
  8.     public static void performLineTransformation(double a, double b)
  9.     {
  10.         System.out.println("X: " + (b / a) + ", Y: " + (b * -1));
  11.     }
  12.  
  13.     public static void performPointTransformation(double x, double y)
  14.     {
  15.         System.out.println("y=" + (-1 * y / x) + "x +" + (-1 * y));
  16.     }
  17.  
  18.     public static void main(String[] args)
  19.     {
  20.         System.out
  21.                 .println("Perform what transformation.\n1. Line Transformation\n2. Point Transformation");
  22.         Scanner sc = new Scanner(System.in);
  23.         int option = sc.nextInt();
  24.         switch (option)
  25.         {
  26.             case 1:
  27.                 System.out.println("Enter the coefficients of line <y=ax-b>");
  28.                 double a = sc.nextDouble();
  29.                 double b = sc.nextDouble();
  30.                 performLineTransformation(a, b);
  31.                 break;
  32.             case 2:
  33.                 System.out.println("Enter the coordinate of point <x, y>");
  34.                 double x = sc.nextDouble();
  35.                 double y = sc.nextDouble();
  36.                 performPointTransformation(x, y);
  37.                 break;
  38.             default:
  39.                 break;
  40.         }
  41.         sc.close();
  42.     }
  43. }

Output:

$ javac DualityTransformationofPointandLine.java
$ java DualityTransformationofPointandLine
 
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

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement
advertisement

Here’s the list of Best Books in Java 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.