edu.harvard.seas.iis.util.geom2D
Class Geom2DUtils

java.lang.Object
  extended by edu.harvard.seas.iis.util.geom2D.Geom2DUtils

public class Geom2DUtils
extends java.lang.Object

Author:
kgajos with some code copied from org/metagraph/utility/graphics/GraphicsUtil.java

Constructor Summary
Geom2DUtils()
           
 
Method Summary
static double getAngle(java.awt.Point p1, java.awt.Point p2)
          Returns the angle of the vector from p1 to p2
static java.awt.Point getCenter(java.awt.Dimension dim)
           
static java.awt.Point getCenter(java.awt.Rectangle loc)
           
static java.awt.Point[] getConnectingLine(java.awt.Point start, java.awt.Rectangle r2)
           
static java.awt.Point[] getConnectingLine(java.awt.Rectangle r1, java.awt.Rectangle r2)
          Find the shortest connecting line between two rectangles.
static double getDistance(double p1x, double p1y, double p2x, double p2y)
           
static double getDistance(double x, double y, java.awt.Polygon polygn)
          computes the distance from the point to the nearest point on the polygon boundary (works for points insider or outside the plygon)
static double getDistance(java.awt.Point point)
          Returns the norm of the vector represented by point
static double getDistance(java.awt.Point point1, java.awt.Point point2)
          Computes distance between two points
static java.awt.Dimension getMax(java.awt.Dimension d1, java.awt.Dimension d2)
           
static java.awt.Dimension getMaxInPlace(java.awt.Dimension res, java.awt.Dimension other)
          computes max of the two dimensions but instead of creating a new return object, it modifies the first parameter to contain the answer
static java.awt.Dimension getMaxInPlace(java.awt.Dimension res, int otherWidth, int otherHeight)
           
static java.awt.Dimension getMin(java.awt.Dimension d1, java.awt.Dimension d2)
           
static java.awt.Dimension getMinInPlace(java.awt.Dimension res, java.awt.Dimension other)
          computes min of the two dimensions but instead of creating a new return object, it modifies the first parameter to contain the answer
static java.awt.Insets getMinInPlace(java.awt.Insets res, java.awt.Insets other)
           
static java.awt.Dimension getSumInPlace(java.awt.Dimension res, java.awt.Dimension other)
           
static java.awt.Dimension getSumInPlace(java.awt.Dimension res, int x, int y)
           
static java.awt.Point getVector(java.awt.Point start, java.awt.Point end)
           
static java.awt.Point getXY(double distance, double angle)
          Converts vector representation from polar to Euclidian coordinates
static java.awt.Point getXY(java.awt.Point offset, double distance, double angle)
           
static java.awt.Rectangle interpolate(java.awt.Rectangle start, java.awt.Rectangle target, double fraction, java.awt.Rectangle res)
          Returns a rectangle that is an interpolation between start and target; if res is not null, the result will be put into it and returned; if res is null, a new Rectangle object will be allocated
static java.awt.Point lineSegmentIntersection(java.awt.Point line1P1, java.awt.Point line1P2, java.awt.Point line2P1, java.awt.Point line2P2)
          Determine the intersection point of two line segments, or return null if no intersection.
static double[] rotate(double x, double y, double angle)
           
static java.awt.Point rotate(java.awt.Point point, double angle)
          Rotate a point around the origin
static java.awt.Point translate(java.awt.Point point, double distance, double angle)
           
static java.awt.Point translate(java.awt.Point point, java.awt.Point offset)
           
static java.awt.Point uniqueLineSegmentRectangleIntersection(java.awt.Point p1, java.awt.Point p2, java.awt.Rectangle r)
          Determine the unique intersection point of a line segment and a rectangle.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Geom2DUtils

public Geom2DUtils()
Method Detail

rotate

public static java.awt.Point rotate(java.awt.Point point,
                                    double angle)
Rotate a point around the origin

Parameters:
point - point to be rotated
angle - the rotation angle (in radians)
Returns:
the new point object rotated

rotate

public static double[] rotate(double x,
                              double y,
                              double angle)

translate

public static java.awt.Point translate(java.awt.Point point,
                                       java.awt.Point offset)

translate

public static java.awt.Point translate(java.awt.Point point,
                                       double distance,
                                       double angle)

getDistance

public static double getDistance(java.awt.Point point1,
                                 java.awt.Point point2)
Computes distance between two points

Parameters:
point1 -
point2 -
Returns:

getDistance

public static double getDistance(double p1x,
                                 double p1y,
                                 double p2x,
                                 double p2y)

