Package edu.cnu.mdi.geometry
Class Point
java.lang.Object
edu.cnu.mdi.geometry.Point
- Direct Known Subclasses:
Vector
A mutable point in three-dimensional Cartesian space.
The coordinates are public for lightweight geometry use and for compatibility
with existing MDI code. The same class is also used in places where a tuple is
naturally treated as a vector, for example in dot products, subtraction, and
scaling. For operations that should explicitly represent a direction rather
than a location, use Vector.
- Author:
- heddle
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds another point or vector to this point, coordinate by coordinate.static Pointdifference(Point a, Point b) Computes the coordinate-wise differencea - b.static voiddifference(Point a, Point b, Point c) Computes the coordinate-wise differencea - band stores it in an existing point.doubledistance(double x, double y, double z) Computes the Euclidean distance from this point to another set of coordinates.doubleComputes the Euclidean distance from this point to another point.static doubleComputes the Euclidean distance between two points.doubleComputes the dot product of this tuple with another tuple.static doubleComputes the dot product of two tuples.scale(double scalar) Multiplies this point's coordinates by a scalar.voidset(double x, double y, double z) Sets this point's coordinates.voidSets this point's coordinates from another point.Subtracts another point from this point.toString()Returns a formatted string representation of this point.
-
Field Details
-
x
public double xThe x coordinate. -
y
public double yThe y coordinate. -
z
public double zThe z coordinate.
-
-
Constructor Details
-
Point
public Point()Creates a point at the origin. -
Point
Creates a copy of another point.- Parameters:
p- the point to copy- Throws:
NullPointerException- ifpisnull
-
Point
public Point(double x, double y, double z) Creates a point from its Cartesian coordinates.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate
-
Point
public Point(double[] p) Creates a point from an array containingx,y, andz, in that order.- Parameters:
p- an array containing at least three values- Throws:
NullPointerException- ifpisnullIndexOutOfBoundsException- ifp.length < 3
-
-
Method Details
-
set
public void set(double x, double y, double z) Sets this point's coordinates.- Parameters:
x- the new x coordinatey- the new y coordinatez- the new z coordinate
-
set
Sets this point's coordinates from another point.- Parameters:
p- the point whose coordinates will be copied- Throws:
NullPointerException- ifpisnull
-
difference
Computes the coordinate-wise differencea - b.- Parameters:
a- the minuend pointb- the subtrahend point- Returns:
- a new point containing
a - b - Throws:
NullPointerException- if either argument isnull
-
subtract
Subtracts another point from this point.- Parameters:
other- the point to subtract- Returns:
- a new point containing
this - other - Throws:
NullPointerException- ifotherisnull
-
difference
Computes the coordinate-wise differencea - band stores it in an existing point.- Parameters:
a- the minuend pointb- the subtrahend pointc- upon return, containsa - b- Throws:
NullPointerException- if any argument isnull
-
dot
Computes the dot product of this tuple with another tuple.- Parameters:
v- the other point or vector- Returns:
this.x*v.x + this.y*v.y + this.z*v.z- Throws:
NullPointerException- ifvisnull
-
dot
Computes the dot product of two tuples.- Parameters:
a- one point or vectorb- the other point or vector- Returns:
a.x*b.x + a.y*b.y + a.z*b.z- Throws:
NullPointerException- if either argument isnull
-
toString
Returns a formatted string representation of this point. -
distance
public double distance(double x, double y, double z) Computes the Euclidean distance from this point to another set of coordinates.- Parameters:
x- the x coordinate of the other pointy- the y coordinate of the other pointz- the z coordinate of the other point- Returns:
- the Euclidean distance between the two points
-
distance
Computes the Euclidean distance from this point to another point.- Parameters:
p- the other point- Returns:
- the Euclidean distance between the points
- Throws:
NullPointerException- ifpisnull
-
distance
Computes the Euclidean distance between two points.- Parameters:
p1- one pointp2- the other point- Returns:
- the Euclidean distance between the two points
- Throws:
NullPointerException- if either argument isnull
-
add
Adds another point or vector to this point, coordinate by coordinate.- Parameters:
other- the point or vector to add- Returns:
- a new point containing
this + other - Throws:
NullPointerException- ifotherisnull
-
scale
Multiplies this point's coordinates by a scalar.- Parameters:
scalar- the scalar multiplier- Returns:
- a new point containing
scalar * this
-