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:

Java Program to find the maximum subarray sum using Binary Search approach
Working with Kotlin and JPA
Java Program to Implement Gaussian Elimination Algorithm
Java Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach
Java Program to Implement Karatsuba Multiplication Algorithm
Spring Data Reactive Repositories with MongoDB
Spring RestTemplate Error Handling
Use Liquibase to Safely Evolve Your Database Schema
Java Program to Encode a Message Using Playfair Cipher
Java Program to Find the Shortest Path from Source Vertex to All Other Vertices in Linear Time
Java Program to Perform Inorder Recursive Traversal of a Given Binary Tree
Assertions in JUnit 4 and JUnit 5
Java Program to Implement Sieve Of Atkin
Java CyclicBarrier vs CountDownLatch
Java Program to Implement the Hungarian Algorithm for Bipartite Matching
Java Program to Implement Interval Tree
Java Program to Implement LinkedHashMap API
Spring Boot Actuator
Java Program to Use Dynamic Programming to Solve Approximate String Matching
Check If a String Is Numeric in Java
Java Program to Implement Ternary Heap
Java – Byte Array to Reader
Marker Interface trong Java
Java Program to Implement CopyOnWriteArrayList API
Hướng dẫn Java Design Pattern – Dependency Injection
A Custom Data Binder in Spring MVC
Java Streams vs Vavr Streams
Java Program to do a Depth First Search/Traversal on a graph non-recursively
Java Program to Implement LinkedBlockingQueue API
Tạo ứng dụng Java RESTful Client với thư viện OkHttp
Working with Network Interfaces in Java
Java Program to Implement the Checksum Method for Small String Messages and Detect