getDistance

public static double getDistance(double x,
                                 double y,
                                 java.awt.Polygon polygn)
computes the distance from the point to the nearest point on the polygon boundary (works for points insider or outside the plygon)

Parameters:
x -
y -
polygn -
Returns:

getDistance

public static double getDistance(java.awt.Point point)
Returns the norm of the vector represented by point

Parameters:
point -
Returns:

getVector

public static java.awt.Point getVector(java.awt.Point start,
                                       java.awt.Point end)

getXY

public static java.awt.Point getXY(double distance,
                                   double angle)
Converts vector representation from polar to Euclidian coordinates

Parameters:
distance -
angle -
Returns:

getXY

public static java.awt.Point getXY(java.awt.Point offset,
                                   double distance,
                                   double angle)

getCenter

public static java.awt.Point getCenter(java.awt.Dimension dim)

getCenter

public static java.awt.Point getCenter(java.awt.Rectangle loc)

getMin

public static java.awt.Dimension getMin(java.awt.Dimension d1,
                                        java.awt.Dimension d2)

getMinInPlace

public static java.awt.Dimension getMinInPlace(java.awt.Dimension res,
                                               java.awt.Dimension other)
computes min of the two dimensions but instead of creating a new return object, it modifies the first parameter to contain the answer

Parameters:
res -
other -
Returns:

getMax

public static java.awt.Dimension getMax(java.awt.Dimension d1,
                                        java.awt.Dimension d2)

getMaxInPlace

public static java.awt.Dimension getMaxInPlace(java.awt.Dimension res,
                                               int otherWidth,
                                               int otherHeight)

getMaxInPlace

public static java.awt.Dimension getMaxInPlace(java.awt.Dimension res,
                                               java.awt.Dimension other)
computes max of the two dimensions but instead of creating a new return object, it modifies the first parameter to contain the answer

Parameters:
res -
other -
Returns:

getSumInPlace

public static java.awt.Dimension getSumInPlace(java.awt.Dimension res,
                                               java.awt.Dimension other)

getSumInPlace

public static java.awt.Dimension getSumInPlace(java.awt.Dimension res,
                                               int x,
                                               int y)

getMinInPlace

public static java.awt.Insets getMinInPlace(java.awt.Insets res,
                                            java.awt.Insets other)

getAngle

public static double getAngle(java.awt.Point p1,
                              java.awt.Point p2)
Returns the angle of the vector from p1 to p2

Parameters:
p1 -
p2 -
Returns:

getConnectingLine

public static java.awt.Point[] getConnectingLine(java.awt.Rectangle r1,
                                                 java.awt.Rectangle r2)
Find the shortest connecting line between two rectangles. copied from org/metagraph/utility/graphics/GraphicsUtil.java

Returns:
An array of two coordinates describing the line

getConnectingLine

public static java.awt.Point[] getConnectingLine(java.awt.Point start,
                                                 java.awt.Rectangle r2)

uniqueLineSegmentRectangleIntersection

public static java.awt.Point uniqueLineSegmentRectangleIntersection(java.awt.Point p1,
                                                                    java.awt.Point p2,
                                                                    java.awt.Rectangle r)
Determine the unique intersection point of a line segment and a rectangle.

Parameters:
p1 - Coordinates of one end of a line
p2 - Coordinates of the other end of a line
r - Rectangle object copied from org/metagraph/utility/graphics/GraphicsUtil.java
Returns:
A Point representing the unique intersection, or null if no unique intersection exists.

lineSegmentIntersection

public static java.awt.Point lineSegmentIntersection(java.awt.Point line1P1,
                                                     java.awt.Point line1P2,
                                                     java.awt.Point line2P1,
                                                     java.awt.Point line2P2)
Determine the intersection point of two line segments, or return null if no intersection.

Parameters:
line1P1 - Coordinates of one end of line #1
line1P2 - Coordinates of the other end of line #1
line2P1 - Coordinates of one end of line #2
line2P2 - Coordinates of the other end of line #2 copied from org/metagraph/utility/graphics/GraphicsUtil.java
Returns:
Coordinates of the intersection, or null if none exists

interpolate

public static java.awt.Rectangle interpolate(java.awt.Rectangle start,
                                             java.awt.Rectangle target,
                                             double fraction,
                                             java.awt.Rectangle res)
Returns a rectangle that is an interpolation between start and target; if res is not null, the result will be put into it and returned; if res is null, a new Rectangle object will be allocated

Parameters:
start -
target -
fraction -
res -
Returns: