/** * Created with IntelliJ IDEA. * User: rebeccamancy * Date: 11/12/2012 * Time: 13:45 * To change this template use File | Settings | File Templates. */ /** * Points in Euclidean space defined by x and y coordinates */ public class Point { double x; double y; Point(double x, double y) { this.x = x; this.y = y; } /** * Returns the Euclidean / Cartesian distance between two points * @param pt1 First point * @param pt2 Second point * @return Distance between points */ public static double dist(Point pt1, Point pt2) { // System.err.println("("+pt1.x+","+pt1.y+")" + " ("+pt2.x+","+pt2.y+")"); return Math.sqrt( Math.pow(pt2.x-pt1.x, 2) + Math.pow(pt2.y-pt1.y, 2)); } /** * Constructor creates a new uniform random point within a rectangle delimited by min and max * @param delimMin Point corresponding to min coords * @param delimMax Point corresponding to min coords * @return a random Point within space */ Point (Point delimMin, Point delimMax) { this.x = delimMin.x + (Math.random() * ((delimMax.x - delimMin.x) + 1)); this.y = delimMin.y + (Math.random() * ((delimMax.y - delimMin.y) + 1)); } public double getX () { return this.x; } public double getY () { return this.y; } public String toString() { return "(" + this.x + "," + this.y + ")"; } }