edu.mit.sketch.geom
Class GeometryUtil

java.lang.Object
  |
  +--edu.mit.sketch.geom.GeometryUtil

public class GeometryUtil
extends Object

Implements geometry related utility functions


Constructor Summary
GeometryUtil()
           
 
Method Summary
static void continualizeDirection(double[] direction)
          This is for making the Math.pi/2, -Math.pi/2 transitions continuous.
static double cosTheoremAngle(Point a, Point b, Point c)
          Return angle between |AB| and |BC|
static double degree2radian(double angle)
          degree2radian
static double distance(Point p1, Point p2)
          Return distnace |p1-p2|
static boolean equalDoubles(double a, double b, double tolerance)
          Return true if |a-b| < tolerance
static double[] getIntermediateAngles(Vertex[] input_vertices)
          Find the angles that the intermediate line segments make WRT the x axis using the input_vertices
static boolean linesParallel(Line a, Line b, double t)
          Return true if two lines are roughly parallel Tolerance is the tolerance in the difference of slopes.
static boolean parallelAngles(double angle_a, double angle_b, double t)
          Return true if two lines with angles a and b are roughly parallel within the tolerance t.
static double ptSegDist(Point p1, Point p2, Point p)
          A different version of ptSegDist
static double ptSegDistSq(double X1, double Y1, double X2, double Y2, double PX, double PY)
          From Sun's java.awt.geom.Line2D.java Returns the square of the distance from a point to a line segment.
static double ptSegDistSq(Point p1, Point p2, Point p)
          A different version of ptSegDistSq
static double radian2degree(double angle)
          radian2degree
static int relativeCCW(double X1, double Y1, double X2, double Y2, double PX, double PY)
          From Sun's java.awt.geom.Line2D.java Returns an indicator of where the specified point (PX, PY) lies with respect to the line segment from (X1, Y1) to (X2, Y2).
static int relativeCCW(Point x1, Point x2, Point p)
          A different version of relativeCCW
static double[] roundAngles(double[] angles, double dx)
          return a double array which is the same length as the input array, except the array entries are rounded up or down to be integral multiples of dx.
static double segmentLength(Point[] points, int begin_index, int end_index)
          Return the segment length from index begin_index to end_index in points (end_index included).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeometryUtil

public GeometryUtil()
Method Detail

roundAngles

public static double[] roundAngles(double[] angles,
                                   double dx)
return a double array which is the same length as the input array, except the array entries are rounded up or down to be integral multiples of dx.

equalDoubles

public static boolean equalDoubles(double a,
                                   double b,
                                   double tolerance)
Return true if |a-b| < tolerance

linesParallel

public static boolean linesParallel(Line a,
                                    Line b,
                                    double t)
Return true if two lines are roughly parallel Tolerance is the tolerance in the difference of slopes.

parallelAngles

public static boolean parallelAngles(double angle_a,
                                     double angle_b,
                                     double t)
Return true if two lines with angles a and b are roughly parallel within the tolerance t.

radian2degree

public static double radian2degree(double angle)
radian2degree

degree2radian

public static double degree2radian(double angle)
degree2radian

distance

public static double distance(Point p1,
                              Point p2)
Return distnace |p1-p2|

cosTheoremAngle

public static double cosTheoremAngle(Point a,
                                     Point b,
                                     Point c)
Return angle between |AB| and |BC|

ptSegDist

public static double ptSegDist(Point p1,
                               Point p2,
                               Point p)
A different version of ptSegDist

ptSegDistSq

public static double ptSegDistSq(Point p1,
                                 Point p2,
                                 Point p)
A different version of ptSegDistSq

ptSegDistSq

public static double ptSegDistSq(double X1,
                                 double Y1,
                                 double X2,
                                 double Y2,
                                 double PX,
                                 double PY)
From Sun's java.awt.geom.Line2D.java Returns the square of the distance from a point to a line segment.
Parameters:
X1, Y1 - the coordinates of the beginning of the specified line segment
X2, Y2 - the coordinates of the end of the specified line segment
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the square of the distance from the specified point to the specified line segment.

relativeCCW

public static int relativeCCW(Point x1,
                              Point x2,
                              Point p)
A different version of relativeCCW

relativeCCW

public static int relativeCCW(double X1,
                              double Y1,
                              double X2,
                              double Y2,
                              double PX,
                              double PY)
From Sun's java.awt.geom.Line2D.java Returns an indicator of where the specified point (PX, PY) lies with respect to the line segment from (X1, Y1) to (X2, Y2). The value is 1 if the line segment must turn counterclockwise to point at the specified point, -1 if it must turn clockwise, or 0 if the point lies exactly on the line segment. If the point is colinear with the line segment, but not between the endpoints, then the value will be -1 if the point lies "beyond (X1, Y1)" or 1 if the point lies "beyond (X2, Y2)". Note that an indicator value of 0 is rare and not useful for determining colinearity because of floating point rounding issues.
Parameters:
X1, Y1 - the coordinates of the beginning of the specified line segment
X2, Y2 - the coordinates of the end of the specified line segment
PX, PY - the coordinates of the specified point to be compared with the specified line segment
Returns:
an integer that indicates the position of the third specified coordinates with respect to the line segment formed by the first two specified coordinates.

getIntermediateAngles

public static double[] getIntermediateAngles(Vertex[] input_vertices)
Find the angles that the intermediate line segments make WRT the x axis using the input_vertices

continualizeDirection

public static void continualizeDirection(double[] direction)
This is for making the Math.pi/2, -Math.pi/2 transitions continuous.

segmentLength

public static double segmentLength(Point[] points,
                                   int begin_index,
                                   int end_index)
Return the segment length from index begin_index to end_index in points (end_index included). begin_index should be less than or equal to end_index.