AnyLogic
Expand
Font size
All Implemented Interfaces:
Locatable2D, Serializable, Cloneable
Direct Known Subclasses:
Position

public class Point
extends Object
implements Serializable, Cloneable, Locatable2D
Class representing Point structure: three coordinates (x, y, z). Used in various utility methods in the AnyLogic Engine and in some AnyLogic libraries.
For those utilities which operate in 2D space (x, y), the third (z) coordinate is simply ignored
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Field Summary

Modifier and TypeFieldDescription
doublex
The x coordinate of this Point.
doubley
The y coordinate of this Point.
doublez
The z coordinate of this Point.

Constructor Summary

ConstructorDescription
Point()
Creates new point with zero (0, 0, 0) coordinates
Point(double x, double y)
Creates new point with the given (x, y) coordinates.
Point(double x, double y, double z)
Creates new point with the given coordinates.
Point(Point p)
Creates a copy of the given point

Method Summary

Modifier and TypeMethodDescription
Pointadd(Point p)
Adds p to this point: moves this point by the offset specified by the given point p.
Pointclone() 
Pointclone(Point out)
Fills the given output instance (if it is not null) or otherwise creates a copy of this object and returns it
doubledistance(double px, double py)
Returns the distance from this Point to the specified point.
doubledistance(double px, double py, double pz)
Returns the distance from this Point to the specified point.
doubledistance(Point p)
Returns the distance from this Point to the specified Point.
doubledistance2D(Point p)
Returns the distance from this Point to the specified Point.
doubledistanceGIS(double lat, double lon)
Returns the distance from this Point to the specified (lat, lon) on GIS surface.
doubledistanceGIS(double lat, double lon, LengthUnits units)
Returns the distance from this Point to the specified (lat, lon) on GIS surface.
doubledistanceGIS(Point p)
Returns the distance from this Point to the specified Point on GIS surface.
doubledistanceGIS(Point p, LengthUnits units)
Returns the distance from this Point to the specified Point on GIS surface.
doubledistanceSq(double px, double py)
Returns the square of the distance from this Point to the specified point.
doubledistanceSq(double px, double py, double pz)
Returns the square of the distance from this Point to the specified point.
This method is useful for comparing different distances, finding nearest point etc.
doubledistanceSq(Point p)
Returns the square of the distance from this Point to the specified Point.
This method is useful for comparing different distances, finding nearest point etc.
doubledistanceSq2D(Point p)
Returns the square of the distance from this Point to the specified Point.
booleanequals(Point p, double relativeError)
Returns true if this point has the same coordinates as in the given point, within the given relative error.
booleanequals(Object obj)
Returns true if the given object is Point and it has exactly the same coordinates as in this Point.
booleanequals2D(Point p, double relativeError)
Returns true if this point has the same (x, y) coordinates (z is ignored) as in the given point, within the given relative error.
doublegetLatitude()
Returns the latitude of this Point
doublegetLongitude()
Returns the longitude if this Point
doublegetX()
Returns the x coordinate of this Point
doublegetY()
Returns the y coordinate of this Point
doublegetZ()
Returns the z coordinate of this Point
inthashCode() 
PointsetLatLon(double lat, double lon)
Set latitude and longitude of this Point
PointsetLocation(double x, double y)
Sets the location of this Point to the given coordinates.
PointsetLocation(double x, double y, double z)
Sets the location of this Point to the given coordinates.
PointsetLocation(Point p)
Sets the location of this Point to the same coordinates as in the given Point object.
Pointsub(Point p)
Subtracts p from this point: moves this point by the negative offset specified by the given point p.
StringtoString() 

Methods inherited from class java.lang.Object

getClass, notify, notifyAll, wait, wait, wait

Field Details

x

public double x
The x coordinate of this Point. In case of GIS environment this is the latitude of this Point, measured in degrees (-90 ... (South) ... 0 ... (North) ... +90)

y

public double y
The y coordinate of this Point. In case of GIS environment this is the longitude of the Point, measured in degrees (-180 ... (West) ... 0 ... (East) ... +180)

z

public double z
The z coordinate of this Point.

Constructor Details

Point

public Point()
Creates new point with zero (0, 0, 0) coordinates

Point

public Point(Point p)
Creates a copy of the given point
Parameters:
p - the original point

