/* * Point.java * * Version: * $Id: Point.txt,v 1.1 2001/01/27 19:17:56 mks Exp $ * * * Revisions: * $Log: Point.txt,v $ * Revision 1.1 2001/01/27 19:17:56 mks * Initial revision * * Revision 1.1 2001/01/22 03:58:55 mks * Initial revision * */ /** * This class defines points on a standard Cartesian (XY) plane. */ public class Point { private double xCoordinate; // The X coordinate of this point private double yCoordinate; // The Y coordinate of this point /** * Create a point at the origin (x = y = 0). */ public Point() { xCoordinate = 0; yCoordinate = 0; } /** * Create a point at the specified coordinate. * * @param x The X coordinate * @param y The Y coordinate */ public Point( double x, double y ) { xCoordinate = x; yCoordinate = y; } /** * Change the X coordinate of the point. * * @param x The new X coordinate */ public void setX( double x ) { xCoordinate = x; } /** * Change the Y coordinate of the point. * * @param y The new Y coordinate */ public void setY( double y ) { yCoordinate = y; } /** * Retrieve the X coordinate of the point. * * @return The X coordinate of the point */ public double getX() { return xCoordinate; } /** * Retrieve the Y coordinate of the point. * * @return The Y coordinate of the point */ public double getY() { return yCoordinate; } /** * Determine the distance between the origin and the point. * * @return The distance between the point and the origin */ public double distanceFromOrigin() { return Math.sqrt( xCoordinate * xCoordinate + yCoordinate * yCoordinate ); } /** * Determine the distance between two points * * @param p The point to determine the distance from * * @return The distance between the two points */ public double distanceFrom( Point p ) { double diffX = xCoordinate - p.getX(); double diffY = yCoordinate - p.getY(); return Math.sqrt( Math.pow( diffX, 2 ) + Math.pow( diffY, 2 ) ); } } // Point