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

Package class diagram package Location
java.lang.Object
  extended by cz.cuni.amis.pogamut.base3d.worldview.object.Location
All Implemented Interfaces:
ILocated, Serializable, Cloneable

public class Location
extends Object
implements ILocated, Serializable, Cloneable

Location within the world. Location is represented as a point within the world's coordinates.

Author:
Juraj 'Loque' Simlovic, Radek 'Black_Hand' Pibil
See Also:
Serialized Form

Nested Class Summary
static class Location.PropertyEditor
          PropertyEditor for class Location.
 
Field Summary
static double DISTANCE_ZERO
          Zero delta for Location#equals(Location).
static Pattern locationPattern
          Pattern used to parse toString() in Location(String).
static Location NONE
          Location representing NONE.
 double x
          X coordinate.
 double y
          Y coordinate.
 double z
          Z coordinate.
static Location ZERO
          Location(0,0,0).
 
Constructor Summary
Location(double[] d)
          Creates location from array of three doubles.
Location(double x, double y)
          Creates location with specified planar coordinates.
Location(double x, double y, double z)
          Creates location with specified coordinates.
Location(float[] f)
          Creates location from array of three doubles.
Location(Location source)
          Copy constructor
Location(math.geom3d.Point3D p)
          Creates location from specified 3D point.
Location(String string)
          Parses the location from the "string" generated by toString().
Location(javax.vecmath.Tuple3d p)
          Creates location from specified 3D point.
 
Method Summary
 Location add(Location l)
          Retreives sum of this location and given location.
static Location add(Location l1, Location l2)
          Retreives sum of two given locations.
static Location add(Location l, Velocity v)
          Adds given velocity to given location.
 Location add(Velocity v)
          Adds given velocity to this location.
 Location addX(double x)
          Adds to the X coordinate.
 Location addXYZ(double x, double y, double z)
          Adds to the X,Y,Z coordinates.
 Location addY(double y)
          Adds to the Y coordinate.
 Location addZ(double z)
          Adds to the Z coordinate.
 javax.vecmath.Point3d asPoint3d()
           
 math.geom3d.Point3D asPoint3D()
           
 javax.vecmath.Vector3d asVector3d()
           
 Location clone()
           
 Location cross(Location b)
          Calculates cross product of this Location and Lcoations b
 double dot(Location b)
          Calculates dot product of this Location and Location b
 double dot2D(Location b)
          Calculates dot product of this Location and Location b in 2D (x,y coord only)
static boolean equal(Location l1, Location l2)
          Tells, whether two given locations equal.
static boolean equal(Location l1, Location l2, double epsilon)
          Tells, whether the distance between coordinates of two given locations is less than or equal to the given epsilon.
 boolean equals(Location l, double epsilon)
          Tells, whether the distance between coordinates of this location and given location is less than or equal to the given epsilon.
 boolean equals(Object obj)
          Tells, whether this location equals to given object.
static Location getAverage(Collection<Location> locations)
          Calculates average of all 'locations'.
 double getDistance(Location l)
          Calculates the distance between this and given location.
static double getDistance(Location l1, Location l2)
          Calculates the distance between two given locations.
 double getDistance2D(Location l)
          Calculates the distance between this and given location (ignoring 'z' coordinate).
static double getDistance2D(Location l1, Location l2)
          Calculates the distance between two given locations (ignoring 'z' coordinate).
 double getDistanceL1(Location l)
          Calculates the Manhattan distance between this and given location.
static double getDistanceL1(Location l1, Location l2)
          Calculates the Manhattan distance between two given locations.
 double getDistanceLinf(Location l)
          Calculates the Chebyshev distance between this and given location.
static double getDistanceLinf(Location l1, Location l2)
          Calculates the Chebyshev distance between two given locations.
 double getDistancePlane(Location l)
          Calculates the distance between this and given location after being projected to the (x,y) plane.
static double getDistancePlane(Location l1, Location l2)
          Calculates the distance between two given locations after being projected to the (x,y) plane.
 double getDistanceSquare(Location l)
          Calculates the square of the distance between this and given location.
