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:

Spring MVC Custom Validation
Tìm hiểu về xác thực và phân quyền trong ứng dụng
The Registration API becomes RESTful
Guide to Spring Cloud Kubernetes
Hướng dẫn Java Design Pattern – Factory Method
The DAO with JPA and Spring
Java Program to Compute the Area of a Triangle Using Determinants
ETags for REST with Spring
Convert Character Array to String in Java
Flattening Nested Collections in Java
Java Program to Implement the Hungarian Algorithm for Bipartite Matching
Loại bỏ các phần tử trùng trong một ArrayList như thế nào?
Introduction to the Functional Web Framework in Spring 5
REST Web service: Basic Authentication trong Jersey 2.x
Spring Cloud – Securing Services
Rest Web service: Filter và Interceptor với Jersey 2.x (P1)
Hướng dẫn sử dụng Java Annotation
Debugging Reactive Streams in Java
Java Program to Implement Sorted Vector
Java Program to Perform Encoding of a Message Using Matrix Multiplication
Java Program to Implement Selection Sort
Spring Boot - Build Systems
Remove HTML tags from a file to extract only the TEXT
Java Program to Check if an UnDirected Graph is a Tree or Not Using DFS
The Dining Philosophers Problem in Java
Rest Web service: Filter và Interceptor với Jersey 2.x (P2)
Hướng dẫn Java Design Pattern – MVC
Java Program to Check Whether a Weak Link i.e. Articulation Vertex Exists in a Graph
Java Program to Implement Dijkstra’s Algorithm using Set
Spring Boot Actuator
The Modulo Operator in Java
Java Program to Permute All Letters of an Input String