cz.cuni.amis.pogamut.base3d.worldview.object
Class Velocity

java.lang.Object
  extended by cz.cuni.amis.pogamut.base3d.worldview.object.Velocity
All Implemented Interfaces:
ILocomotive, java.io.Serializable, java.lang.Cloneable

public class Velocity
extends java.lang.Object
implements ILocomotive, java.io.Serializable, java.lang.Cloneable

Velocity within the world. Direction of the velocity is represented as a vector within the world's coordinates. Size of the velocity is represented by length of that vector.

See Also:
Serialized Form

Nested Class Summary
static class Velocity.PropertyEditor
          Property editor for Velocity.
 
Field Summary
 double x
          X coordinate.
 double y
          Y coordinate.
 double z
          Z coordinate.
 
Constructor Summary
Velocity()
          Creates velocity with all values set to zeroes.
Velocity(double[] d)
          Creates velocity from array of three doubles.
Velocity(double x, double y)
          Creates velocity with specified planar coordinates.
Velocity(double x, double y, double z)
          Creates velocity with specified coordinates.
Velocity(Tuple3d v)
          Creates velocity from specified 3D vector.
Velocity(Velocity velocity)
          Creates velocity same as the the passed one.
 
Method Summary
 Velocity absolute()
          Converts values of all three coordinates to absolute values.
 Velocity add(Velocity v)
          Retreives sum of this velocity and given velocity.
static Velocity add(Velocity v1, Velocity v2)
          Retreives sum of two given velocities.
 Velocity align()
          Projects the velocity into the (x, y) plane, i.e.
 Location asLocation()
           
 Vector3d asVector3d()
           
 Velocity clone()
           
 Velocity cross(Velocity v)
          Computes cross product of this and other given velocity.
static Velocity cross(Velocity v1, Velocity v2)
          Computes cross product of two given velocities.
 double dot(Velocity v)
          Computes dot product of this and other given velocity.
static double dot(Velocity v1, Velocity v2)
          Computes dot product of two given velocities.
static boolean equal(Velocity v1, Velocity v2)
          Tells, whether two given velocities equal.
static boolean equal(Velocity v1, Velocity v2, double epsilon)
          Tells, whether the distance between coordinates of two given velocities is less than or equal to the given epsilon.
 boolean equals(Velocity v)
          Tells, whether this velocity equals to given velocity.
 boolean equals(Velocity v, double epsilon)
          Tells, whether the distance between coordinates of this velocity and given velocity is less than or equal to the given epsilon.
 Vector3d getVector3d()
          Retreives javax.vecmath.Vector3d representation of the velocity.
 Velocity getVelocity()
          Retreives the velocity itself to implement ILocomotive.
 double getX()
          X coordinate.
 double getY()
          Y coordinate.
 double getZ()
          Z coordinate.
 Velocity interpolate(Velocity v, double d)
          Linearly interpolates between this velocity and given velocity.
static Velocity interpolate(Velocity v1, Velocity v2, double d)
          Linearly interpolates between two given velocities.
 boolean isPlanarZero()
          Tells, whether the velocity is zero in planar coordinates.
 boolean isZero()
          Tells, whether the velocity is zero.
 boolean isZero(double epsilon)
          Tells, whether the velocity is zero (with tolerance of 'epsilon').
 Velocity negate()
          Negates values of all three coordinates.
 Velocity normalize()
          Retreives normalized vector of the velocity.
 Velocity scale(double d)
          Scales values of all three coordinates by given multiplier.
 Velocity setX(double x)
          Sets the X coordinate.
 Velocity setY(double y)
          Sets the Y coordinate.
 Velocity setZ(double z)
          Sets the Z coordinate.
 Velocity sideways()
          Computes sideways velocity, i.e.
 double size()
          Retreives size of the velocity.
 double sizeSquare()
          Retreives squared size of the velocity.
 Velocity sub(Velocity v)
          Retreives subtraction of given velocity from this velocity.
static Velocity sub(Velocity v1, Velocity v2)
          Retreives subtraction of two given velocities.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x
X coordinate.


y

public double y
Y coordinate.


z

public double z
Z coordinate.

Constructor Detail

Velocity

public Velocity()
Creates velocity with all values set to zeroes.


Velocity

public Velocity(Velocity velocity)
Creates velocity same as the the passed one.

Parameters:
velocity - original velocity that will be copied

Velocity

public Velocity(double x,
                double y,
                double z)
Creates velocity with specified coordinates.

Parameters:
x - X coordinate.
y - Y coordinate.
z - Z coordinate.

Velocity

public Velocity(double x,
                double y)
Creates velocity with specified planar coordinates. Sets z to zero.

Parameters:
x - X coordinate.
y - Y coordinate.

Velocity

public Velocity(double[] d)
Creates velocity from array of three doubles. Sets x = d[0], y = d[1] and z = d[2].

Parameters:
d - Array of (at least) three doubles to be used for creation.

Velocity

public Velocity(Tuple3d v)
Creates velocity from specified 3D vector.

Parameters:
v - Vector in space to be used for creation.
Method Detail

clone

public Velocity clone()
Overrides:
clone in class java.lang.Object

asVector3d

public Vector3d asVector3d()

asLocation

public Location asLocation()

getX

public double getX()
X coordinate.

Returns:
X coordinate.

getY

public double getY()
Y coordinate.

Returns:
Y coordinate.

getZ

public double getZ()
Z coordinate.

Returns:
Z coordinate.

setX

public Velocity setX(double x)
Sets the X coordinate.

Returns:
self.

setY

public Velocity setY(double y)
Sets the Y coordinate.

Returns:
self.

setZ

public Velocity setZ(double z)
Sets the Z coordinate.

Returns:
self.

isZero

