Package org.evoludo.geom
Class Point3D
Object
Point3D
- All Implemented Interfaces:
Point
Class representing a point in 3D Cartesian space.
- Author:
- Christoph Hauert
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubledistance()Calculate distance from the origin(0,0,0): \(\sqrt{x^2+y^2+z^2}\).doubleCalculate the distance between the two 3D pointspandq: \(\sqrt{(p.x-q.x)^2+(p.y-q.y)^2+(p.z-q.z)^2}\).doubleCalculate the distance squared from the origin(0,0,0): \(x^2+y^2+z^2\).doubleCalculate the distance squared between the two 3D pointspandq: \((p.x-q.x)^2+(p.y-q.y)^2+(p.z-q.z)^2\).doublegetX()Get thex-coordinate of this 3D point.doublegetY()Get they-coordinate of this 3D point.doublegetZ()Get thez-coordinate of this 3D point.scale(double s) Scale the coordinates of this 3D point by a factorsto(s*x,s*y,s*z).scale(double sx, double sy, double sz) Scale the coordinates of this 3D point by scalar factorssx,syandsz, respectively, to(sx*x, sy*y, sz*z).set(double x, double y, double z) Setx-,y- andz-coordinates of the 3D point.Setx-,y- andz-coordinates of the point to those of the 3D pointp.voidsetLocation(double x, double y, double z) Compatibility method (followingPoint2D.setLocation(double, double)).voidCompatibility method (followingPoint2D.setLocation(Point2D p)).setX(double x) Set thex-coordinate of this 3D point.setY(double y) Set they-coordinate of this 3D point.setZ(double z) Set thez-coordinate of this 3D point.shake(double quake) Randomly shake the position of this point by an amount scaled byquake.shift(double dx, double dy, double dz) Shift the 3D point bydx,dy, anddzin thex-,y-, andz-coordinates, respectively, to(x+p.x,y+p.y,z+p.z).Shift the 3D point byp.x,p.y, andp.zin thex-,y-, andz-coordinates, respectively, to(x+p.x,y+p.y,z+p.z).toString()
-
Field Details
-
x
public double xThex-coordinate of the point. -
y
public double yThey-coordinate of the point. -
z
public double zThez-coordinate of the point.
-
-
Constructor Details
-
Point3D
public Point3D()Create a new 3D point with coordinates(0,0,0). -
Point3D
Create a copy of the 3D pointp.- Parameters:
p- the 3D point to copy
-
Point3D
public Point3D(double x, double y, double z) Create a new 3D point with coordinates(x,y,z).- Parameters:
x- thex-coordinatey- they-coordinatez- thez-coordinate
-
-
Method Details
-
set
Setx-,y- andz-coordinates of the 3D point.- Parameters:
x- thex-coordinatey- they-coordinatez- thez-coordinate- Returns:
- this point
-
set
Setx-,y- andz-coordinates of the point to those of the 3D pointp.- Parameters:
p- the 3D point to copy coordinates from- Returns:
- this point
-
setLocation
public void setLocation(double x, double y, double z) Compatibility method (followingPoint2D.setLocation(double, double)).- Parameters:
x- thex-coordinatey- they-coordinatez- thez-coordinate
-
setLocation
Compatibility method (followingPoint2D.setLocation(Point2D p)).- Parameters:
p- the 3D point to copy the position from
-
shift
Shift the 3D point byp.x,p.y, andp.zin thex-,y-, andz-coordinates, respectively, to(x+p.x,y+p.y,z+p.z).- Parameters:
p- the shift in the(x, y, z)-coordinates- Returns:
- the shifted point
-
shift
Shift the 3D point bydx,dy, anddzin thex-,y-, andz-coordinates, respectively, to(x+p.x,y+p.y,z+p.z).- Parameters:
dx- the shift in thex-coordinatedy- the shift in they-coordinatedz- the shift in thez-coordinate- Returns:
- the shifted point
-
scale
Scale the coordinates of this 3D point by a factorsto(s*x,s*y,s*z).- Parameters:
s- the scaling factor- Returns:
- the scaled point
-
scale
Scale the coordinates of this 3D point by scalar factorssx,syandsz, respectively, to(sx*x, sy*y, sz*z).- Parameters:
sx- the scaling of thex-coordinatesy- the scaling of they-coordinatesz- the scaling of thez-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 3D point.- Returns:
- the
x-coordinate
-
setX
Set thex-coordinate of this 3D point.- Parameters:
x- the newx-coordinate- Returns:
- this point
-
getY
public double getY()Get they-coordinate of this 3D point.- Returns:
- the
y-coordinate
-
setY
Set they-coordinate of this 3D point.- Parameters:
y- the newy-coordinate- Returns:
- this point
-
getZ
public double getZ()Get thez-coordinate of this 3D point.- Returns:
- the
z-coordinate
-
setZ
Set thez-coordinate of this 3D point.- Parameters:
z- the newz-coordinate- Returns:
- this point
-
distance
public double distance()Calculate distance from the origin(0,0,0): \(\sqrt{x^2+y^2+z^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,0): \(x^2+y^2+z^2\).- Returns:
- the squared distance
-
distance
Calculate the distance between the two 3D pointspandq: \(\sqrt{(p.x-q.x)^2+(p.y-q.y)^2+(p.z-q.z)^2}\).For computational efficiency the fairly expensive square-roots calculations should be avoided whenever possible.
- Parameters:
q- the point to calculate distance to- Returns:
- the distance between the two points
- See Also:
-
distance2
Calculate the distance squared between the two 3D pointspandq: \((p.x-q.x)^2+(p.y-q.y)^2+(p.z-q.z)^2\).- Parameters:
q- the point to calculate distance to- Returns:
- the distance squared between the two points
-
toString
-