Tuesday, 28 November 2017

Java Program to Show the Duality Transformation of Line and Point


Code:

package com.executecodes.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 ");
                double a = sc.nextDouble();
                double b = sc.nextDouble();
                performLineTransformation(a, b);
                break;
            case 2:
                System.out.println("Enter the coordinate of point ");
                double x = sc.nextDouble();
                double y = sc.nextDouble();
                performPointTransformation(x, y);
                break;
            default:
                break;
        }
        sc.close();
    }
}


Output:

Perform what transformation.
1. Line Transformation
2. Point Transformation
1
Enter the coefficients of line
1 2
X: 2.0, Y: -2.0

Perform what transformation.
1. Line Transformation
2. Point Transformation
2
Enter the coordinate of point
2 -2
y=1.0x +2.0



 More Java Programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...