Class Line

java.lang.Object
cnuphys.adaptiveSwim.geometry.Line

public class Line extends Object
3D line of the form p(t) = po + t*dp where p(t) is a point on the line, po is one point and dp = (p1-po) where p1 is another point. If this is an infinite line, the t = [-infinity, infinity]. If this is a directed segment, t = [0, 1]
Author:
heddle
  • Constructor Summary

    Constructors
    Constructor
    Description
    Line(double[] p1, double[] p2)
    Create a line from two ponts passed as arrays
    Line(Line line)
    Copy constructor
    Line(Point po, Point p1)
    Create a line from two points on the line.
    Create a line from the origing in the direction of a vector
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    distance(double x, double y, double z)
    Get the shortest distance between this line (as an infinite line) and a point
    double
    Get the shortest distance between this line (as an infinite line) and a point
    Get the center of the line
    Get the p1-po "dP" segment
    getEndpoint(int end)
    Get one of the endpoints
    getP(double t)
    Get a point on the line
    void
    getP(double t, Point p)
    Get a point on the line (in place)
    Get the po "start" point.
    Get the p1 "end" point.
    static void
    main(String[] arg)
     
    boolean
    Decide whether a point is on the line using the constant TINY as the max distance
    boolean
    pointOnLine(Point p, double maxDistance)
    Decide whether a point is on the line
    Get a String representation

    Methods inherited from class java.lang.Object

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

    • Line

      public Line(Point po, Point p1)
      Create a line from two points on the line. If this is a directed line segment, the line will go from po to p1.
      Parameters:
      po - one point
      p1 - the other point
    • Line

      public Line(double[] p1, double[] p2)
      Create a line from two ponts passed as arrays
      Parameters:
      p1 - one point as an xyz array
      p2 - another point as an xyz array
    • Line

      public Line(Line line)
      Copy constructor
      Parameters:
      line - the line to copy
    • Line

      public Line(Vector v)
      Create a line from the origing in the direction of a vector
      Parameters:
      v - the vector
  • Method Details

    • getP0

      public Point getP0()
      Get the po "start" point. This is just an arbitrary point on an infinite line, but the starting point if this is a directed line segment
      Returns:
      the "starting" point.
    • getDelP

      public Vector getDelP()
      Get the p1-po "dP" segment
      Returns:
      dP = p1 - po
    • getEndpoint

      public Point getEndpoint(int end)
      Get one of the endpoints
      Parameters:
      end - one of the Constants START or END
      Returns:
      the requested endpoint
    • getP1

      public Point getP1()
      Get the p1 "end" point. This is just an arbitrary point on an infinite line, but the end point if this is a directed line segment
      Returns:
      the "end" point.
    • getP

      public Point getP(double t)
      Get a point on the line
      Parameters:
      t - the t parameter. If this is a directed line segment, t should be restricted to [0, 1]
      Returns:
      a point on the line
    • getP

      public void getP(double t, Point p)
      Get a point on the line (in place)
      Parameters:
      t - the t parameter. If this is a directed line segment, t should be restricted to [0, 1]
      p - upon return, a point on the line
    • distance

      public double distance(Point p)
      Get the shortest distance between this line (as an infinite line) and a point
      Parameters:
      p - a point
      Returns:
      the perpendicular distance
    • distance

      public double distance(double x, double y, double z)
      Get the shortest distance between this line (as an infinite line) and a point
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      the perpendicular distance
    • pointOnLine

      public boolean pointOnLine(Point p, double maxDistance)
      Decide whether a point is on the line
      Parameters:
      p - the point
      maxDistance - the max distance it can be off the line and still considered on the line
      Returns:
      true if the point is considered on the line
    • pointOnLine

      public boolean pointOnLine(Point p)
      Decide whether a point is on the line using the constant TINY as the max distance
      Parameters:
      p - the point
      Returns:
      true if the point is considered on the line
    • toString

      public String toString()
      Get a String representation
      Overrides:
      toString in class Object
      Returns:
      a String representation of the Line
    • getCenter

      public Point getCenter()
      Get the center of the line
      Returns:
      the center of the line
    • main

      public static void main(String[] arg)