jumbo.euclid
Class Real2

java.lang.Object
  |
  +--jumbo.euclid.Status
        |
        +--jumbo.euclid.Real2
Direct Known Subclasses:
Complex, Coordinate2, Vector2

public class Real2
extends Status

Real2 - a pair of FPt numbers - no other assumptions

Contains two doubles. Can be used as-is, but there are some specialised derived classes (e.g. Complex (a complex number), Point2 (x,y coords), etc),

The default value is 0.0, 0.0.


Field Summary
 double x
          the first floating point value
 double y
          the second floating point value
 
Constructor Summary
Real2()
           
Real2(double x, double y)
           
Real2(Real2 r)
          copy constructor
 
Method Summary
static Real2[] addPolygonOnLine(Real2 point1, Real2 point2, int nPoints, int end, Real2 repelPoint)
          creates a polygon (returns points[]) from two points.
 void clear()
          set to 0, 0
 double dotProduct(Real2 r)
          get dot product
 double elementAt(int elem)
          get either value; counts from ZERO
 boolean equals(Real2 r)
           
 double getAngle()
          get angle between origin and this point (i.e polar coords) - uses atan2 (i.e.
static Angle getAngle(Real2 p1, Real2 p2, Real2 p3)
          get angle between 3 Real2s (the second is in the centre).
 double getLength()
          get length of Real2 if centered on origin
 Real2 getMidPoint(Real2 p)
          point midway between 'this' and 'p'
 Real2 getUnitVector()
          get unit vector
 double getX()
          get X value
 double getY()
          get Y value
 Real2 makePoint(double rad, double theta)
          make a new point at (dist, theta) from this
 Real2 multiplyBy(double f)
          multiply a point by a scalar
 void negative()
          multiply both components by -1; MODIFIES 'this'
 Real2 plus(Real2 r2)
          add two points - vector sum;
 void setX(double xx)
           
 void setY(double yy)
           
 void sortAscending()
          sorts x and y so that x <= y
 void sortDescending()
          sorts x and y so that x >= y
 Real2 subtract(Real2 r2)
          subtract two points - vector difference;
 void swap()
          swaps the x and y values
 java.lang.String toString()
           
 void transformBy(Transform2 t)
          transforms the point by a rot-trans matrix; MODIFIES 'this'
 
Methods inherited from class jumbo.euclid.Status
NYI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x
the first floating point value

y

public double y
the second floating point value
Constructor Detail

Real2

public Real2()

Real2

public Real2(double x,
             double y)

Real2

public Real2(Real2 r)
copy constructor
Method Detail

swap

public void swap()
swaps the x and y values

sortAscending

public void sortAscending()
sorts x and y so that x <= y

sortDescending

public void sortDescending()
sorts x and y so that x >= y

clear

public void clear()
set to 0, 0

setX

public void setX(double xx)

setY

public void setY(double yy)

equals

public boolean equals(Real2 r)

plus

public Real2 plus(Real2 r2)
add two points - vector sum;

subtract

public Real2 subtract(Real2 r2)
subtract two points - vector difference;

negative

public void negative()
multiply both components by -1; MODIFIES 'this'

multiplyBy

public Real2 multiplyBy(double f)
multiply a point by a scalar

getX

public double getX()
get X value

getY

public double getY()
get Y value

elementAt

public double elementAt(int elem)
                 throws java.lang.ArrayIndexOutOfBoundsException
get either value; counts from ZERO

getLength

public double getLength()
get length of Real2 if centered on origin

getMidPoint

public Real2 getMidPoint(Real2 p)
point midway between 'this' and 'p'

getUnitVector

public Real2 getUnitVector()
                    throws ZeroVectorException
get unit vector
Throws:
ZeroVectorException - this was of zero length

dotProduct

public double dotProduct(Real2 r)
get dot product

getAngle

public static Angle getAngle(Real2 p1,
                             Real2 p2,
                             Real2 p3)
get angle between 3 Real2s (the second is in the centre). angle is CLOCKWISE from p1 to p3

transformBy

public void transformBy(Transform2 t)
transforms the point by a rot-trans matrix; MODIFIES 'this'

addPolygonOnLine

public static Real2[] addPolygonOnLine(Real2 point1,
                                       Real2 point2,
                                       int nPoints,
                                       int end,
                                       Real2 repelPoint)
creates a polygon (returns points[]) from two points. Serial numbers of points are 0 and end (i.e. point1 is points[0] and point2 is points[end]. if end == 0, end=>1

getAngle

public double getAngle()
get angle between origin and this point (i.e polar coords) - uses atan2 (i.e. anticlockwise from X axis); if x == y == 0.0 presumably returns NaN

makePoint

public Real2 makePoint(double rad,
                       double theta)
make a new point at (dist, theta) from this
Parameters:
double - rad the distance to new point
double - angle the angle to new point (anticlockwise from X axis), i.e. theta=0 gives (rad, 0), theta=PI/2 gives (0, rad)
Returns:
Real2 new point

toString

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