Package org.jlab.geom.prim
Class Point3D
java.lang.Object
org.jlab.geom.prim.Point3D
- All Implemented Interfaces:
Transformable,Showable
A 3D point in space represented by three coordinates coordinates (x, y, z).
The distance between two points can be obtained via
distance(org.jlab.geom.prim.Point3D). It is also possible to linearly
interpolate between one point an another via lerp(Point3D, double),
and to vector from one point to another via vectorTo(Point3D) and
vectorFrom(Point3D). Also, any collection of points can be averaged
using average(java.util.Collection).
- Author:
- gavalian
-
Constructor Summary
ConstructorsConstructorDescriptionPoint3D()Constructs a newPoint3Dat (0, 0, 0).Point3D(double x, double y, double z) Constructs a newPoint3Dat (x, y, z).Constructs a newPoint3Dby copying the x, y, and z coordinates of the given point.Constructs a newPoint3Dby adding the given vector to the given point.Constructs a newPoint3Dwith the given vector. -
Method Summary
Modifier and TypeMethodDescriptionstatic Point3Daverage(Collection<Point3D> points) Constructs a newPoint3Dat the geometric mean of the given points.static Point3DConstructs a newPoint3Dat the geometric mean of the given points.voidCombines this point with the given point.voidSets the components of this point to be equal the components of the given point.doubledistance(double x, double y, double z) Returns the distance between this point and the point at the given coordinate.doubleReturns the distance between this point and the given point.Constructs a newPoint3Dbetween this point and the given point by linearly interpolating from this point to the given point by the amount specified.Constructs a newPoint3Dat the geometric mean of this point and the given point.voidrotateX(double angle) Rotates this object clockwise around the x axis.voidrotateY(double angle) Rotates this object clockwise around the y axis.voidrotateZ(double angle) Rotates this object clockwise around the z axis.voidset(double x, double y, double z) Sets the x, y and z coordinates of this point.voidSets this points coordinates by adding the given vector to the given point.voidsetX(double x) Sets the x coordinate.voidsetY(double y) Sets the y coordinate.voidsetZ(double z) Sets the z coordinate.voidshow()InvokesSystem.out.println(this).toString()toStringBrief(int ndigits) Constructs a newVector3Dusing this points x, y, and z coordinates.voidtranslateXYZ(double x, double y, double z) Translates this object linearly by the amounts specified.vectorFrom(double x, double y, double z) Constructs a newVector3Dpoint from the point at the given coordinates to this point (this.x-x, this.y-y, this.z-z)vectorFrom(Point3D point) Constructs a newVector3Dpointing from the given point to this point (equivalent to (this.x-point.x, this.y-point.y, this.z-point.z).vectorTo(double x, double y, double z) Constructs a newVector3Dpoint from this point to the point at the given coordinates (x-this.x, y-this.y, z-this.z)).Constructs a newVector3Dpointing from this point to the given point (equivalent to (point.x-this.x, point.y-this.y, point.z-this.z)).doublex()Returns the x coordinate.doubley()Returns the y coordinate.doublez()Returns the z coordinate.
-
Constructor Details
-
Point3D
public Point3D()Constructs a newPoint3Dat (0, 0, 0). -
Point3D
public Point3D(double x, double y, double z) Constructs a newPoint3Dat (x, y, z).- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate
-
Point3D
Constructs a newPoint3Dwith the given vector.- Parameters:
v- the vector
-
Point3D
Constructs a newPoint3Dby adding the given vector to the given point.- Parameters:
point- the origin pointvector- the direction vector
-
Point3D
Constructs a newPoint3Dby copying the x, y, and z coordinates of the given point.- Parameters:
point- the point to copy
-
-
Method Details
-
copy
Sets the components of this point to be equal the components of the given point.- Parameters:
point- the point to copy
-
set
Sets this points coordinates by adding the given vector to the given point.- Parameters:
point- the origin pointvector- the direction vector
-
set
public void set(double x, double y, double z) Sets the x, y and z coordinates of this point.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate
-
setX
public void setX(double x) Sets the x coordinate.- Parameters:
x- the x coordinate
-
setY
public void setY(double y) Sets the y coordinate.- Parameters:
y- the y coordinate
-
setZ
public void setZ(double z) Sets the z coordinate.- Parameters:
z- the z coordinate
-
x
public double x()Returns the x coordinate.- Returns:
- the x coordinate
-
y
public double y()Returns the y coordinate.- Returns:
- the y coordinate
-
z
public double z()Returns the z coordinate.- Returns:
- the z coordinate
-
distance
Returns the distance between this point and the given point.- Parameters:
point- the point to calculate the distance from this point to- Returns:
- the distance between the points
-
distance
public double distance(double x, double y, double z) Returns the distance between this point and the point at the given coordinate.- Parameters:
x- the x coordinate of the given pointy- the y coordinate of the given pointz- the z coordinate of the given point- Returns:
- the distance between the points
-
midpoint
Constructs a newPoint3Dat the geometric mean of this point and the given point. This function behaves identically to lerp(point, 0.5).- Parameters:
point- the other point- Returns:
- a point at the geometric mean of the two given points
-
lerp
Constructs a newPoint3Dbetween this point and the given point by linearly interpolating from this point to the given point by the amount specified.- If t==0, then the returned point is equal to this point.
- If t==0.5, then the returned point is half way between both points.
- If t==1, then the returned point is equal to the given point.
- Parameters:
point- the point to interpolate betweent- the interpolation coefficient- Returns:
- the newly constructed point
-
combine
Combines this point with the given point. The position of this point will move to the geometric mean (midpoint) of the the two points.- Parameters:
point- the point used to calculate the geometric mean
-
vectorFrom
Constructs a newVector3Dpointing from the given point to this point (equivalent to (this.x-point.x, this.y-point.y, this.z-point.z).- Parameters:
point- the given point- Returns:
- the direction vector from the given point to this point
-
vectorFrom
Constructs a newVector3Dpoint from the point at the given coordinates to this point (this.x-x, this.y-y, this.z-z)- Parameters:
x- the x coordinate of the given pointy- the y coordinate of the given pointz- the z coordinate of the given point- Returns:
- the direction vector from the given point to this point
-
vectorTo
Constructs a newVector3Dpointing from this point to the given point (equivalent to (point.x-this.x, point.y-this.y, point.z-this.z)).- Parameters:
point- the given point- Returns:
- the direction vector from this point to the given
-
vectorTo
Constructs a newVector3Dpoint from this point to the point at the given coordinates (x-this.x, y-this.y, z-this.z)).- Parameters:
x- the x coordinate of the given pointy- the y coordinate of the given pointz- the z coordinate of the given point- Returns:
- the direction vector from this point to the given
-
toVector3D
Constructs a newVector3Dusing this points x, y, and z coordinates.- Returns:
- a vector representation of this point
-
translateXYZ
public void translateXYZ(double x, double y, double z) Description copied from interface:TransformableTranslates this object linearly by the amounts specified.- Specified by:
translateXYZin interfaceTransformable- Parameters:
x- amount to translate along the x axisy- amount to translate along the y axisz- amount to translate along the z axis
-
rotateX
public void rotateX(double angle) Description copied from interface:TransformableRotates this object clockwise around the x axis.- Specified by:
rotateXin interfaceTransformable- Parameters:
angle- rotation angle in radians
-
rotateY
public void rotateY(double angle) Description copied from interface:TransformableRotates this object clockwise around the y axis.- Specified by:
rotateYin interfaceTransformable- Parameters:
angle- rotation angle in radians
-
rotateZ
public void rotateZ(double angle) Description copied from interface:TransformableRotates this object clockwise around the z axis.- Specified by:
rotateZin interfaceTransformable- Parameters:
angle- rotation angle in radians
-
average
Constructs a newPoint3Dat the geometric mean of the given points.- Parameters:
points- the points to average- Returns:
- the geometric mean of the points
-
average
Constructs a newPoint3Dat the geometric mean of the given points.- Parameters:
points- the points to average- Returns:
- the geometric mean of the points
-
show
public void show()InvokesSystem.out.println(this). -
toString
-
toStringBrief
-
toStringBrief
-