Point

public Point(double x,
 double y,
 double z)
Creates new point with the given coordinates.
Parameters:
x - the x coordinate of the Point
y - the y coordinate of the Point
z - the z coordinate of the Point

Point

public Point(double x,
 double y)
Creates new point with the given (x, y) coordinates. (z coordinate is set to zero)
Parameters:
x - the x coordinate of the Point In case of GIS environment this is the latitude of the Point, measured in degrees (-90 ... (South) ... 0 ... (North) ... +90)
y - the y coordinate of the Point In case of GIS environment this is the longitude of the Point, measured in degrees (-180 ... (West) ... 0 ... (East) ... +180)

Method Details

getX

public double getX()
Returns the x coordinate of this Point
Specified by:
getX in interface Locatable2D
Returns:
the x coordinate of this Point

getY

public double getY()
Returns the y coordinate of this Point
Specified by:
getY in interface Locatable2D
Returns:
the y coordinate of this Point

getZ

public double getZ()
Returns the z coordinate of this Point
Returns:
the z coordinate of this Point

setLocation

public Point setLocation(double x,
 double y,
 double z)
Sets the location of this Point to the given coordinates.
Parameters:
x - the new x coordinate of this Point
y - the new y coordinate of this Point
z - the new z coordinate of this Point
Returns:
this Point object

setLocation

public Point setLocation(double x,
 double y)
Sets the location of this Point to the given coordinates. (z coordinate is not changed)
Parameters:
x - the new x coordinate of this Point In case of GIS environment this is the latitude of this Point, measured in degrees (-90 ... (South) ... 0 ... (North) ... +90)
y - the y coordinate of the Point In case of GIS environment this is the longitude of this Point, measured in degrees (-180 ... (West) ... 0 ... (East) ... +180)
Returns:
this Point object

setLatLon

public Point setLatLon(double lat,
 double lon)
Set latitude and longitude of this Point
Parameters:
lat - the latitude coordinate of the Point measured in degrees (-90 ... (South) ... 0 ... (North) ... +90)
lon - the longitude coordinate of the Point measured in degrees (-180 ... (West) ... 0 ... (East) ... +180)
Returns:
this Point object

setLocation

public Point setLocation(Point p)
Sets the location of this Point to the same coordinates as in the given Point object.
Parameters:
p - the specified Point to which to set this Point
Returns:
this Point object

add

public Point add(Point p)
Adds p to this point: moves this point by the offset specified by the given point p. In other words, increments coordinates of this point by the values of p's coordinates.
Returns this point for convenience.
Parameters:
p - the point which will be added to this point
Returns:
this point

sub

public Point sub(Point p)
Subtracts p from this point: moves this point by the negative offset specified by the given point p. In other words, decrements coordinates of this point by the values of p's coordinates.
Returns this point for convenience.
Parameters:
p - the point which will be subtracted from this point
Returns:
this point

distanceSq

public double distanceSq(Point p)
Returns the square of the distance from this Point to the specified Point.
This method is useful for comparing different distances, finding nearest point etc. because of better performance compared with distance()
Parameters:
p - the specified point to be measured against this Point
Returns:
the square of the distance between this Point and the specified Point.

distanceSq2D

public double distanceSq2D(Point p)
Returns the square of the distance from this Point to the specified Point. Z coordinate isn't used in calculation.
This method is useful for comparing different distances, finding nearest point etc. because of better performance compared with distance()
Parameters:
p - the specified point to be measured against this Point
Returns:
the square of the distance between this Point and the specified Point in the XY-plane (2D).

distanceSq

public double distanceSq(double px,
 double py)
Returns the square of the distance from this Point to the specified point. Z coordinate isn't used in calculation.
This method is useful for comparing different distances, finding nearest point etc. because of better performance compared with distance()
Parameters:
px - the x coordinate of the specified point to be measured against this Point
py - the y coordinate of the specified point to be measured against this Point
Returns:
the square of the distance between this Point and the specified point in the XY-plane (2D).

distance

public double distance(double px,
 double py)
Returns the distance from this Point to the specified point. Z coordinate isn't used in calculation.
Parameters:
px - the x coordinate of the specified point to be measured against this Point
py - the y coordinate of the specified point to be measured against this Point
Returns:
the distance between this Point and the specified point.

