Contents
- Description
- Constructor Summary
- Method Summary
- Constructor Details
- Method Details
- copy(Point3D)
- set(Point3D, Vector3D)
- set(double, double, double)
- setX(double)
- setY(double)
- setZ(double)
- x()
- y()
- z()
- distance(Point3D)
- distance(double, double, double)
- midpoint(Point3D)
- lerp(Point3D, double)
- combine(Point3D)
- vectorFrom(Point3D)
- vectorFrom(double, double, double)
- vectorTo(Point3D)
- vectorTo(double, double, double)
- toVector3D()
- translateXYZ(double, double, double)
- rotateX(double)
- rotateY(double)
- rotateZ(double)
- average(Point3D...)
- average(Collection)
- show()
- toString()
- toStringBrief(int)
- toStringBrief()
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 newPoint3D
at (0, 0, 0).Point3D
(double x, double y, double z) Constructs a newPoint3D
at (x, y, z).Constructs a newPoint3D
by copying the x, y, and z coordinates of the given point.Constructs a newPoint3D
by adding the given vector to the given point.Constructs a newPoint3D
with the given vector. -
Method Summary
Modifier and TypeMethodDescriptionstatic Point3D
average
(Collection<Point3D> points) Constructs a newPoint3D
at the geometric mean of the given points.static Point3D
Constructs a newPoint3D
at the geometric mean of the given points.void
Combines this point with the given point.void
Sets the components of this point to be equal the components of the given point.double
distance
(double x, double y, double z) Returns the distance between this point and the point at the given coordinate.double
Returns the distance between this point and the given point.Constructs a newPoint3D
between this point and the given point by linearly interpolating from this point to the given point by the amount specified.Constructs a newPoint3D
at the geometric mean of this point and the given point.void
rotateX
(double angle) Rotates this object clockwise around the x axis.void
rotateY
(double angle) Rotates this object clockwise around the y axis.void
rotateZ
(double angle) Rotates this object clockwise around the z axis.void
set
(double x, double y, double z) Sets the x, y and z coordinates of this point.void
Sets this points coordinates by adding the given vector to the given point.void
setX
(double x) Sets the x coordinate.void
setY
(double y) Sets the y coordinate.void
setZ
(double z) Sets the z coordinate.void
show()
InvokesSystem.out.println(this)
.toString()
toStringBrief
(int ndigits) Constructs a newVector3D
using this points x, y, and z coordinates.void
translateXYZ
(double x, double y, double z) Translates this object linearly by the amounts specified.vectorFrom
(double x, double y, double z) Constructs a newVector3D
point from the point at the given coordinates to this point (this.x-x, this.y-y, this.z-z)vectorFrom
(Point3D point) Constructs a newVector3D
pointing 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 newVector3D
point from this point to the point at the given coordinates (x-this.x, y-this.y, z-this.z)).Constructs a newVector3D
pointing from this point to the given point (equivalent to (point.x-this.x, point.y-this.y, point.z-this.z)).double
x()
Returns the x coordinate.double
y()
Returns the y coordinate.double
z()
Returns the z coordinate.
-
Constructor Details
-
Point3D
public Point3D()Constructs a newPoint3D
at (0, 0, 0). -
Point3D
public Point3D(double x, double y, double z) Constructs a newPoint3D
at (x, y, z).- Parameters:
x
- the x coordinatey
- the y coordinatez
- the z coordinate
-
Point3D
Constructs a newPoint3D
with the given vector.- Parameters:
v
- the vector
-
Point3D
-
Point3D
Constructs a newPoint3D
by 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
-
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
-
lerp
Constructs a newPoint3D
between 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
-
vectorFrom
Constructs a newVector3D
point 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
-
vectorTo
Constructs a newVector3D
point 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 newVector3D
using 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:Transformable
Translates this object linearly by the amounts specified.- Specified by:
translateXYZ
in 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:Transformable
Rotates this object clockwise around the x axis.- Specified by:
rotateX
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
rotateY
public void rotateY(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the y axis.- Specified by:
rotateY
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
rotateZ
public void rotateZ(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the z axis.- Specified by:
rotateZ
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
average
-
average
Constructs a newPoint3D
at the geometric mean of the given points.- Parameters:
points
- the points to average- Returns:
- the geometric mean of the points
-
show
-
toString
-
toStringBrief
-
toStringBrief
-