maslab.geom
Class GLine2D

java.lang.Object
  extended by maslab.geom.GLine2D
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class GLine2D
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A 2D line

See Also:
Serialized Form

Constructor Summary
GLine2D()
           
GLine2D(double M, double b)
          Create a new line
GLine2D(double dx, double dy, GPoint2D p)
          Create a new line
GLine2D(GPoint2D p1, GPoint2D p2)
          Create a new line through two points.
 
Method Summary
static GLine2D fromRmatrix(Matrix R)
          Create a line from the vector from the origin to the line that is perpendicular to the line.
static GLine2D fromRTheta(double r, double theta)
          Create a new line given a distance and angle from the origin that is perpendicular to the line.
static GLine2D fromThetaPoint(double theta, GPoint2D p)
          Create a line that is at angle theta from the x axis and passes through point p
 double getB()
          Get the y intercept of the line
 double getLineCoordinate(GPoint2D p)
          Get the coordinate of a point (on this line), with 0 corresponding to the point on the line that is perpendicular to a line passing through the origin and the line.
 double getM()
          Get the slope of the line
 GPoint2D getPointOfCoordinate(double coord)
          The inverse of getLineCoordinate.
 Matrix getR()
          The 2x1 vector from the origin to the line that is perpendicular to the line.
 Matrix getU()
          The 2x1 unit vector corresponding to the slope of the line.
 GPoint2D intersectionWith(GLine2D l)
          Compute the point where two lines intersect, or null if the lines are parallel.
static void main(java.lang.String[] args)
          Self tests
 void optimize()
          Hint that the object should be optimized for future computation by putting the internal representation into a more convenient format.
 GLine2D parallelLineThrough(GPoint2D pin)
          Return a line parallel to this line that passes through the specified point.
 double perpendicularDistanceTo(GPoint2D pin)
          Compute the perpendicular distance between a point and the line
 GLine2D perpendicularLine()
          A line perpendicular to this line.
 GLine2D perpendicularLineThrough(GPoint2D pin)
          The line perpendicular to this line that passes through point p
 GPoint2D pointOnLineClosestTo(GPoint2D pin)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GLine2D

public GLine2D()

GLine2D

public GLine2D(double dx,
               double dy,
               GPoint2D p)
Create a new line

Parameters:
dx - A change in X corresponding to dy
dy - A change in Y corresponding to dx
p - A point that the line passes through

GLine2D

public GLine2D(double M,
               double b)
Create a new line

Parameters:
M - the slope
b - the y intercept

GLine2D

public GLine2D(GPoint2D p1,
               GPoint2D p2)
Create a new line through two points.

Method Detail

optimize

public void optimize()
Hint that the object should be optimized for future computation by putting the internal representation into a more convenient format. This never affects correctness, only performance.


getM

public double getM()
Get the slope of the line


getB

public double getB()
Get the y intercept of the line


getLineCoordinate

public double getLineCoordinate(GPoint2D p)
Get the coordinate of a point (on this line), with 0 corresponding to the point on the line that is perpendicular to a line passing through the origin and the line. This allows easy computation if one point is between two other points on the line: compute the line coordinate of all three points and test if a

getPointOfCoordinate

public GPoint2D getPointOfCoordinate(double coord)
The inverse of getLineCoordinate.


fromRmatrix

public static GLine2D fromRmatrix(Matrix R)
Create a line from the vector from the origin to the line that is perpendicular to the line.

Parameters:
R - a 2x1 matrix [x y]'

fromRTheta

public static GLine2D fromRTheta(double r,
                                 double theta)
Create a new line given a distance and angle from the origin that is perpendicular to the line.


fromThetaPoint

public static GLine2D fromThetaPoint(double theta,
                                     GPoint2D p)
Create a line that is at angle theta from the x axis and passes through point p


perpendicularLine

public GLine2D perpendicularLine()
A line perpendicular to this line.


getR

public Matrix getR()
The 2x1 vector from the origin to the line that is perpendicular to the line.


getU

public Matrix getU()
The 2x1 unit vector corresponding to the slope of the line.


perpendicularLineThrough

public GLine2D perpendicularLineThrough(GPoint2D pin)
The line perpendicular to this line that passes through point p


parallelLineThrough

public GLine2D parallelLineThrough(GPoint2D pin)
Return a line parallel to this line that passes through the specified point.


intersectionWith

public GPoint2D intersectionWith(GLine2D l)
Compute the point where two lines intersect, or null if the lines are parallel.


pointOnLineClosestTo

public GPoint2D pointOnLineClosestTo(GPoint2D pin)

perpendicularDistanceTo

public double perpendicularDistanceTo(GPoint2D pin)
Compute the perpendicular distance between a point and the line


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
Self tests