All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aima.core.util.datastructure.Point2D Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

There is a newer version: 3.0.0
Show newest version
package aima.core.util.datastructure;

/**
 * Simplified version of java.awt.geom.Point2D. We do not want
 * dependencies to presentation layer packages here.
 * 
 * @author R. Lunde
 * @author Mike Stampone
 */
public class Point2D {
	private double x;
	private double y;

	public Point2D(double x, double y) {
		this.x = x;
		this.y = y;
	}

	/**
	 * Returns the X coordinate of this Point2D in
	 * double precision.
	 * 
	 * @return the X coordinate of this Point2D.
	 */
	public double getX() {
		return x;
	}

	/**
	 * Returns the Y coordinate of this Point2D in
	 * double precision.
	 * 
	 * @return the Y coordinate of this Point2D.
	 */
	public double getY() {
		return y;
	}

	/**
	 * Returns the Euclidean distance between a specified point and this point.
	 * 
	 * @return the Euclidean distance between a specified point and this point.
	 */
	public double distance(Point2D pt) {
		double result = (pt.getX() - x) * (pt.getX() - x);
		result += (pt.getY() - y) * (pt.getY() - y);
		return Math.sqrt(result);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy