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:

advertisement
$ 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

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

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn