gishur.x2.core
Class XPoint

java.lang.Object
  |
  +--gishur.x2.core.XObject
        |
        +--gishur.x2.core.XPoint
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, java12.lang.Comparable, java.io.Serializable

public class XPoint
extends XObject
implements java12.lang.Comparable

A point in double precision.

Version:
1.0
Author:
Thomas Wolf
See Also:
Serialized Form

Field Summary
static double IDENTICAL
          Minimum distance between two point, under which the point are treated as equal.
static int LIES_BEFORE
          Test point lies before the other points
static int LIES_BEHIND
          Test point lies behind the other points
static int LIES_BETWEEN
          Test point lies between the points
static int ORIENTATION_COLLINEAR
          Points are collinear.
static int ORIENTATION_LEFT
          Points are counterclockwise.
static int ORIENTATION_RIGHT
          Points are clockwise.
static int ORIENTATION_UNDEFINED
          Undefined orientation.
static XPoint ORIGIN
          The origin (0,0) point.
 
Fields inherited from class gishur.x2.core.XObject
RESERVED_STATE_MAX_MASK, STATE_DIRTY, STATE_LOCKED, STATE_MUTABLE
 
Constructor Summary
XPoint(double x, double y)
          Creates a new point (x,y).
 
Method Summary
 XPoint add(XPoint v)
          Adds this vector to v.
 double angle()
          Return the angle with the origin and the X-axe.
static double angle(double x, double y)
          Return the angle between the segment (0,0)-(x,y) and the x-axe.
static double angle(double x, double y, double x1, double y1, double x2, double y2)
          Returns the angle (x1,y1)-(x,y)-(x2,y2) (in Radiant).
 double angle(XPoint q)
          Returns the angle between the line through this and q with the abscissa (x-axis).
 double angle(XPoint q, XPoint r)
          Returns the angle q-this-r (in Radiant).
 int compareTo(java.lang.Object o)
          Compares this Object with the specified Object for order.
 int compareTo(XPoint p)
          Compares this point with the specified point for order.
static XPoint create(double x, double y)
           
static XPoint createMiddle(XPoint a, XPoint b)
          Creates a point in the middle between this point and p.
static XPoint createPolar(double angle, double length)
           
static double distance(double x1, double y1, double x2, double y2)
          Computes the euclidean distance between two given points.
 double distance(XPoint p)
          Computes the the euclidean distance between this point and the given point p.
static double distance(XPoint a, XPoint b)
          Computes the euclidean distance between two given points.
static double distanceSq(double x1, double y1, double x2, double y2)
          Computes the square of the euclidean distance between two given points.
 double distanceSq(XPoint p)
          Computes the square of the euclidean distance between this point and the given point p.
static double distanceSq(XPoint a, XPoint b)
          Computes the square of the euclidean distance between two given points.
 boolean equals(double x, double y)
          Determines whether two points are equal.
 boolean equals(java.lang.Object o)
          Determines whether two objects (this and o) are equal.
 boolean equals(XPoint p)
          Determines whether two points are equal.
 java.lang.Object getOldXObject()
          Returns corresponding old gishur.x-object.
protected  XObject[] getXObjectMembers()
          This method should return all XObject members that contain geometric information.
static boolean inSector(double x, double y, double x0, double y0, double x1, double y1, double x2, double y2)
          Checks if the point (x,y) lies in the (convex) sector (x1,y1)-(x0,y0)-(x2,y2) (with apex (x0,y0)).
static boolean inSector(XPoint x, XPoint p, XPoint a, XPoint b)
          Checks if the point x lies in the (convex) sector a-p-b (with apex p).
static boolean inTria(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3)
          Checks if the point (x,y) lies in the triangle (x1,y1)-(x2,y2)-(x3,y3).
static boolean inTria(XPoint x, XPoint a, XPoint b, XPoint c)
          Checks if the point x lies in the triangle a-b-c.
 void makeImmutable()
          Makes this object immutable.
 void makeMutable()
          Makes this object mutable.
static XPoint max(XPoint a, XPoint b)
          Returns the bigger point according to the natural order defined by compareTo.
static XPoint min(XPoint a, XPoint b)
          Returns the smaller point according to the natural order defined by compareTo.
 XPoint multiply(double m)
          Multiplies this vector with m.
 double multiply(XPoint v)
          Calculates the scalar product between this and v.
 double norm()
          Return the euclidian norm of this point.
 XPoint normalize()
          Returns a normalized point, that means: the new point has norm 1 and points to the same direction than this point.
 XPoint normalizeTo(double length)
          Returns a vector (point) which points to the same direction as this but has norm length.
static int opposite(int orientation)
          Returns the 'opposite' (collinear) orientation constant to the given constant.
static int orientation(double x1, double y1, double x2, double y2, double x, double y)
          Return an indicator of where the point (x,y) lies with respect to the directed line (x1,y1)->(x2,y2).
 int orientation(XPoint a, XPoint b)
          Return an indicator of where this point lies with respect to the directed line a->b.
static int orientation(XPoint a, XPoint b, XPoint c)
          Return an indicator of where the point c lies with respect to the directed line a->b.
static int orientationColinear(double x1, double y1, double x2, double y2, double xp, double yp)
          Return an indicator of where the specified point (xp,yp) lies with respect to the directed line segment (x1,y1)->(x2,y2).
static int orientationColinear(XPoint a, XPoint b, XPoint c)
          Return an indicator of where the specified point c lies with respect to the directed line segment a->b.
 void set(double x, double y)
          Changes the position of the point to (x,y).
static double signedArea(double x1, double y1, double x2, double y2, double x3, double y3)
          Returns the signed area of the triangle (x1,y1)-(x2,y2)-(x3,y3).
static double signedArea(XPoint a, XPoint b, XPoint c)
          Returns the signed area of the triangle a-b-c.
 XPoint subtract(XPoint v)
          Substracts v from this vector.
 java.lang.String toString_complete()
          Returns a more detailed string representation of the object than toString().
 java.lang.String toString()
          Returns a string representation of the object.
 XObject transform(double m00, double m01, double m02, double m10, double m11, double m12)
          Transforms this XObject by the given affine transformation matrix.
 double x()
          Return the X-coordinate value.
 double y()
          Return the Y-coordinate value.
 
Methods inherited from class gishur.x2.core.XObject
checkState, checkStateCleared, clearDirty, clearState, clone, copy, dirty, getMutable, inverseTransform, lock, locked, modify, mutable, restoreMutability, rotate, scale, setState, state, state, toString_state, transform, translate, translate, unlock
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ORIENTATION_LEFT

public static final int ORIENTATION_LEFT
Points are counterclockwise.

ORIENTATION_COLLINEAR

public static final int ORIENTATION_COLLINEAR
Points are collinear.

ORIENTATION_RIGHT

public static final int ORIENTATION_RIGHT
Points are clockwise.

ORIENTATION_UNDEFINED

public static final int ORIENTATION_UNDEFINED
Undefined orientation.

LIES_BEFORE

public static final int LIES_BEFORE
Test point lies before the other points

LIES_BETWEEN

public static final int LIES_BETWEEN
Test point lies between the points

LIES_BEHIND

public static final int LIES_BEHIND
Test point lies behind the other points

IDENTICAL

public static final double IDENTICAL
Minimum distance between two point, under which the point are treated as equal.

ORIGIN

public static final XPoint ORIGIN
The origin (0,0) point.
Constructor Detail

XPoint

public XPoint(double x,
              double y)
Creates a new point (x,y).
Parameters:
x - X-Coordinate
y - Y-Coordinate
Method Detail

create

public static XPoint create(double x,
                            double y)

createPolar

public static XPoint createPolar(double angle,
                                 double length)

createMiddle

public static XPoint createMiddle(XPoint a,
                                  XPoint b)
Creates a point in the middle between this point and p.
Returns:
middle point between this and p

toString

public java.lang.String toString()
Returns a string representation of the object.
Overrides:
toString in class XObject
Returns:
a string representation of the object.

toString_complete

public java.lang.String toString_complete()
Returns a more detailed string representation of the object than toString().
Overrides:
toString_complete in class XObject
Returns:
a string representation of the object.

makeMutable

public void makeMutable()
Makes this object mutable. This means this Object can modify its coordinates (and some other geometric information). This must be assured by every subclass of XObject itself - but propagation to all XObject members contained by this class (returned by getXObjectMembers()) is assured by this method.
Overrides:
makeMutable in class XObject

makeImmutable

public void makeImmutable()
Makes this object immutable. This means this Object cannot modify its coordinates (and some other geometric information). This must be assured by every subclass of XObject itself - but propagation to all XObject members contained by this class (returned by getXObjectMembers()) is assured by this method.
Overrides:
makeImmutable in class XObject

getXObjectMembers

protected XObject[] getXObjectMembers()
This method should return all XObject members that contain geometric information. The result will be used by makeMutable(), makeImmutable(), XObject.clearDirty(), XObject.lock() and XObject.unlock(). To make this work there must not occur circular dependencies.
Overrides:
getXObjectMembers in class XObject
Returns:
Array with all XObject members (or null if none).

x

public double x()
Return the X-coordinate value.
Returns:
X-Coordinate.

y

public double y()
Return the Y-coordinate value.
Returns:
Y-Coordinate.

angle

public double angle()
Return the angle with the origin and the X-axe.
Returns:
Angle.

equals

public boolean equals(double x,
                      double y)
Determines whether two points are equal.
Parameters:
(x,y) - Point to compare with this.
Returns:
True, if the two points are equal.

equals

public boolean equals(XPoint p)
Determines whether two points are equal.
Parameters:
p - Point to compare with this.
Returns:
True, if the two points are equal.

equals

public boolean equals(java.lang.Object o)
Determines whether two objects (this and o) are equal.
Overrides:
equals in class java.lang.Object
Parameters:
o - Object to compare with.
Returns:
True, if the two objects are equal.

compareTo

public int compareTo(XPoint p)
Compares this point with the specified point for order. Returns a negative integer, zero, or a positive integer as this point is less than, equal to, or greater than the given point. If p is null then a positive integer will be returned.

Point a is less than point b if it has a smaller x-coordinate or - if both x-coordinates are equal - if it has a smaller y-coordinate than b.

Parameters:
p - the XPoint to be compared.
Returns:
a negative integer, zero, or a positive integer as this point is less than, equal to, or greater than the given point.

compareTo

public int compareTo(java.lang.Object o)
Compares this Object with the specified Object for order. Returns a negative integer, zero, or a positive integer as this Object is less than, equal to, or greater than the given Object.

The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.

The implementer must also ensure that x.equals(y) implies that x.compareTo(y)==0. Note that the converse is not necessarily true (e.g., BigDecimal).

Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.

Specified by:
compareTo in interface java12.lang.Comparable
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this Object is less than, equal to, or greater than the given Object.
Throws:
ClassCastException - the specified Object's type prevents it from being compared to this Object.

min

public static final XPoint min(XPoint a,
                               XPoint b)
Returns the smaller point according to the natural order defined by compareTo. If the two points are equal, a will be returned. If one of the points is null the other will be returned, if both are null, null will be returned.
Parameters:
a - first point
b - second point
Returns:
Minimum of the two points.

max

public static final XPoint max(XPoint a,
                               XPoint b)
Returns the bigger point according to the natural order defined by compareTo. If the two points are equal, a will be returned. If the two points are equal, a will be returned. If one of the points is null the other will be returned, if both are null, null will be returned.
Parameters:
a - first point
b - second point
Returns:
Maximum of the two points.

norm

public double norm()
Return the euclidian norm of this point.
Returns:
The euclidian norm.

distanceSq

public static final double distanceSq(double x1,
                                      double y1,
                                      double x2,
                                      double y2)
Computes the square of the euclidean distance between two given points.
Parameters:
x1,y1 - the first point (x1,y1)
x2,y2 - the second point (x2,y2)
Returns:
The square distance between (x1,y1) and (x2,y2).

distance

public static final double distance(double x1,
                                    double y1,
                                    double x2,
                                    double y2)
Computes the euclidean distance between two given points.
Parameters:
x1,y1 - the first point (x1,y1)
x2,y2 - the second point (x2,y2)
Returns:
The distance between (x1,y1) and (x2,y2).

distanceSq

public static final double distanceSq(XPoint a,
                                      XPoint b)
Computes the square of the euclidean distance between two given points.
Parameters:
a - the first point
b - the second point
Returns:
The square distance between a and b.

distance

public static final double distance(XPoint a,
                                    XPoint b)
Computes the euclidean distance between two given points.
Parameters:
a - the first point
b - the second point
Returns:
The distance between a and b.

distanceSq

public double distanceSq(XPoint p)
Computes the square of the euclidean distance between this point and the given point p.
Parameters:
p - the other point
Returns:
The square distance between this and p.

distance

public double distance(XPoint p)
Computes the the euclidean distance between this point and the given point p.
Parameters:
p - the other point
Returns:
The euclidean distance between this and p.

angle

public static double angle(double x,
                           double y)
Return the angle between the segment (0,0)-(x,y) and the x-axe.
Parameters:
x,y - coordinates of the point
Returns:
Angle (+inf,0)-(0,0)-(x,y).

angle

public static final double angle(double x,
                                 double y,
                                 double x1,
                                 double y1,
                                 double x2,
                                 double y2)
Returns the angle (x1,y1)-(x,y)-(x2,y2) (in Radiant). The angle will be positive and measured counterclockwise.
Parameters:
(x1,y1),(x2,y2) - endpoints of the anglesides
Returns:
Angle (x1,y1)-(x,y)-(x2,y2).

angle

public double angle(XPoint q,
                    XPoint r)
Returns the angle q-this-r (in Radiant). The angle will be positive and measured counterclockwise.
Parameters:
q,r - endpoints of the anglesides
Returns:
Angle q-this-r.

angle

public double angle(XPoint q)
Returns the angle between the line through this and q with the abscissa (x-axis). The angle will be positive and measured counterclockwise.
Parameters:
q - othe point defining one angleside
Returns:
angle

orientation

public static final int orientation(double x1,
                                    double y1,
                                    double x2,
                                    double y2,
                                    double x,
                                    double y)
Return an indicator of where the point (x,y) lies with respect to the directed line (x1,y1)->(x2,y2). The value will be ORIENTATION_LEFT if (x,y) lies left of, ORIENTATION_RIGHT if it lies right of (x1,y1)->(x2,y2), or ORIENTATION_COLLINEAR if (x1,y1),(x2,y2),(x,y) are collinear. ORIENTATION_UNDEFINED will be returned only if the points (x1,y1) and (x2,y2) are equal and (x,y) not.
Parameters:
(x1,y1),(x2,y2),(x,y) - the three points
Returns:
The orientation of the three points (one constant of {ORIENTATION_LEFT, ORIENTATION_RIGHT, ORIENTATION_COLLINEAR, ORIENTATION_UNDEFINED}).

orientation

public static final int orientation(XPoint a,
                                    XPoint b,
                                    XPoint c)
                             throws GeomException
Return an indicator of where the point c lies with respect to the directed line a->b. The value will be ORIENTATION_LEFT if c lies left of, ORIENTATION_RIGHT if it lies right of a->b, or ORIENTATION_COLLINEAR if a,b,c are collinear. If any given point is null then a GeomException is thrown.
Parameters:
a,b,c - the three points
Returns:
The orientation of the three points (one constant of {ORIENTATION_LEFT,ORIENTATION_RIGHT, ORIENTATION_COLLINEAR}).
Throws:
GeomException - if any argument is null

orientationColinear

public static final int orientationColinear(double x1,
                                            double y1,
                                            double x2,
                                            double y2,
                                            double xp,
                                            double yp)
Return an indicator of where the specified point (xp,yp) lies with respect to the directed line segment (x1,y1)->(x2,y2). If the three points are collinear, the result value will be LIES_BEFORE if (xp,yp) lies before (x1,y1)->(x2,y2), LIES_BEHIND if it lies behind (x1,y1)->(x2,y2) or LIES_BETWEEN if it lies in the segment (x1,y1)-(x2,y2). If the points are not collinear the result is worthless.
Parameters:
(x1,y1),(x2,y2),(xp,yp) - the three points
Returns:
The collinear orientation of the three points (one constant of {LIES_BEFORE,LIES_BEHIND, LIES_BETWEEN}).

orientationColinear

public static final int orientationColinear(XPoint a,
                                            XPoint b,
                                            XPoint c)
Return an indicator of where the specified point c lies with respect to the directed line segment a->b. If the three points are collinear, the result value will be LIES_BEFORE if c lies before a->b, LIES_BEHIND if it lies behind a->b or LIES_BETWEEN if it lies in the segment a-b. If the points are not collinear the result is worthless.
Parameters:
a,b,c - the three points
Returns:
The collinear orientation of the three points (one constant of {LIES_BEFORE,LIES_BEHIND, LIES_BETWEEN}).
Throws:
GeomException - if any argument is null

orientation

public int orientation(XPoint a,
                       XPoint b)
                throws GeomException
Return an indicator of where this point lies with respect to the directed line a->b.
Parameters:
a,b - the other two points
Returns:
The orientation of the three points (one constant of {ORIENTATION_LEFT,ORIENTATION_RIGHT, ORIENTATION_COLLINEAR}).
Throws:
GeomException - if any argument is null

opposite

public static final int opposite(int orientation)
Returns the 'opposite' (collinear) orientation constant to the given constant.
Parameters:
orientation - given orientation constant
Returns:
Opposite orientation.

inSector

public static final boolean inSector(double x,
                                     double y,
                                     double x0,
                                     double y0,
                                     double x1,
                                     double y1,
                                     double x2,
                                     double y2)
Checks if the point (x,y) lies in the (convex) sector (x1,y1)-(x0,y0)-(x2,y2) (with apex (x0,y0)).
Parameters:
x,y - test point
x0,y0 - apex
x1,y1 - first vertex
x2,y2 - second vertex
Returns:
True, if the point lies in the sector.

inSector

public static final boolean inSector(XPoint x,
                                     XPoint p,
                                     XPoint a,
                                     XPoint b)
Checks if the point x lies in the (convex) sector a-p-b (with apex p).
Parameters:
x - test point
p - apex
a - first vertex
b - second vertex
Returns:
True, if the point lies in the sector.
Throws:
GeomException - if any argument is null

inTria

public static final boolean inTria(double x,
                                   double y,
                                   double x1,
                                   double y1,
                                   double x2,
                                   double y2,
                                   double x3,
                                   double y3)
Checks if the point (x,y) lies in the triangle (x1,y1)-(x2,y2)-(x3,y3).
Parameters:
x,y - test point
x1,y1 - first vertex
x2,y2 - second vertex
x3,y3 - third vertex
Returns:
True, if the point lies in the triangle.

inTria

public static final boolean inTria(XPoint x,
                                   XPoint a,
                                   XPoint b,
                                   XPoint c)
Checks if the point x lies in the triangle a-b-c.
Parameters:
x - test point
a - first vertex
b - second vertex
c - third vertex
Returns:
True, if the point lies in the triangle.
Throws:
GeomException - if any argument is null

signedArea

public static final double signedArea(double x1,
                                      double y1,
                                      double x2,
                                      double y2,
                                      double x3,
                                      double y3)
Returns the signed area of the triangle (x1,y1)-(x2,y2)-(x3,y3). The value is positive if the points are arranged counterclockwise.
Parameters:
x1,y1 - first vertex
x2,y2 - second vertex
x3,y3 - third vertex
Returns:
Signed area of the triangle.

signedArea

public static final double signedArea(XPoint a,
                                      XPoint b,
                                      XPoint c)
Returns the signed area of the triangle a-b-c. The value is positive if the points are arranged counterclockwise.
Parameters:
a - first vertex
b - second vertex
c - third vertex
Returns:
Signed area of the triangle.
Throws:
GeomException - if any argument is null

normalize

public XPoint normalize()
Returns a normalized point, that means: the new point has norm 1 and points to the same direction than this point.
Returns:
normalized point

normalizeTo

public XPoint normalizeTo(double length)
Returns a vector (point) which points to the same direction as this but has norm length.
Parameters:
length - vector length to normalize to
Returns:
normalized point

add

public XPoint add(XPoint v)
Adds this vector to v.
Parameters:
v - second vector
Returns:
Sum of this and v.

subtract

public XPoint subtract(XPoint v)
Substracts v from this vector.
Parameters:
v - second vector
Returns:
Difference of this and v.

multiply

public XPoint multiply(double m)
Multiplies this vector with m.
Parameters:
m - multipier
Returns:
Streched vector.

multiply

public double multiply(XPoint v)
Calculates the scalar product between this and v.
Parameters:
v - other vector
Returns:
Scalar product.

set

public void set(double x,
                double y)
Changes the position of the point to (x,y). If the object is immutable, a GeomException will be thrown.
Throws:
GeomException - if point is immutable

transform

public XObject transform(double m00,
                         double m01,
                         double m02,
                         double m10,
                         double m11,
                         double m12)
Transforms this XObject by the given affine transformation matrix.
Overrides:
transform in class XObject
Parameters:
m00,m01,m02 - first row of the transformation matrix
m10,m11,m12 - second row of the transformation matrix
Returns:
transformed XObject (this, only if it is mutable)

getOldXObject

public java.lang.Object getOldXObject()
Returns corresponding old gishur.x-object.
Overrides:
getOldXObject in class XObject
Returns:
Corresponding old gishur.x-object.