Package org.openpnp.model
Class Location
- java.lang.Object
-
- org.openpnp.model.Location
-
public class Location extends java.lang.Object
A Location is a an immutable 3D point in X, Y, Z space with a rotation component. The rotation is applied about the Z axis.
-
-
Constructor Summary
Constructors Constructor Description Location(LengthUnit units)
Location(LengthUnit units, double x, double y, double z, double rotation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Location
add(Location l)
Returns a new Location with the given Location's X, Y, and Z components added to this Location's X, Y, and Z components.Location
addWithRotation(Location l)
Returns a new Location with the given Location's X, Y, and Z components added to this Location's X, Y, and Z components.boolean
containsLocation(Location originLocation, Location targetLocation)
Checks if targetLocation is contained in current location given the current location represents a rectangular item with the origin in originLocation.Location
convertToUnits(LengthUnit units)
Location
derive(java.lang.Double x, java.lang.Double y, java.lang.Double z, java.lang.Double rotation)
Returns a new Location with the same units as this one but with values updated to the passed in values.Location
derive(Location location, boolean x, boolean y, boolean z, boolean rotation)
Returns a new Location with the same units as this one but with values updated from a second Location.Location
deriveLengths(Length x, Length y, Length z, java.lang.Double rotation)
Returns a new Location with the same units as this one but with values updated to the passed in Lengths.Length
dotProduct(Location l)
Return the dot product of this and l.boolean
equals(java.lang.Object obj)
Performs a unit agnostic equality check.Length
getLengthX()
Length
getLengthY()
Length
getLengthZ()
double
getLinearDistanceTo(double x, double y)
double
getLinearDistanceTo(Location location)
Returns the distance between this Location and the specified Location in the units of this Location.double
getLinearDistanceToLine(Location A, Location B)
Returns the distance between this Location and the infinite line defined by the Locations a and b, in the units of this Location.double
getLinearDistanceToLineSegment(Location A, Location B)
Returns the distance between this Location and the line segment defined by the Locations a and b, in the units of this Location.Length
getLinearLengthTo(Location location)
Location
getLocalLocationRelativeTo(Location baseLocation)
Treats this as a global location in the same reference frame as baseLocation and returns the local location of this relative to the baseLocationdouble
getRotation()
LengthUnit
getUnits()
double
getX()
Point
getXyPoint()
double
getXyzcDistanceTo(Location location)
double
getXyzDistanceTo(Location location)
Length
getXyzLengthTo(Location location)
double
getY()
double
getZ()
int
hashCode()
Location
invert(boolean x, boolean y, boolean z, boolean rotation)
Returns a new Location with the same units as this one and with any of fields specified as true inverted from the values of this one.boolean
isInitialized()
Location
multiply(double factor)
Returns a new Location based on this Location with values multiplied by the specified factor.Location
multiply(double x, double y, double z, double rotation)
Returns a new Location based on this Location with values multiplied by the specified values.Location
multiply(Location l)
Returns a new Location with the given Location's X, Y and Z components multiplied by this Location's X, Y and Z components.Location
offsetWithRotationFrom(Location baseLocation)
Treats this as local location relative to baseLocation and returns the global location of this in the same reference frame as baseLocationLocation
rotateXy(double angle)
Returns a new Location with this Location's X and Y rotated by angle.Location
rotateXyCenterPoint(Location center, double angle)
Location
subtract(Location l)
Returns a new Location with the given Location's X, Y, and Z components subtracted from this Location's X, Y, and Z components.Location
subtractWithRotation(Location l)
Same assubtract(Location)
but also subtracts rotation.java.lang.String
toString()
Location
unitVectorTo(Location l)
Returns the unit vector of the vector between this and location l in units of this.
-
-
-
Field Detail
-
origin
public static final Location origin
-
-
Constructor Detail
-
Location
public Location(LengthUnit units)
-
Location
public Location(LengthUnit units, double x, double y, double z, double rotation)
-
-
Method Detail
-
getX
public double getX()
-
getY
public double getY()
-
getZ
public double getZ()
-
getRotation
public double getRotation()
-
getUnits
public LengthUnit getUnits()
-
convertToUnits
public Location convertToUnits(LengthUnit units)
-
getLinearDistanceTo
public double getLinearDistanceTo(Location location)
Returns the distance between this Location and the specified Location in the units of this Location.- Parameters:
location
-- Returns:
-
getLinearDistanceTo
public double getLinearDistanceTo(double x, double y)
-
getXyzDistanceTo
public double getXyzDistanceTo(Location location)
-
getXyzcDistanceTo
public double getXyzcDistanceTo(Location location)
-
getLinearDistanceToLine
public double getLinearDistanceToLine(Location A, Location B)
Returns the distance between this Location and the infinite line defined by the Locations a and b, in the units of this Location. From http://www.ahristov.com/tutorial/geometry-games/point-line-distance.html- Returns:
-
getLinearDistanceToLineSegment
public double getLinearDistanceToLineSegment(Location A, Location B)
Returns the distance between this Location and the line segment defined by the Locations a and b, in the units of this Location. From Real Time Collision Detection p/130- Returns:
-
getLengthX
public Length getLengthX()
-
getLengthY
public Length getLengthY()
-
getLengthZ
public Length getLengthZ()
-
subtract
public Location subtract(Location l)
Returns a new Location with the given Location's X, Y, and Z components subtracted from this Location's X, Y, and Z components. Rotation is left unchanged.- Parameters:
l
-- Returns:
-
subtractWithRotation
public Location subtractWithRotation(Location l)
Same assubtract(Location)
but also subtracts rotation.- Parameters:
l
-- Returns:
-
add
public Location add(Location l)
Returns a new Location with the given Location's X, Y, and Z components added to this Location's X, Y, and Z components. Rotation is left unchanged.- Parameters:
l
-- Returns:
-
addWithRotation
public Location addWithRotation(Location l)
Returns a new Location with the given Location's X, Y, and Z components added to this Location's X, Y, and Z components. Rotation is included.- Parameters:
l
-- Returns:
-
multiply
public Location multiply(Location l)
Returns a new Location with the given Location's X, Y and Z components multiplied by this Location's X, Y and Z components. Rotation is left unchanged.- Parameters:
l
-- Returns:
-
multiply
public Location multiply(double x, double y, double z, double rotation)
Returns a new Location based on this Location with values multiplied by the specified values. Units are the same as this Location.- Parameters:
x
-y
-z
-rotation
-- Returns:
-
multiply
public Location multiply(double factor)
Returns a new Location based on this Location with values multiplied by the specified factor. Units are the same as this Location.- Parameters:
factor
-- Returns:
-
invert
public Location invert(boolean x, boolean y, boolean z, boolean rotation)
Returns a new Location with the same units as this one and with any of fields specified as true inverted from the values of this one. Specifically, if one of the x, y, z or rotation fields are specified true in the method call, that field will be multipled by -1 in the returned Location.- Parameters:
x
-y
-z
-rotation
-- Returns:
-
unitVectorTo
public Location unitVectorTo(Location l)
Returns the unit vector of the vector between this and location l in units of this.- Parameters:
l
-- Returns:
-
dotProduct
public Length dotProduct(Location l)
Return the dot product of this and l. Can be used to calculate the cosinus between two unit vectors.- Parameters:
l
-- Returns:
-
derive
public Location derive(java.lang.Double x, java.lang.Double y, java.lang.Double z, java.lang.Double rotation)
Returns a new Location with the same units as this one but with values updated to the passed in values. A caveat is that if a specified value is null, the new Location will contain the value from this object instead of the new value. This is intended as a utility method, useful for creating new Locations based on existing ones with one or more values changed.- Parameters:
x
-y
-z
-rotation
-- Returns:
-
deriveLengths
public Location deriveLengths(Length x, Length y, Length z, java.lang.Double rotation)
Returns a new Location with the same units as this one but with values updated to the passed in Lengths. A caveat is that if a specified value is null, the new Location will contain the value from this object instead of the new value. The Lengths will automatically be converted to this locations's units. This is intended as a utility method, useful for creating new Locations based on existing ones with one or more values changed.- Parameters:
x
-y
-z
-rotation
-- Returns:
-
derive
public Location derive(Location location, boolean x, boolean y, boolean z, boolean rotation)
Returns a new Location with the same units as this one but with values updated from a second Location. If a specified boolean is false, the new Location will contain the value from this object instead of the second location. This is intended as a utility method, useful for creating new Locations based on two existing ones with one or more values substituted.- Parameters:
location
-x
-y
-z
-rotation
-- Returns:
-
rotateXy
public Location rotateXy(double angle)
Returns a new Location with this Location's X and Y rotated by angle. Z and Rotation are unchanged.- Parameters:
angle
-- Returns:
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getXyPoint
public Point getXyPoint()
-
containsLocation
public boolean containsLocation(Location originLocation, Location targetLocation)
Checks if targetLocation is contained in current location given the current location represents a rectangular item with the origin in originLocation.
-
offsetWithRotationFrom
public Location offsetWithRotationFrom(Location baseLocation)
Treats this as local location relative to baseLocation and returns the global location of this in the same reference frame as baseLocation- Parameters:
baseLocation
-- Returns:
-
getLocalLocationRelativeTo
public Location getLocalLocationRelativeTo(Location baseLocation)
Treats this as a global location in the same reference frame as baseLocation and returns the local location of this relative to the baseLocation- Parameters:
baseLocation
-- Returns:
-
equals
public boolean equals(java.lang.Object obj)
Performs a unit agnostic equality check. If the Object being tested is a Location in a different unit, it is first converted to the units of this Location and then each value field is compared.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isInitialized
public boolean isInitialized()
- Returns:
- true if at least one of the coordinates are non-zero, assuming the location is therefore initialized.
-
-