Class LineSegment3d

    • Field Detail

      • startX

        public final double startX
        The start x-coordinate.
      • startY

        public final double startY
        The start y-coordinate.
      • startZ

        public final double startZ
        The start z-coordinate.
      • endX

        public final double endX
        The end x-coordinate.
      • endY

        public final double endY
        The end y-coordinate.
      • endZ

        public final double endZ
        The end z-coordinate.
    • Constructor Detail

      • LineSegment3d

        public LineSegment3d​(double startX,
                             double startY,
                             double startZ,
                             double endX,
                             double endY,
                             double endZ)
                      throws DrawRuntimeException
        Construct a new LineSegment3d start six coordinates.
        Parameters:
        startX - double; the x-coordinate of the start point
        startY - double; the y-coordinate of the start point
        startZ - double; the z-coordinate of the start point
        endX - double; the x-coordinate of the end point
        endY - double; the y-coordinate of the end point
        endZ - double; the z-coordinate of the end point
        Throws:
        DrawRuntimeException - when (startX,startY) is equals end (endX,endY)
      • LineSegment3d

        public LineSegment3d​(Point3d start,
                             double endX,
                             double endY,
                             double endZ)
                      throws NullPointerException,
                             DrawRuntimeException
        Construct a new LineSegment3d start a Point3d and three coordinates.
        Parameters:
        start - Point3d; the start point
        endX - double; the x-coordinate of the end point
        endY - double; the y-coordinate of the end point
        endZ - double; the z-coordinate of the end point
        Throws:
        NullPointerException - when start is null
        DrawRuntimeException - when start has the exact coordinates endX, endY
      • LineSegment3d

        public LineSegment3d​(double startX,
                             double startY,
                             double startZ,
                             Point3d end)
                      throws NullPointerException,
                             DrawRuntimeException
        Construct a new LineSegment3d start three coordinates and a Point3d.
        Parameters:
        startX - double; the x-coordinate of the start point
        startY - double; the y-coordinate of the start point
        startZ - double; the z-coordinate of the start point
        end - Point3d; the end point
        Throws:
        NullPointerException - when end is null
        DrawRuntimeException - when end has the exact coordinates startX, startY
    • Method Detail

      • getLength

        public double getLength()
        Get the length (distance from start point to end point) of this LineSegment.
        Specified by:
        getLength in interface LineSegment<Point3d,​Ray3d,​Space3d>
        Returns:
        double; (distance from start point to end point) of this LineSegment
      • getPoints

        public Iterator<? extends Point3d> getPoints()
        Retrieve, or generate all points that make up the object.
        Specified by:
        getPoints in interface Drawable<Point3d,​Space3d>
        Returns:
        Iterable<Point2d>; an iterator that generates all points that make up the object
      • size

        public int size()
        Retrieve the number of points that make up the object.
        Specified by:
        size in interface Drawable<Point3d,​Space3d>
        Returns:
        int; the number of points that make up the object
      • getBounds

        public Bounds3d getBounds()
        Retrieve the bounding box of the object.
        Specified by:
        getBounds in interface Drawable3d
        Returns:
        Bounds3d; the bounding box of the object
      • project

        public LineSegment2d project()
                              throws DrawRuntimeException
        Project the object onto the z=0 plane.
        Specified by:
        project in interface Drawable3d
        Returns:
        Drawable2d; the projected object
        Throws:
        DrawRuntimeException - when projecting onto the z=0 plane results in an invalid object. E.g. a Line3d that consists of points that all have the exact same x and y coordinates cannot be a line after projecting on the z=0 plane.
      • closestPointOnSegment

        public Point3d closestPointOnSegment​(Point3d point)
        Project a Point on this LineSegment. If the the projected points lies outside the line segment, the nearest end point of the line segment is returned. Otherwise the returned point lies between the end points of the line segment.
        Adapted from example code provided by Paul Bourke.
        Specified by:
        closestPointOnSegment in interface LineSegment<Point3d,​Ray3d,​Space3d>
        Parameters:
        point - P; the point to project onto the segment
        Returns:
        P; either the start point, or the end point of the segment or a Point2d that lies somewhere in between those two.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object