CH.ifa.draw.util
Class Geom

java.lang.Object
  extended by CH.ifa.draw.util.Geom

public class Geom
extends java.lang.Object

Some geometric utilities.


Field Summary
static int EAST
           
static int NORTH
           
static int SOUTH
           
static int WEST
           
 
Method Summary
static java.awt.Point angleToPoint(java.awt.Rectangle r, double angle)
          Gets the point on a rectangle that corresponds to the given angle.
static java.awt.Point center(java.awt.Rectangle r)
           
static int direction(int x1, int y1, int x2, int y2)
          Returns the direction NORTH, SOUTH, WEST, EAST from one point to another one.
static java.awt.Point east(java.awt.Rectangle r)
           
static java.awt.Point intersect(int xa, int ya, int xb, int yb, int xc, int yc, int xd, int yd)
          Standard line intersection algorithm Return the point of intersection if it exists, else null
static long length(int x1, int y1, int x2, int y2)
          Gets the distance between to points
static long length2(int x1, int y1, int x2, int y2)
          Gets the square distance between two points.
static boolean lineContainsPoint(int x1, int y1, int x2, int y2, int px, int py)
          Tests if a point is on a line.
static java.awt.Point north(java.awt.Rectangle r)
           
static java.awt.Point ovalAngleToPoint(java.awt.Rectangle r, double angle)
          Gets the point on an oval that corresponds to the given angle.
static double pointToAngle(java.awt.Rectangle r, java.awt.Point p)
          Gets the angle of a point relative to a rectangle.
static java.awt.Point polarToPoint(double angle, double fx, double fy)
          Converts a polar to a point
static int range(int min, int max, int value)
          Constains a value to the given range.
static java.awt.Point south(java.awt.Rectangle r)
           
static java.awt.Point west(java.awt.Rectangle r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTH

public static final int NORTH
See Also:
Constant Field Values

SOUTH

public static final int SOUTH
See Also:
Constant Field Values

WEST

public static final int WEST
See Also:
Constant Field Values

EAST

public static final int EAST
See Also:
Constant Field Values
Method Detail

lineContainsPoint

public static boolean lineContainsPoint(int x1,
                                        int y1,
                                        int x2,
                                        int y2,
                                        int px,
                                        int py)
Tests if a point is on a line.


direction

public static int direction(int x1,
                            int y1,
                            int x2,
                            int y2)
Returns the direction NORTH, SOUTH, WEST, EAST from one point to another one.


south

public static java.awt.Point south(java.awt.Rectangle r)

center

public static java.awt.Point center(java.awt.Rectangle r)

west

public static java.awt.Point west(java.awt.Rectangle r)

east

public static java.awt.Point east(java.awt.Rectangle r)

north

public static java.awt.Point north(java.awt.Rectangle r)

range

public static int range(int min,
                        int max,
                        int value)
Constains a value to the given range.

Returns:
the constrained value

length2

public static long length2(int x1,
                           int y1,
                           int x2,
                           int y2)
Gets the square distance between two points.


length

public static long length(int x1,
                          int y1,
                          int x2,
                          int y2)
Gets the distance between to points


pointToAngle

public static double pointToAngle(java.awt.Rectangle r,
                                  java.awt.Point p)
Gets the angle of a point relative to a rectangle.


angleToPoint

public static java.awt.Point angleToPoint(java.awt.Rectangle r,
                                          double angle)
Gets the point on a rectangle that corresponds to the given angle.


polarToPoint

public static java.awt.Point polarToPoint(double angle,
                                          double fx,
                                          double fy)
Converts a polar to a point


ovalAngleToPoint

public static java.awt.Point ovalAngleToPoint(java.awt.Rectangle r,
                                              double angle)
Gets the point on an oval that corresponds to the given angle.


intersect

public static java.awt.Point intersect(int xa,
                                       int ya,
                                       int xb,
                                       int yb,
                                       int xc,
                                       int yc,
                                       int xd,
                                       int yd)
Standard line intersection algorithm Return the point of intersection if it exists, else null