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 – Try with Resources
Chuyển đổi giữa các kiểu dữ liệu trong Java
Java Program to Implement HashSet API
Xử lý ngoại lệ đối với trường hợp ghi đè phương thức trong java
Java Program to Find Number of Spanning Trees in a Complete Bipartite Graph
Hashtable trong java
Java Program to Implement Sparse Matrix
Biến trong java
Dockerizing a Spring Boot Application
Java NIO2 Path API
The Difference Between Collection.stream().forEach() and Collection.forEach()
Java Program to Implement Wagner and Fisher Algorithm for online String Matching
Mix plain text and HTML content in a mail
A Guide to Apache Commons Collections CollectionUtils
Java – String to Reader
Abstract class và Interface trong Java
Java Program to Implement IdentityHashMap API
Java Program to Generate Date Between Given Range
The Basics of Java Security
Spring Webflux with Kotlin
Spring Boot - Cloud Configuration Server
Java Program to Find Nearest Neighbor Using Linear Search
Removing all duplicates from a List in Java
An Intro to Spring Cloud Zookeeper
Lớp Collections trong Java (Collections Utility Class)
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
SOAP Web service: Upload và Download file sử dụng MTOM trong JAX-WS
Tạo ứng dụng Java RESTful Client với thư viện Retrofit
Using the Map.Entry Java Class
Create Java Applet to Simulate Any Sorting Technique
Introduction to Spring Cloud CLI
“Stream has already been operated upon or closed” Exception in Java