Package org.evoludo.geom
Class Point2D
Object
Point2D
- All Implemented Interfaces:
Point
Class representing a point in 2D Cartesian space.
- Author:
- Christoph Hauert
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubledistance()Calculate the distance from the origin(0,0): \(\sqrt{x^2+y^2}\).doubleCalculate the distance between the two 2D pointspandq: \(\sqrt{(p.x-q.x)^2+(p.y-q.y)^2}\).doubleCalculate the distance squared from the origin(0,0): \(x^2+y^2\).doubleCalculate the distance squared between the two 2D pointspandq: \((p.x-q.x)^2+(p.y-q.y)^2\).doublegetX()Get thex-coordinate of this 2D point.doublegetY()Get they-coordinate of this 2D point.scale(double s) Scale the coordinates of this 2D point by a factorsto(s*x,s*y).scale(double sx, double sy) Scale the coordinates of this 2D point by scalar factorssxandsy, respectively, to(sx*x, sy*y).set(double x, double y) Setx- andy-coordinates of the point.Setx- andy-coordinates of the point to those of the 2D pointp.voidsetLocation(double x, double y) Compatibility method to coverPoint2D.setLocation(double, double).voidCompatibility method to coverPoint2D.setLocation(java.awt.geom.Point2D).setX(double x) Set thex-coordinate of this 2D point.setY(double y) Set they-coordinate of this 2D point.shake(double quake) Randomly shake the position of this point by an amount scaled byquake.shift(double dx, double dy) Shift the 2D point bydx, anddyin thex-,y-coordinates, respectively, to(x+dx,y+dy).Shift the 2D point byp.x, andp.yin thex-,y-coordinates, respectively, to(x+p.x,y+p.y).toString()
-
Field Details
-
x
public double xThex-coordinate of the point. -
y
public double yThey-coordinate of the point.
-
-
Constructor Details
-
Point2D
public Point2D()Create a new 2D point with coordinates(0,0). -
Point2D
Create a copy of the 2D pointp.- Parameters:
p- the 2D point to copy
-
Point2D
public Point2D(double x, double y) Create a new 2D point with coordinates(x,y).- Parameters:
x- thexcoordinatey- theycoordinate
-
-
Method Details
-
set
Setx- andy-coordinates of the point.- Parameters:
x- thex-coordinatey- they-coordinate- Returns:
- this point
-
set
Setx- andy-coordinates of the point to those of the 2D pointp.- Parameters:
p- the point to copy coordinates from- Returns:
- this point
-
setLocation
public void setLocation(double x, double y) Compatibility method to coverPoint2D.setLocation(double, double).- Parameters:
x- thex-coordinatey- they-coordinate- See Also:
-
setLocation
Compatibility method to coverPoint2D.setLocation(java.awt.geom.Point2D).- Parameters:
p- the 2D point to copy the position from- See Also:
-
shift
Shift the 2D point byp.x, andp.yin thex-,y-coordinates, respectively, to(x+p.x,y+p.y).- Parameters:
p- the shift in the(x, y)-coordinates- Returns:
- the shifted point
-
shift
Shift the 2D point bydx, anddyin thex-,y-coordinates, respectively, to(x+dx,y+dy).- Parameters:
dx- the shift in thex-coordinatedy- the shift in they-coordinate- Returns:
- the shifted point
-
scale
Scale the coordinates of this 2D point by a factorsto(s*x,s*y).- Parameters:
s- the scaling factor- Returns:
- the scaled point
-
scale
Scale the coordinates of this 2D point by scalar factorssxandsy, respectively, to(sx*x, sy*y).- Parameters:
sx- the scaling of thex-coordinatesy- the scaling of they-coordinate- Returns:
- the scaled point
-
shake
Description copied from interface:PointRandomly shake the position of this point by an amount scaled byquake. -
getX
public double getX()Get thex-coordinate of this 2D point.- Returns:
- the
x-coordinate
-
setX
Set thex-coordinate of this 2D point.- Parameters:
x- the newx-coordinate- Returns:
- this point
-
getY
public double getY()Get they-coordinate of this 2D point.- Returns:
- the
y-coordinate
-
setY
Set they-coordinate of this 2D point.- Parameters:
y- the newy-coordinate- Returns:
- this point
-
distance
public double distance()Calculate the distance from the origin(0,0): \(\sqrt{x^2+y^2}\).For computational efficiency the fairly expensive square-roots calculations should be avoided whenever possible.
- Returns:
- the distance
- See Also:
-
distance2
public double distance2()Calculate the distance squared from the origin(0,0): \(x^2+y^2\).- Returns:
- the squared distance
-
distance
Calculate the distance between the two 2D pointspandq: \(\sqrt{(p.x-q.x)^2+(p.y-q.y)^2}\).For computational efficiency the fairly expensive square-roots calculations should be avoided whenever possible.
- Parameters:
q- the point to calculate the distance to- Returns:
- the distance between the two points
- See Also:
-
distance2
Calculate the distance squared between the two 2D pointspandq: \((p.x-q.x)^2+(p.y-q.y)^2\).- Parameters:
q- the point to calculate distance to- Returns:
- the distance squared between the two points
-
toString
-