edu.princeton.plot
Class Point

java.lang.Object
  extended by edu.princeton.plot.Point
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
GameExtremePoint

public class Point
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A class representing a point in R^2, with coordinates x and y

See Also:
Serialized Form

Field Summary
private static long serialVersionUID
          Serialization ID
 double x
          x-coordinate
 double y
          y-coordinate
 
Constructor Summary
Point()
           
Point(double x, double y)
          Simple constructor
 
Method Summary
static Point affineCombo(Point p1, double alpha1, Point p2)
           
static double angleRadians(Point a, Point b, Point c)
          Returns the angle formed by the points a, b and c, with b the vertex
static double angleRadiansAbs(Point a, Point b, Point c)
          Returns the angle formed by the points a, b and c, with b the vertex, normalized to [0, Pi]
private static double boundToOne(double x)
          Bounds a number x to the interval [-1, 1]
 Point clone()
          Returns a deep-copy of this Point
 Point deepCopy()
           
 double dot(Point p)
          Returns the dot product of this and p.
static double dot(Point p1, Point p2)
          Returns the dot product of p1 and p2.
 boolean equals(java.lang.Object o)
           
 double euclidDistance(Point p)
           
static double euclidDistance(Point p1, Point p2)
          The Euclidean-distance between points p1 and p2;
 double get(int index)
          Convenience method to get x and y by numerical index
 Point getClockwiseNormal()
           
static Point getNaN()
           
 double getX()
           
 double getY()
           
 int hashCode()
           
static double interpXonY(Point p1, Point p2, double y)
          Taking points p1, p2 as two points defining a line, calculates the value of x such that the point (x,y) lies on the same line
static double interpYonX(Point p1, Point p2, double x)
          Taking points p1, p2 as two points defining a line, calculates the value of y such that the point (x,y) lies on the same line
 boolean isCloseTo(Point point, double err)
          Check if this point is within err of the point point
 double L1norm()
           
 double L2norm()
           
static Point linearCombo(Point p1, double a1, Point p2, double a2)
           
 double LInfnorm()
           
 Point minus(Point p)
           
 double norm(int n)
           
 Point normalize()
           
 Point plus(Point p)
           
 Point rotate(double theta)
           
 void roundEquals(int digits)
          Rounds the coordinates of this points to digits many digits
static
<T extends Point>
void
roundPointList(java.util.ArrayList<T> list, int digits)
          Rounds the list of points list to digits many digits
 void set(int index, double value)
           
 void setX(double x)
           
 void setY(double y)
           
 double supDistance(Point p)
           
static double supDistance(Point p1, Point p2)
          The sup-distance between points p1 and p2;
 double supNorm()
          TODO Put here a description of what this method does.
 Point times(double m)
           
 double[] toArray()
           
 java.lang.String toString()
           
 java.lang.String toString(int digits, boolean paren)
          Returns a string representation of this point
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serialization ID

See Also:
Constant Field Values

x

public double x
x-coordinate


y

public double y
y-coordinate

Constructor Detail

Point

public Point()

Point

public Point(double x,
             double y)
Simple constructor

Parameters:
x - x-coordinate
y - y-coordinate
Method Detail

getNaN

public static Point getNaN()

getX

public double getX()

get

public double get(int index)
Convenience method to get x and y by numerical index

Parameters:
index - x is zero, y is one (1)
Returns:
index == 0 ? x : y

set

public void set(int index,
                double value)

getY

public double getY()

setX

public void setX(double x)

setY

public void setY(double y)

clone

public Point clone()
Returns a deep-copy of this Point

Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int digits,
                                 boolean paren)
Returns a string representation of this point

Parameters:
digits - the number of digits to use
paren - use parentheses/comma or no-parentheses/tab
Returns:
the point as text

angleRadiansAbs

public static double angleRadiansAbs(Point a,
                                     Point b,
                                     Point c)
Returns the angle formed by the points a, b and c, with b the vertex, normalized to [0, Pi]

Parameters:
a -
b -
c -
Returns:
the angle, in Radians, normalized to [0, Pi]

angleRadians

public static double angleRadians(Point a,
                                  Point b,
                                  Point c)
Returns the angle formed by the points a, b and c, with b the vertex

Parameters:
a -
b -
c -
Returns:
the angle, in Radians

boundToOne

private static double boundToOne(double x)
Bounds a number x to the interval [-1, 1]

Parameters:
x -
Returns:
Max( Min(x, 1), -1 )

isCloseTo

public boolean isCloseTo(Point point,
                         double err)
Check if this point is within err of the point point

Parameters:
point -
err - distance
Returns:
supDistance(this, point) < err

dot

public double dot(Point p)
Returns the dot product of this and p.

Parameters:
p -
Returns:
this (dot) p

dot

public static double dot(Point p1,
                         Point p2)
Returns the dot product of p1 and p2.

Parameters:
p1 -
p2 -
Returns:
p1 (dot) p2

euclidDistance

public static double euclidDistance(Point p1,
                                    Point p2)
The Euclidean-distance between points p1 and p2;

Parameters:
p1 -
p2 -
Returns:
sqrt( |p1.x-p2.x|^2, |p1.y-p2.y|^2 )

supDistance

public static double supDistance(Point p1,
                                 Point p2)
The sup-distance between points p1 and p2;

Parameters:
p1 -
p2 -
Returns:
max( |p1.x-p2.x|, |p1.y-p2.y| )

supDistance

public double supDistance(Point p)

euclidDistance

public double euclidDistance(Point p)

interpYonX

public static double interpYonX(Point p1,
                                Point p2,
                                double x)
Taking points p1, p2 as two points defining a line, calculates the value of y such that the point (x,y) lies on the same line

Parameters:
p1 -
p2 -
x -
Returns:
the interpolated value of y

interpXonY

public static double interpXonY(Point p1,
                                Point p2,
                                double y)
Taking points p1, p2 as two points defining a line, calculates the value of x such that the point (x,y) lies on the same line

Parameters:
p1 -
p2 -
y -
Returns:
the interpolated value of x

roundEquals

public void roundEquals(int digits)
Rounds the coordinates of this points to digits many digits

Parameters:
digits - precision in digits

roundPointList

public static <T extends Point> void roundPointList(java.util.ArrayList<T> list,
                                                    int digits)
Rounds the list of points list to digits many digits

Parameters:
list - list of Point
digits -

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getClockwiseNormal

public Point getClockwiseNormal()
Returns:
the clockwise normal vector to the point

linearCombo

public static Point linearCombo(Point p1,
                                double a1,
                                Point p2,
                                double a2)
Returns:
a1 * p1 + a2 * p2

affineCombo

public static Point affineCombo(Point p1,
                                double alpha1,
                                Point p2)
Returns:
alpha1 * p1 + (1-alpha1) * p2

minus

public Point minus(Point p)
Returns:
this - p

plus

public Point plus(Point p)
Returns:
this + p

times

public Point times(double m)
Returns:
m * x

normalize

public Point normalize()
Returns:
(x,y) / (x*x + y*y)

toArray

public double[] toArray()

rotate

public Point rotate(double theta)

deepCopy

public Point deepCopy()

supNorm

public double supNorm()
TODO Put here a description of what this method does.

Returns:

L2norm

public double L2norm()

L1norm

public double L1norm()

LInfnorm

public double LInfnorm()

norm

public double norm(int n)