distanceSq

public double distanceSq(double px,
 double py,
 double pz)
Returns the square of the distance from this Point to the specified point.
This method is useful for comparing different distances, finding nearest point etc. because of better performance compared with distance()
Parameters:
px - the x coordinate of the specified point to be measured against this Point
py - the y coordinate of the specified point to be measured against this Point
pz - the z coordinate of the specified point to be measured against this Point
Returns:
the square of the distance between this Point and the specified point.

distance

public double distance(double px,
 double py,
 double pz)
Returns the distance from this Point to the specified point. Z coordinate isn't used in calculation.
Parameters:
px - the x coordinate of the specified point to be measured against this Point
py - the y coordinate of the specified point to be measured against this Point
pz - the z coordinate of the specified point to be measured against this Point
Returns:
the distance between this Point and the specified point.

distance

public double distance(Point p)
Returns the distance from this Point to the specified Point.
Parameters:
p - the specified point to be measured against this Point
Returns:
the distance between this Point and the specified Point.

distanceGIS

public double distanceGIS(Point p)
Returns the distance from this Point to the specified Point on GIS surface. Latitude and Longitude used.
Parameters:
p - the specified point to be measured against this Point
Returns:
the distance between this Point and the specified Point in meters.

distanceGIS

public double distanceGIS(Point p,
 LengthUnits units)
Returns the distance from this Point to the specified Point on GIS surface. Latitude and Longitude used.
Parameters:
p - the specified point to be measured against this Point
units - the units of length
Returns:
the distance between this Point and the specified Point in given length units.

distanceGIS

public double distanceGIS(double lat,
 double lon)
Returns the distance from this Point to the specified (lat, lon) on GIS surface.
Parameters:
lat - the latitude coordinate of the Point measured in degrees (-90 ... (South) ... 0 ... (North) ... +90)
lon - the longitude coordinate of the Point measured in degrees (-180 ... (West) ... 0 ... (East) ... +180)
Returns:
the distance in meters between this Point and the specified (lat, lon).

distanceGIS

public double distanceGIS(double lat,
 double lon,
 LengthUnits units)
Returns the distance from this Point to the specified (lat, lon) on GIS surface.
Parameters:
lat - the latitude coordinate of the Point measured in degrees (-90 ... (South) ... 0 ... (North) ... +90)
lon - the longitude coordinate of the Point measured in degrees (-180 ... (West) ... 0 ... (East) ... +180)
units - the units of length
Returns:
the distance in given length units between this Point and the specified (lat, lon).

distance2D

public double distance2D(Point p)
Returns the distance from this Point to the specified Point. Z coordinate isn't used in calculation.
Parameters:
p - the specified point to be measured against this Point
Returns:
the distance between this Point and the specified Point in the XY-plane (2D).

toString

public String toString()
Overrides:
toString in class Object

clone

public Point clone()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Returns true if the given object is Point and it has exactly the same coordinates as in this Point. Note that due to numeric errors there may cases when some calculated point has slightly different coordinates and hence doesn't match with expected value.
Overrides:
equals in class Object
See Also:

equals

public boolean equals(Point p,
 double relativeError)
Returns true if this point has the same coordinates as in the given point, within the given relative error. Each pair of coordinates is compared separately using this formula:
|x1 - x2| <= relativeError * max( |x1|, |x2| )
Parameters:
p - the point to compare to
relativeError - relative error, applied to each coordinate separately

equals2D

public boolean equals2D(Point p,
 double relativeError)
Returns true if this point has the same (x, y) coordinates (z is ignored) as in the given point, within the given relative error. Each pair of coordinates is compared separately using this formula:
|x1 - x2| <= relativeError * max( |x1|, |x2| )
Parameters:
p - the point to compare to
relativeError - relative error, applied to each coordinate separately

clone

public Point clone(Point out)
Fills the given output instance (if it is not null) or otherwise creates a copy of this object and returns it
Parameters:
out - the Point object to write to (may be null)
Returns:
the given output object (if was not null) or new Point with coordinates set equal to this object.

getLatitude

public double getLatitude()
Returns the latitude of this Point
Returns:
latitude

getLongitude

public double getLongitude()
Returns the longitude if this Point
Returns:
longitude