static double getDistanceSquare(Location l1, Location l2)
          Calculates the square of the distance between two given locations.
 double getDistanceZ(Location location)
          Returns difference between z-coords (this.z - location.z).
 double getLength()
          Calculates length of Location
 Location getLocation()
          Retreives the location itself to implement ILocated.
 Location getNormalized()
          Normalizes this Location
 javax.vecmath.Point3d getPoint3d()
          Retreives javax.vecmath.Point3d representation of the location.
 Rotation getQuatLikeRotationSeq(Rotation.Order order)
          WIP not completed yet.
 Rotation getRotation(Rotation.Order order)
          Converts Location into Rotation.
 double getX()
          X coordinate.
 double getY()
          Y coordinate.
 double getZ()
          Z coordinate.
 int hashCode()
          Generates a hashCode for this Location.
 Location interpolate(Location l, double d)
          Lineary interpolates between this location and given location.
static Location interpolate(Location l1, Location l2, double d)
          Linearly interpolates between two given locations.
 Location invert()
          Calculates inverse Location
 Location mul(javax.vecmath.Matrix3d matrix)
          Projects this Location (vector) using matrix from parameter
 Location rotateXY(double angle)
          Rotate according to XY plane (~ YAW).
 Location rotateXZ(double angle)
          Rotate according to XZ plane (~ PITCH).
 Location rotateYZ(double angle)
          Rotate according to YZ plane (~ ROLL).
 Location scale(double d)
          Scales values of all three coordinates by given multiplier.
 Location scaleX(double x)
          Scales the X coordinate.
 Location scaleY(double y)
          Scales the Y coordinate.
 Location scaleZ(double z)
          Scales the Z coordinate.
 Location setX(double x)
          Sets the X coordinate.
 Location setY(double y)
          Sets the Y coordinate.
 Location setZ(double z)
          Sets the Z coordinate.
 Location sub(Location l)
          Retreives subtraction of given location from this location.
static Location sub(Location l1, Location l2)
          Retreives subtraction of two given locations.
static Location sub(Location l, Velocity v)
          Subtracts given velocity from given location.
 Location sub(Velocity v)
          Subtracts given velocity from this location.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NONE

public static final Location NONE
Location representing NONE.


ZERO

public static final Location ZERO
Location(0,0,0).


x

public final double x
X coordinate.


y

public final double y
Y coordinate.


z

public final double z
Z coordinate.


locationPattern

public static final Pattern locationPattern
Pattern used to parse toString() in Location(String).


DISTANCE_ZERO

public static final double DISTANCE_ZERO
Zero delta for Location#equals(Location).

See Also:
Constant Field Values
Constructor Detail

Location

public Location(double x,
                double y,
                double z)
Creates location with specified coordinates.

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

Location

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

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

Location

public Location(Location source)
Copy constructor

Parameters:
source - Location to copy

Location

public Location(String string)
Parses the location from the "string" generated by toString(). If it fails, it throws RuntimeException.

Parameters:
string -

Location

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

Parameters:
d - Array of doubles to be used for creation.

Location

public Location(float[] f)
Creates location from array of three doubles. Sets x = f[0], y = f[1] and z = f[2].

Parameters:
f - Array of to be used for creation.

Location

public Location(javax.vecmath.Tuple3d p)
Creates location from specified 3D point.

Parameters:
p - Point in space to be used for creation.

Location

public Location(math.geom3d.Point3D p)
Creates location from specified 3D point.

Parameters:
p - Point in space to be used for creation.
Method Detail

clone

public Location clone()
Overrides:
clone in class Object

asVector3d

public javax.vecmath.Vector3d asVector3d()

asPoint3d

public javax.vecmath.Point3d asPoint3d()

asPoint3D

public math.geom3d.Point3D asPoint3D()

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.

add

public Location add(Location l)
Retreives sum of this location and given location.

Parameters:
l - Location to be added to this location.
Returns:
Sum of the two locations.

add

public static Location add(Location l1,
                           Location l2)
Retreives sum of two given locations.

Parameters:
l1 - First location to be summed.
l2 - Second location to be summed.
Returns:
Sum of the two locations.

sub

public Location sub(Location l)
Retreives subtraction of given location from this location.

Parameters:
l - Location to be subtracted.
Returns:
Subtraction of the two locations.

sub

public static Location sub(Location l1,
                           Location l2)
Retreives subtraction of two given locations.

Parameters:
l1 - Location to be subtracted from.
l2 - Location to be subtracted.
Returns:
Subtraction of the two locations.

add

public Location add(Velocity v)
Adds given velocity to this location.

Parameters:
v - Velocity to be added to this location.
Returns:
Sum of the location and velocity.

add

public static Location add(Location l,
                           Velocity v)
Adds given velocity to given location.

Parameters:
l - Location to be summed.
v - Velocity to be summed.
Returns:
Sum of the location and velocity.

