Gets the straight line distance between the pair of points {(x,y),(x1,y1)}. - Java 2D Graphics

Java examples for 2D Graphics:Line

Description

Gets the straight line distance between the pair of points {(x,y),(x1,y1)}.

Demo Code


//package com.java2s;

public class Main {
    /**/*from   w w w  .j  av  a2s .co  m*/
     * Gets the straight line distance between the pair of points {(x,y),(x1,y1)}.
     * 
     * @param x The first x coordinate
     * @param y The first y coordinate
     * @param x1 The second x coordinate
     * @param y1 The second y coordinate
     * @return The straight line distances between {(x,y),(x1,y1)}
     */
    public static double getDistance(double x, double y, double x1,
            double y1) {
        return Math.sqrt(Math.pow(x - x1, 2) + Math.pow(y - y1, 2));
    }
}

Related Tutorials