public boolean isZero()
Tells, whether the velocity is zero.

Returns:
True if the velocity is 0 in all directions; false otherwise.

isZero

public boolean isZero(double epsilon)
Tells, whether the velocity is zero (with tolerance of 'epsilon').

Returns:
True if the velocity is 0 in all directions; false otherwise.

isPlanarZero

public boolean isPlanarZero()
Tells, whether the velocity is zero in planar coordinates.

Returns:
True if the velocity is 0 in planar directions; false otherwise.

size

public double size()
Retreives size of the velocity.

Returns:
Size of the velocity.

sizeSquare

public double sizeSquare()
Retreives squared size of the velocity.

Returns:
Size of the velocity to the power of 2.

normalize

public Velocity normalize()
Retreives normalized vector of the velocity.

Returns:
Velocity normalized to the size of 1.

negate

public Velocity negate()
Negates values of all three coordinates.

Returns:
Velocity with all three coordinates negated.

absolute

public Velocity absolute()
Converts values of all three coordinates to absolute values.

Returns:
Velocity with all three coordinates absoluted.

scale

public Velocity scale(double d)
Scales values of all three coordinates by given multiplier.

Parameters:
d - Scaling multiplier.
Returns:
Velocity with all three coordinates negated.

dot

public double dot(Velocity v)
Computes dot product of this and other given velocity.

Parameters:
v - Second velocity to be computed upon.
Returns:
Dot product (scalar product) of the two velocities.

dot

public static double dot(Velocity v1,
                         Velocity v2)
Computes dot product of two given velocities.

Parameters:
v1 - First velocity to be computed upon.
v2 - Second velocity to be computed upon.
Returns:
Dot product (scalar product) of the two velocities.

cross

public Velocity cross(Velocity v)
Computes cross product of this and other given velocity.

Parameters:
v - Second velocity to be computed upon.
Returns:
Cross product of the two velocities.

cross

public static Velocity cross(Velocity v1,
                             Velocity v2)
Computes cross product of two given velocities.

Parameters:
v1 - First velocity to be computed upon.
v2 - Second velocity to be computed upon.
Returns:
Cross product of the two velocities.

add

public Velocity add(Velocity v)
Retreives sum of this velocity and given velocity.

Parameters:
v - Velocity to by added to this velocity.
Returns:
Sum of the two velocities.

add

public static Velocity add(Velocity v1,
                           Velocity v2)
Retreives sum of two given velocities.

Parameters:
v1 - First velocity to by summed.
v2 - Second velocity to by summed.
Returns:
Sum of the two velocities.

sub

public Velocity sub(Velocity v)
Retreives subtraction of given velocity from this velocity.

Parameters:
v - Velocity to be subtracted.
Returns:
Subtraction of the two velocities.

sub

public static Velocity sub(Velocity v1,
                           Velocity v2)
Retreives subtraction of two given velocities.

Parameters:
v1 - Velocity to be subtracted from.
v2 - Velocity to be subtracted.
Returns:
Subtraction of the two velocities.

interpolate

public Velocity interpolate(Velocity v,
                            double d)
Linearly interpolates between this velocity and given velocity.

Parameters:
v - Velocity to be interpolated to.
d - Interpolation parameter.
Returns:
Linear interpolation between the two velocities.

interpolate

public static Velocity interpolate(Velocity v1,
                                   Velocity v2,
                                   double d)
Linearly interpolates between two given velocities.

Parameters:
v1 - Velocity to be interpolated from.
v2 - Velocity to be interpolated to.
d - Interpolation parameter.
Returns:
Linear interpolation between the two velocities.

equals

public boolean equals(Velocity v)
Tells, whether this velocity equals to given velocity.

Parameters:
v - Velocity to be compared with.
Returns:
True, if the velocities have the same values of all three corresponding coordinates.

equal

public static boolean equal(Velocity v1,
                            Velocity v2)
Tells, whether two given velocities equal.

Parameters:
v1 - First velocity to comapre.
v2 - Second velocity to comapre.
Returns:
True, if the velocities have the same values of all three corresponding coordinates.

equals

public boolean equals(Velocity v,
                      double epsilon)
Tells, whether the distance between coordinates of this velocity and given velocity is less than or equal to the given epsilon.

Parameters:
v - Velocity to comapre with.
epsilon - Epsilon to compare with.
Returns:
True, if the distance between the velocities is less than the epsilon, false otherwise.

equal

public static boolean equal(Velocity v1,
                            Velocity v2,
                            double epsilon)
Tells, whether the distance between coordinates of two given velocities is less than or equal to the given epsilon.

Parameters:
v1 - First velocity to comapre.
v2 - Second velocity to comapre.
epsilon - Epsilon to compare with.
Returns:
True, if the distance between the velocities is less than the epsilon, false otherwise.

align

public Velocity align()
Projects the velocity into the (x, y) plane, i.e. removes z coordinate.

Returns:
Aligned velocity, with z coordinate set to zero.

sideways

public Velocity sideways()
Computes sideways velocity, i.e. orthogonal velocity to projection of this velocity to (x, y) plane.

Note: Ignores the z coordinate whatsoever, which is the same as projecting the velocity to the (x, y) plane. Calculates orthogonal vector to this projection. Returns vector (y, -x, 0).

Returns:
Aligned velocity, with z coordinate set to zero.

getVelocity

public Velocity getVelocity()
Retreives the velocity itself to implement ILocomotive.

Specified by:
getVelocity in interface ILocomotive
Returns:
The velocity itself (note: does not create a copy).

getVector3d

public Vector3d getVector3d()
Retreives javax.vecmath.Vector3d representation of the velocity.

Returns:
javax.vecmath.Vector3d representation with x, y and z values set.

toString

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