Class Point3D

Object
Point3D
All Implemented Interfaces:
Point
Direct Known Subclasses:
Node3D, Vector3D

public class Point3D extends Object implements Point
Class representing a point in 3D Cartesian space.
Author:
Christoph Hauert
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
    The x-coordinate of the point.
    double
    The y-coordinate of the point.
    double
    The z-coordinate of the point.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new 3D point with coordinates (0,0,0).
    Point3D(double x, double y, double z)
    Create a new 3D point with coordinates (x,y,z).
    Create a copy of the 3D point p.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Calculate distance from the origin (0,0,0): \(\sqrt{x^2+y^2+z^2}\).
    double
    Calculate the distance between the two 3D points p and q: \(\sqrt{(p.x-q.x)^2+(p.y-q.y)^2+(p.z-q.z)^2}\).
    double
    Calculate the distance squared from the origin (0,0,0): \(x^2+y^2+z^2\).
    double
    Calculate the distance squared between the two 3D points p and q: \((p.x-q.x)^2+(p.y-q.y)^2+(p.z-q.z)^2\).
    double
    Get the x-coordinate of this 3D point.
    double
    Get the y-coordinate of this 3D point.
    double
    Get the z-coordinate of this 3D point.
    scale(double s)
    Scale the coordinates of this 3D point by a factor s to (s*x,s*y,s*z).
    scale(double sx, double sy, double sz)
    Scale the coordinates of this 3D point by scalar factors sx, sy and sz, respectively, to (sx*x, sy*y, sz*z).
    set(double x, double y, double z)
    Set x-, y- and z-coordinates of the 3D point.
    Set x-, y- and z-coordinates of the point to those of the 3D point p.
    void
    setLocation(double x, double y, double z)
    Compatibility method (following Point2D.setLocation(double, double)).
    void
    Compatibility method (following Point2D.setLocation(Point2D p)).
    setX(double x)
    Set the x-coordinate of this 3D point.
    setY(double y)
    Set the y-coordinate of this 3D point.
    setZ(double z)
    Set the z-coordinate of this 3D point.
    shake(double quake)
    Randomly shake the position of this point by an amount scaled by quake.
    shift(double dx, double dy, double dz)
    Shift the 3D point by dx, dy, and dz in the x-, y-, and z-coordinates, respectively, to (x+p.x,y+p.y,z+p.z).
    Shift the 3D point by p.x, p.y, and p.z in the x-, y-, and z-coordinates, respectively, to (x+p.x,y+p.y,z+p.z).
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public double x
      The x-coordinate of the point.
    • y

      public double y
      The y-coordinate of the point.
    • z

      public double z
      The z-coordinate of the point.
  • Constructor Details

    • Point3D

      public Point3D()
      Create a new 3D point with coordinates (0,0,0).
    • Point3D

      public Point3D(Point3D p)
      Create a copy of the 3D point p.
      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 - the x-coordinate
      y - the y-coordinate
      z - the z-coordinate
  • Method Details

    • set

      public Point3D set(double x, double y, double z)
      Set x-, y- and z-coordinates of the 3D point.
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      z - the z-coordinate
      Returns:
      this point
    • set

      public Point3D set(Point3D p)
      Set x-, y- and z-coordinates of the point to those of the 3D point p.
      Parameters:
      p - the 3D point to copy coordinates from
      Returns:
      this point
    • setLocation

      public void setLocation(double x, double y, double z)
      Compatibility method (following Point2D.setLocation(double, double)).
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      z - the z-coordinate
    • setLocation

      public void setLocation(Point3D p)
      Compatibility method (following Point2D.setLocation(Point2D p)).
      Parameters:
      p - the 3D point to copy the position from
    • shift

      public Point3D shift(Point3D p)
      Shift the 3D point by p.x, p.y, and p.z in the x-, y-, and z-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

      public Point3D shift(double dx, double dy, double dz)
      Shift the 3D point by dx, dy, and dz in the x-, y-, and z-coordinates, respectively, to (x+p.x,y+p.y,z+p.z).
      Parameters:
      dx - the shift in the x-coordinate
      dy - the shift in the y-coordinate
      dz - the shift in the z-coordinate
      Returns:
      the shifted point
    • scale

      public Point3D scale(double s)
      Scale the coordinates of this 3D point by a factor s to (s*x,s*y,s*z).
      Parameters:
      s - the scaling factor
      Returns:
      the scaled point
    • scale

      public Point3D scale(double sx, double sy, double sz)
      Scale the coordinates of this 3D point by scalar factors sx, sy and sz, respectively, to (sx*x, sy*y, sz*z).
      Parameters:
      sx - the scaling of the x-coordinate
      sy - the scaling of the y-coordinate
      sz - the scaling of the z-coordinate
      Returns:
      the scaled point
    • shake

      public Point3D shake(double quake)
      Description copied from interface: Point
      Randomly shake the position of this point by an amount scaled by quake.
      Specified by:
      shake in interface Point
      Parameters:
      quake - the amount to shake the point
      Returns:
      this point to enable chains of manipulations
    • getX

      public double getX()
      Get the x-coordinate of this 3D point.
      Returns:
      the x-coordinate
    • setX

      public Point3D setX(double x)
      Set the x-coordinate of this 3D point.
      Parameters:
      x - the new x-coordinate
      Returns:
      this point
    • getY

      public double getY()
      Get the y-coordinate of this 3D point.
      Returns:
      the y-coordinate
    • setY

      public Point3D setY(double y)
      Set the y-coordinate of this 3D point.
      Parameters:
      y - the new y-coordinate
      Returns:
      this point
    • getZ

      public double getZ()
      Get the z-coordinate of this 3D point.
      Returns:
      the z-coordinate
    • setZ

      public Point3D setZ(double z)
      Set the z-coordinate of this 3D point.
      Parameters:
      z - the new z-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

      public double distance(Point3D q)
      Calculate the distance between the two 3D points p and q: \(\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

      public double distance2(Point3D q)
      Calculate the distance squared between the two 3D points p and q: \((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

      public String toString()
      Overrides:
      toString in class Object