sub

public Location sub(Velocity v)
Subtracts given velocity from this location.

Parameters:
v - Velocity to be subtracted.
Returns:
Subtraction of the velocity from the location.

sub

public static Location sub(Location l,
                           Velocity v)
Subtracts given velocity from given location.

Parameters:
l - Location to be subtracted from.
v - Velocity to be subtracted.
Returns:
Subtraction of the velocity from the location.

scale

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

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

interpolate

public Location interpolate(Location l,
                            double d)
Lineary interpolates between this location and given location.

Parameters:
l - Location to be interpolated to.
d - Interpolation parameter.
Returns:
Linear interpolation between the two locations.

interpolate

public static Location interpolate(Location l1,
                                   Location l2,
                                   double d)
Linearly interpolates between two given locations.

Parameters:
l1 - Location to be interpolated from.
l2 - Location to be interpolated to.
d - Interpolation parameter.
Returns:
Linear interpolation between the two locations.

hashCode

public int hashCode()
Generates a hashCode for this Location.

Overrides:
hashCode in class Object
Returns:
the hashcode for this Location.

equals

public boolean equals(Object obj)
Tells, whether this location equals to given object.

Overrides:
equals in class Object
Parameters:
obj - Object to be compared with.
Returns:
True, if the object is a Location and has has the same values of all three corresponding coordinates.

equal

public static boolean equal(Location l1,
                            Location l2)
Tells, whether two given locations equal.

Parameters:
l1 - First location to compare.
l2 - Second location to compare.
Returns:
True, if the locations has the same values of all three corresponding coordinates.

equals

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

Parameters:
l - Location to compare with.
epsilon - Epsilon to compare with.
Returns:
True, if the distance between the locations is less than the epsilon, false otherwise.

equal

public static boolean equal(Location l1,
                            Location l2,
                            double epsilon)
Tells, whether the distance between coordinates of two given locations is less than or equal to the given epsilon.

Parameters:
l1 - First location to compare.
l2 - Second location to compare.
epsilon - Epsilon to compare with.
Returns:
True, if the distance between the locations is less than the epsilon, false otherwise.

getAverage

public static Location getAverage(Collection<Location> locations)
Calculates average of all 'locations'. If locations.size() == 0, returns null.

Parameters:
locations -
Returns:
average location

getDistance

public double getDistance(Location l)
Calculates the distance between this and given location.

Parameters:
l - Location to be calculated the distance to.
Returns:
Euclidean distance between the two locations.

getDistance2D

public double getDistance2D(Location l)
Calculates the distance between this and given location (ignoring 'z' coordinate).

Parameters:
l - Location to be calculated the distance to.
Returns:
Euclidean distance between the two locations.

getDistance

public static double getDistance(Location l1,
                                 Location l2)
Calculates the distance between two given locations.

Parameters:
l1 - Location to be calculated the distance from.
l2 - Location to be calculated the distance to.
Returns:
Euclidean distance between the two locations.

getDistanceZ

public double getDistanceZ(Location location)
Returns difference between z-coords (this.z - location.z).

Parameters:
location -
Returns:
z-difference

getDistance2D

public static double getDistance2D(Location l1,
                                   Location l2)
Calculates the distance between two given locations (ignoring 'z' coordinate).

Parameters:
l1 - Location to be calculated the distance from.
l2 - Location to be calculated the distance to.
Returns:
Euclidean distance between the two locations.

getDistanceSquare

public double getDistanceSquare(Location l)
Calculates the square of the distance between this and given location.

Parameters:
l - Location to be calculated the distance to.
Returns:
Square of the euclidean distance between the two locations.

getDistanceSquare

public static double getDistanceSquare(Location l1,
                                       Location l2)
Calculates the square of the distance between two given locations.

Parameters:
l1 - Location to be calculated the distance from.
l2 - Location to be calculated the distance to.
Returns:
Square of the euclidean distance between the two locations.

getDistanceL1

public double getDistanceL1(Location l)
Calculates the Manhattan distance between this and given location.

Parameters:
l - Location to be calculated the distance to.
Returns:
Manhattan (i.e. 1-norm) distance between the two locations.

getDistanceL1

public static double getDistanceL1(Location l1,
                                   Location l2)
Calculates the Manhattan distance between two given locations.

Parameters:
l1 - Location to be calculated the distance from.
l2 - Location to be calculated the distance to.
Returns:
Manhattan (i.e. 1-norm) distance between the two locations.

