jumbo.euclid
Class Real2Vector

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--jumbo.euclid.EuclidVector
                          |
                          +--jumbo.euclid.Real2Vector

public class Real2Vector
extends EuclidVector

Real2Vector - a (Java) Vector of Real2s. (Note that 'Vector' is used by Java to describe an array of objects - there is no relationship to geometrical vectors in this package.)

Support is also given for the two component arrays as RealArrays

Default is an empty (Java) Vector;

See Also:
Serialized Form

Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Real2Vector()
           
Real2Vector(double[] flarray)
          Formed by feeding in an existing array to a 2xn matrix.
Real2Vector(int size)
          create a Vector with given number of points
Real2Vector(int n, double[] x, double[] y)
          from two parallel arrays of x, y - by REFERENCE
Real2Vector(Real2Vector pv)
          copy constructor from Real2Vector COPIES pv
Real2Vector(RealArray m)
          constructor from RealArray - by REFERENCE
 
Method Summary
 void addElement(Real2 p)
           
 Angle angle(int i1, int i2, int i3)
          get angle between 3 points
 Angle angle(IntSet is)
          get angle between 3 points
 double distance(int i1, int i2)
          get distance between 2 points
 double distance(IntSet is)
          get distance between 2 points
 Real2 getCentroid()
          get centroid of all points
 int getClosestPoint(Real2 p)
          get the closest point (both ranges are assumed to have the same scales
 double getCoordinate(int i, Choice2 j)
          get a single coordinate value
 int getPoint(Real2 p, double width, double height)
          get the index of the first point within a box centered on p (i.e.
 RealRange getRange(Choice2 ax)
          get range of one coordinate
 Real2Range getRange2()
          get range of both coordinates
 Real2 getReal2(int i)
          get the i'th Real2
 RealArray getXorY(Choice2 axis)
          get a single coordinate array - e.g.
 RealArray getXY()
          get the coordinate coordinate array as doubles x,y,x,y, ...
 java.lang.String makeString()
          we are not allowed a toString() here, as Vector is a final class
 void multiplyBy(double f)
          multiply all coordinates be a given scalar (i.e.
 void plus(Real2 p)
          add a Real2 to all elements of 'this'; MODIFIES 'this'
static Real2Vector regularPolygon(int nsides, double rad)
          make a regular polygon, zero point at (0, rad); points go clockwise
 void rotateAboutCentroid(Angle a)
          rotate about centroid by given angle; MODIFIES 'this'
 void setElementAt(Real2 v, int i)
           
 Real2Vector sortAscending(Choice2 ax)
          sort ARRAY on X or Y coordinate; returns new array
 Real2Vector sortDescending(Choice2 ax)
          sort ARRAY on X or Y coordinate; returns new array
 void sortXYAscending()
          sort X and Y within each point; MODIFIES array
 void sortXYDescending()
          sort X and Y within each point; MODIFIES array
 Real2Vector subArray(IntSet is)
          create a NEW subset of the points; points are COPIED
 IntSet subSet(Real2Range r)
          create a subset of the points within a box
 void subtract(Real2 v)
          translate negatively; MODIFIES 'this'
 void swapXY()
          swap all X and Y coordinates; MODIFIES array
 void transformBy(Transform2 t)
          transforms 'this' by rotation-translation matrix; MODIFIES 'this'
 void translateBy(Real2 v)
          translate by a vector, synonym for 'plus'; MODIFIES 'this'
 
Methods inherited from class jumbo.euclid.EuclidVector
concatenate
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Real2Vector

public Real2Vector()

Real2Vector

public Real2Vector(int size)
create a Vector with given number of points

Real2Vector

public Real2Vector(double[] flarray)
            throws BadArgumentException
Formed by feeding in an existing array to a 2xn matrix. THE COLUMN IS THE FASTEST MOVING INDEX, i.e. the matrix is filled as flarray(0,0, flarray(0,1). Primarily for compatibility with other apps
Throws:
BadArgumentException - array must have even number of elements

Real2Vector

public Real2Vector(int n,
                   double[] x,
                   double[] y)
from two parallel arrays of x, y - by REFERENCE

Real2Vector

public Real2Vector(RealArray m)
            throws BadArgumentException
constructor from RealArray - by REFERENCE
Throws:
BadArgumentException - array must have even number of elements

Real2Vector

public Real2Vector(Real2Vector pv)
copy constructor from Real2Vector COPIES pv
Method Detail

addElement

public void addElement(Real2 p)

setElementAt

public void setElementAt(Real2 v,
                         int i)
                  throws java.lang.ArrayIndexOutOfBoundsException
Throws:
java.lang.ArrayIndexOutOfBoundsException - v does not have an i'th element

getRange

public RealRange getRange(Choice2 ax)
get range of one coordinate

getRange2

public Real2Range getRange2()
get range of both coordinates

subArray

public Real2Vector subArray(IntSet is)
                     throws BadSubscriptException
create a NEW subset of the points; points are COPIED
Throws:
BadSubscriptException - an element of is is out of range of this

subSet

public IntSet subSet(Real2Range r)
create a subset of the points within a box

getClosestPoint

public int getClosestPoint(Real2 p)
get the closest point (both ranges are assumed to have the same scales

getPoint

public int getPoint(Real2 p,
                    double width,
                    double height)
get the index of the first point within a box centered on p (i.e. p+- width/2, height/2) or -1 if none

getCentroid

public Real2 getCentroid()
get centroid of all points

translateBy

public void translateBy(Real2 v)
translate by a vector, synonym for 'plus'; MODIFIES 'this'

plus

public void plus(Real2 p)
add a Real2 to all elements of 'this'; MODIFIES 'this'

subtract

public void subtract(Real2 v)
translate negatively; MODIFIES 'this'

multiplyBy

public void multiplyBy(double f)
multiply all coordinates be a given scalar (i.e. expands scale)

distance

public double distance(int i1,
                       int i2)
get distance between 2 points

distance

public double distance(IntSet is)
                throws BadArgumentException
get distance between 2 points
Throws:
BadArgumentException - a value in IntSet is not in the range 0 ... nelem-1

angle

public Angle angle(int i1,
                   int i2,
                   int i3)
            throws ZeroVectorException
get angle between 3 points
Throws:
ZeroVectorException - two points are coincident

angle

public Angle angle(IntSet is)
            throws BadArgumentException,
                   ZeroVectorException
get angle between 3 points
Throws:
BadArgumentException - a value in IntSet is not in the range 0 ... nelem-1
ZeroVectorException - two points are coincident

getReal2

public Real2 getReal2(int i)
get the i'th Real2

getXY

public RealArray getXY()
get the coordinate coordinate array as doubles x,y,x,y, ...

getCoordinate

public double getCoordinate(int i,
                            Choice2 j)
get a single coordinate value

getXorY

public RealArray getXorY(Choice2 axis)
get a single coordinate array - e.g. all x-coordinates

swapXY

public void swapXY()
swap all X and Y coordinates; MODIFIES array

sortXYAscending

public void sortXYAscending()
sort X and Y within each point; MODIFIES array

sortXYDescending

public void sortXYDescending()
sort X and Y within each point; MODIFIES array

sortAscending

public Real2Vector sortAscending(Choice2 ax)
sort ARRAY on X or Y coordinate; returns new array

sortDescending

public Real2Vector sortDescending(Choice2 ax)
sort ARRAY on X or Y coordinate; returns new array

transformBy

public void transformBy(Transform2 t)
transforms 'this' by rotation-translation matrix; MODIFIES 'this'

rotateAboutCentroid

public void rotateAboutCentroid(Angle a)
rotate about centroid by given angle; MODIFIES 'this'

regularPolygon

public static Real2Vector regularPolygon(int nsides,
                                         double rad)
make a regular polygon, zero point at (0, rad); points go clockwise

makeString

public java.lang.String makeString()
we are not allowed a toString() here, as Vector is a final class