com.speckled.specksim
Class SpeckPosition

java.lang.Object
  extended by com.speckled.specksim.SpeckPosition

public class SpeckPosition
extends java.lang.Object

Encapsulates the position and orientation of a speck.

Author:
ryanm

Nested Class Summary
static class SpeckPosition.Configurator
          A useful configurator for manipulating a SpeckPosition.
 
Field Summary
 com.ryanm.util.geom.Orientation orientation
          The orientation of the speck
 Point3d position
          The position of the speck
 
Constructor Summary
SpeckPosition()
          Standard constructor
SpeckPosition(java.io.DataInputStream dis)
          Constructs a new SpeckPosition from the values read from the stream
SpeckPosition(SpeckPosition sp)
          Copies the supplied SpeckPosition
 
Method Summary
static SpeckPosition add(SpeckPosition so1, SpeckPosition so2)
          Adds two SpeckOrientations.
 void encode(java.io.DataOutputStream dos)
          Encodes the values of the SpeckPosition to the supplied stream
 boolean epsilonEquals(SpeckPosition p, double delta)
          Determines if this SpeckPosition is the same as another, within a defined tolerance
 boolean equals(java.lang.Object o)
           
 Matrix4d getTransform()
          Calculates the transform that will take us from the origin, facing down the z-axis, to the orientation of this object
 boolean isZero()
          Determines if this SpeckPosition has the zero vector for position and zero as all rotation angles.
static void main(java.lang.String[] args)
          Tests addition and subtraction
 void set(SpeckPosition sp)
          Sets the values of this SpeckPosition to copy those of the supplied SpeckPosition
static SpeckPosition subtract(SpeckPosition a, SpeckPosition b)
          Subtracts two SpeckOrientations.
 java.lang.String toString()
           
 void transform(Matrix4d m)
          Transforms this SpeckPosition by the supplied matrix
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

position

public Point3d position
The position of the speck


orientation

public com.ryanm.util.geom.Orientation orientation
The orientation of the speck

Constructor Detail

SpeckPosition

public SpeckPosition()
Standard constructor


SpeckPosition

public SpeckPosition(SpeckPosition sp)
Copies the supplied SpeckPosition

Parameters:
sp - The speckPosition to copy

SpeckPosition

public SpeckPosition(java.io.DataInputStream dis)
              throws java.io.IOException
Constructs a new SpeckPosition from the values read from the stream

Parameters:
dis - the stream to read from
Throws:
java.io.IOException
Method Detail

main

public static void main(java.lang.String[] args)
Tests addition and subtraction

Parameters:
args -

getTransform

public Matrix4d getTransform()
Calculates the transform that will take us from the origin, facing down the z-axis, to the orientation of this object

Returns:
the transform

transform

public void transform(Matrix4d m)
Transforms this SpeckPosition by the supplied matrix

Parameters:
m - The transformation matrix

add

public static SpeckPosition add(SpeckPosition so1,
                                SpeckPosition so2)
Adds two SpeckOrientations. This is analogous to using so1 as the origin for the values of s02.

Parameters:
so1 - The first orientation
so2 - The second orientation
Returns:
The combined orientation

subtract

public static SpeckPosition subtract(SpeckPosition a,
                                     SpeckPosition b)
Subtracts two SpeckOrientations. Calculates b from the point of view of a

Parameters:
a - The first orientation
b - The second orientation
Returns:
The subtracted orientation

set

public void set(SpeckPosition sp)
Sets the values of this SpeckPosition to copy those of the supplied SpeckPosition

Parameters:
sp - The values to copy.

isZero

public boolean isZero()
Determines if this SpeckPosition has the zero vector for position and zero as all rotation angles. Can help avoid doing costly transforms.

Returns:
true if every component of the position is zero and every rotation angle is zero, false otherwise.

toString

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

encode

public void encode(java.io.DataOutputStream dos)
            throws java.io.IOException
Encodes the values of the SpeckPosition to the supplied stream

Parameters:
dos - the stream to write to
Throws:
java.io.IOException - If something goes wrong

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

epsilonEquals

public boolean epsilonEquals(SpeckPosition p,
                             double delta)
Determines if this SpeckPosition is the same as another, within a defined tolerance

Parameters:
p - The SpeckPosition to test against
delta - The maximum distance between the two SpeckPosition's positions, up and forward vectors
Returns:
true if sufficiently similar, false otherwise