getDistanceLinf

public double getDistanceLinf(Location l)
Calculates the Chebyshev distance between this and given location.

Parameters:
l - Location to be calculated the distance to.
Returns:
Chebyshev (i.e. infinity-norm) distance between the two locations.

getDistanceLinf

public static double getDistanceLinf(Location l1,
                                     Location l2)
Calculates the Chebyshev distance between two given locations.

Parameters:
l1 - Location to be calculated the distance from.
l2 - Location to be calculated the distance to.
Returns:
Chebyshev (i.e. infinity-norm) distance between the two locations.

getDistancePlane

public double getDistancePlane(Location l)
Calculates the distance between this and given location after being projected to the (x,y) plane.

Parameters:
l - Location to be calculated the distance to.
Returns:
Plane-projected distance between the two locations.

getDistancePlane

public static double getDistancePlane(Location l1,
                                      Location l2)
Calculates the distance between two given locations after being projected to the (x,y) plane.

Parameters:
l1 - Location to be calculated the distance from.
l2 - Location to be calculated the distance to.
Returns:
Plane-projected distance between the two locations.

getLocation

public Location getLocation()
Retreives the location itself to implement ILocated.

Specified by:
getLocation in interface ILocated
Returns:
The location itself (note: does not create a copy).

getPoint3d

public javax.vecmath.Point3d getPoint3d()
Retreives javax.vecmath.Point3d representation of the location.

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

dot

public double dot(Location b)
Calculates dot product of this Location and Location b

Parameters:
b - Location to dot with
Returns:
dot product of this and b

dot2D

public double dot2D(Location b)
Calculates dot product of this Location and Location b in 2D (x,y coord only)

Parameters:
b - Location to dot with
Returns:
dot product of this and b

cross

public Location cross(Location b)
Calculates cross product of this Location and Lcoations b

Parameters:
b - Location to cross with
Returns:
cross product of this and b

rotateXY

public Location rotateXY(double angle)
Rotate according to XY plane (~ YAW).

Parameters:
angle - in radians
Returns:

rotateXZ

public Location rotateXZ(double angle)
Rotate according to XZ plane (~ PITCH).

Parameters:
angle - in radians
Returns:

rotateYZ

public Location rotateYZ(double angle)
Rotate according to YZ plane (~ ROLL).

Parameters:
angle - in radians
Returns:

getRotation

public Rotation getRotation(Rotation.Order order)
Converts Location into Rotation. Since location is only a single vector, roll is ommited.

Parameters:
order - tells resulting rotation, which rotation order should it represent
Returns:
resulting rotation

getQuatLikeRotationSeq

public Rotation getQuatLikeRotationSeq(Rotation.Order order)
WIP not completed yet. Use only in case roll yaw pitch order is used. Converts this location into rotation required to be applied on (1,0,0) in order achieve this location. Difference from getRotation is that in this case, quaternion like rotation chaining is achieved. That means that if you take rotation (x, y, z) then result would be same as applying rotation (x, 0, 0) on (1, 0, 0) - identity - then (0, y, 0) on the result, but like it was identity. Then again (0, 0, z) on the result like it was identity. Thus it works in similar vein as quaternion multiplication.

Parameters:
order -
Returns:

getNormalized

public Location getNormalized()
Normalizes this Location

Returns:
normalized

getLength

public double getLength()
Calculates length of Location

Returns:
length

mul

public Location mul(javax.vecmath.Matrix3d matrix)
Projects this Location (vector) using matrix from parameter

Parameters:
matrix - projection matrix
Returns:
resulting Location

invert

public Location invert()
Calculates inverse Location

Returns:
new inverted Location

setX

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

Returns:
new location object

setY

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

Returns:
new location object

setZ

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

Returns:
new location object

addX

public Location addX(double x)
Adds to the X coordinate.

Returns:
new location object

addY

public Location addY(double y)
Adds to the Y coordinate.

Returns:
new location object

addZ

public Location addZ(double z)
Adds to the Z coordinate.

Returns:
new location object

addXYZ

public Location addXYZ(double x,
                       double y,
                       double z)
Adds to the X,Y,Z coordinates.

Parameters:
x -
y -
z -
Returns:
new Location object

scaleX

public Location scaleX(double x)
Scales the X coordinate.

Returns:
new location object

scaleY

public Location scaleY(double y)
Scales the Y coordinate.

Returns:
new location object

scaleZ

public Location scaleZ(double z)
Scales the Z coordinate.

Returns:
new location object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.