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.

package com.maixuanviet.computationalgeometry;
 
import java.util.Scanner;
 
public class DualityTransformationofPointandLine
{
    public static void performLineTransformation(double a, double b)
    {
        System.out.println("X: " + (b / a) + ", Y: " + (b * -1));
    }
 
    public static void performPointTransformation(double x, double y)
    {
        System.out.println("y=" + (-1 * y / x) + "x +" + (-1 * y));
    }
 
    public static void main(String[] args)
    {
        System.out
                .println("Perform what transformation.\n1. Line Transformation\n2. Point Transformation");
        Scanner sc = new Scanner(System.in);
        int option = sc.nextInt();
        switch (option)
        {
            case 1:
                System.out.println("Enter the coefficients of line <y=ax-b>");
                double a = sc.nextDouble();
                double b = sc.nextDouble();
                performLineTransformation(a, b);
                break;
            case 2:
                System.out.println("Enter the coordinate of point <x, y>");
                double x = sc.nextDouble();
                double y = sc.nextDouble();
                performPointTransformation(x, y);
                break;
            default:
                break;
        }
        sc.close();
    }
}

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

Related posts:

Hướng dẫn sử dụng Java String, StringBuffer và StringBuilder
Initialize a HashMap in Java
Configure a RestTemplate with RestTemplateBuilder
Spring Boot - Cloud Configuration Server
Add Multiple Items to an Java ArrayList
Java Program to Implement TreeMap API
Java Program to Implement Floyd-Warshall Algorithm
Java Program to Construct an Expression Tree for an Prefix Expression
Daemon Threads in Java
Java Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence
Java Copy Constructor
Uploading MultipartFile with Spring RestTemplate
Java Program to Decode a Message Encoded Using Playfair Cipher
Default Password Encoder in Spring Security 5
String Operations with Java Streams
Java Program to Implement Direct Addressing Tables
Guide to Apache Commons CircularFifoQueue
Spring @RequestMapping New Shortcut Annotations
Java Program to Find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs)
The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5
Rest Web service: Filter và Interceptor với Jersey 2.x (P1)
Connect through a Proxy
Thực thi nhiều tác vụ cùng lúc như thế nào trong Java?
Tổng quan về ngôn ngữ lập trình java
Function trong Java 8
Collect a Java Stream to an Immutable Collection
A Guide to Java SynchronousQueue
Java Program to Perform Matrix Multiplication
Java Program to Implement K Way Merge Algorithm
Java String Conversions
Java Program to do a Depth First Search/Traversal on a graph non-recursively
Registration – Password Strength and Rules