math.geom2d.line
Class StraightLine2D

java.lang.Object
  extended by math.geom2d.curve.AbstractContinuousCurve2D
      extended by math.geom2d.curve.AbstractSmoothCurve2D
          extended by math.geom2d.line.AbstractLine2D
              extended by math.geom2d.line.StraightLine2D
All Implemented Interfaces:
java.lang.Cloneable, CircleLine2D, CirculinearBoundary2D, CirculinearContinuousCurve2D, CirculinearContour2D, CirculinearCurve2D, CirculinearElement2D, CirculinearShape2D, ContinuousCurve2D, Curve2D, SmoothCurve2D, Boundary2D, ContinuousOrientedCurve2D, Contour2D, OrientedCurve2D, SmoothContour2D, SmoothOrientedCurve2D, GeometricObject2D, LinearElement2D, LinearShape2D, Shape2D

public class StraightLine2D
extends AbstractLine2D
implements SmoothContour2D, java.lang.Cloneable, CircleLine2D

Implementation of a straight line. Such a line can be constructed using two points, a point and a parallel line or straight object, or with coefficient of the Cartesian equation.


Field Summary
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
StraightLine2D()
          Empty constructor: a straight line corresponding to horizontal axis.
StraightLine2D(double a, double b, double c)
          Defines a new straight line, from the coefficients of the cartesian equation.
StraightLine2D(double xp, double yp, double dx, double dy)
          Defines a new Straight line going through the point (xp, yp) and with the direction dx, dy.
StraightLine2D(LinearShape2D line)
          Defines a new Straight line at the same position and with the same direction than an other straight object (line, edge or ray).
StraightLine2D(LinearShape2D line, Point2D point)
          Defines a new Straight line, parallel to another straigth object (ray, straight line or edge), and going through the given point.
StraightLine2D(Point2D point, double angle)
          Defines a new Straight line going through the given point, and with the specified direction given by angle.
StraightLine2D(Point2D point, double dx, double dy)
          Defines a new Straight line going through the given point, and with the specified direction vector.
StraightLine2D(Point2D point1, Point2D point2)
          Defines a new Straight line going through the two given points.
StraightLine2D(Point2D point, Vector2D direction)
          Defines a new Straight line going through the given point, and with the specified direction vector.
 
Method Summary
 boolean almostEquals(GeometricObject2D obj, double eps)
          Checks if the two objects are similar up to a given threshold value.
 java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
          Append the path of the curve to the given path.
 Polyline2D asPolyline(int n)
          Throws an exception when called.
 Box2D boundingBox()
          Returns the bounding box of the shape.
 StraightLine2D clone()
          Ensures public declaration of clone(), and ensures valid return type.
 boolean contains(double x, double y)
          Returns true if the point (x, y) lies on the line, with precision given by Shape2D.ACCURACY.
 boolean contains(Point2D p)
          Returns true if the point p lies on the line, with precision given by Shape2D.ACCURACY.
 java.util.Collection<? extends StraightLine2D> continuousCurves()
          Need to override to cast the type.
static StraightLine2D create(Point2D point, double angle)
          Deprecated. since 0.11.1
static StraightLine2D create(Point2D p1, Point2D p2)
          Deprecated. since 0.11.1
static StraightLine2D create(Point2D origin, Vector2D direction)
          Deprecated. since 0.11.1
static StraightLine2D createCartesian(double a, double b, double c)
          Returns a new Straight line, with the given coefficient of the cartesian equation (a*x + b*y + c = 0).
static StraightLine2D createHorizontal(Point2D origin)
          Creates a vertical straight line through the given point.
static StraightLine2D createMedian(Point2D p1, Point2D p2)
          Creates a median between 2 points.
static StraightLine2D createParallel(LinearShape2D linear, double d)
          Returns a new Straight line, parallel to another straight object (ray, straight line or edge), and going through the given point.
static StraightLine2D createParallel(LinearShape2D line, Point2D point)
          Returns a new Straight line, parallel to another straight object (ray, straight line or edge), and going through the given point.
static StraightLine2D createPerpendicular(LinearShape2D linear, Point2D point)
          Returns a new Straight line, perpendicular to a straight object (ray, straight line or edge), and going through the given point.
static StraightLine2D createVertical(Point2D origin)
          Creates a vertical straight line through the given point.
 double distance(double x, double y)
          Returns the distance of the point (x, y) to this straight line.
 CirculinearDomain2D domain()
          Returns the domain delimited by this boundary.
 boolean equals(java.lang.Object obj)
           
 void fill(java.awt.Graphics2D g2)
          Fills the interior of the boundary, using the Graphics current Paint.
 Point2D firstPoint()
          Throws an infiniteShapeException
 java.awt.geom.GeneralPath getGeneralPath()
          Throws an infiniteShapeException
static Point2D getIntersection(Point2D p1, Point2D p2, Point2D p3, Point2D p4)
          Computes the intersection point of the two (infinite) lines going through p1 and p2 for the first one, and p3 and p4 for the second one.
 double getT0()
          Deprecated. replaced by t0() (since 0.11.1).
 double getT1()
          Deprecated. replaced by t1() (since 0.11.1).
 boolean isBounded()
          Always returns false, because a line is not bounded.
 boolean isSingular(double pos)
          Returns false, whatever the position.
 Point2D lastPoint()
          Throws an infiniteShapeException
 StraightLine2D parallel(double d)
          Returns the parallel line located at a distance d from the line.
 StraightLine2D parallel(Point2D point)
          Returns a new Straight line, parallel to another straight object (ray, straight line or edge), and going through the given point.
 StraightLine2D perpendicular(Point2D point)
          Returns a new Straight line, parallel to another straight object (ray, straight line or edge), and going through the given point.
 Point2D point(double t)
          Returns the point specified with the parametric representation of the line.
 StraightLine2D reverse()
          Returns the straight line with same origin but with opposite direction vector.
 java.util.Collection<Point2D> singularPoints()
          Returns an empty list of points.
 double t0()
          Returns the parameter of the first point of the line, which is always Double.NEGATIVE_INFINITY.
 double t1()
          Returns the parameter of the last point of the line, which is always Double.POSITIVE_INFINITY.
 java.lang.String toString()
           
 StraightLine2D transform(AffineTransform2D trans)
          Returns the transformed line.
 CircleLine2D transform(CircleInversion2D inv)
          Transforms the shape by a circle inversion.
 double windingAngle(Point2D point)
          Return the angle portion that the curve turn around the given point.
 
Methods inherited from class math.geom2d.line.AbstractLine2D
buffer, cartesianEquation, clip, curvature, direction, distance, getIntersection, getSymmetric, getSymmetric, horizontalAngle, intersection, intersections, isClosed, isColinear, isColinear, isEmpty, isInside, isParallel, isParallel, length, length, origin, parametric, polarCoefficients, polarCoefficientsSigned, position, position, positionOnLine, positionOnLine, project, projectedPoint, projectedPoint, signedDistance, signedDistance, smoothPieces, subCurve, supportingLine, tangent
 
Methods inherited from class math.geom2d.curve.AbstractSmoothCurve2D
leftTangent, normal, rightTangent, vertices
 
Methods inherited from class math.geom2d.curve.AbstractContinuousCurve2D
asAwtShape, draw
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface math.geom2d.circulinear.CirculinearElement2D
clip, subCurve
 
Methods inherited from interface math.geom2d.circulinear.CirculinearContinuousCurve2D
smoothPieces
 
Methods inherited from interface math.geom2d.circulinear.CirculinearCurve2D
length, length, position
 
Methods inherited from interface math.geom2d.circulinear.CirculinearShape2D
buffer
 
Methods inherited from interface math.geom2d.curve.SmoothCurve2D
normal, tangent
 
Methods inherited from interface math.geom2d.domain.Boundary2D
isInside
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
curvature, isClosed, leftTangent, rightTangent
 
Methods inherited from interface math.geom2d.domain.OrientedCurve2D
signedDistance, signedDistance
 
Methods inherited from interface math.geom2d.curve.Curve2D
asAwtShape, draw, intersections, position, project, vertices
 
Methods inherited from interface math.geom2d.Shape2D
distance, isEmpty
 

Constructor Detail

StraightLine2D

public StraightLine2D()
Empty constructor: a straight line corresponding to horizontal axis.


StraightLine2D

public StraightLine2D(Point2D point1,
                      Point2D point2)
Defines a new Straight line going through the two given points.


StraightLine2D

public StraightLine2D(Point2D point,
                      Vector2D direction)
Defines a new Straight line going through the given point, and with the specified direction vector.


StraightLine2D

public StraightLine2D(Point2D point,
                      double dx,
                      double dy)
Defines a new Straight line going through the given point, and with the specified direction vector.


StraightLine2D

public StraightLine2D(Point2D point,
                      double angle)
Defines a new Straight line going through the given point, and with the specified direction given by angle.


StraightLine2D

public StraightLine2D(LinearShape2D line)
Defines a new Straight line at the same position and with the same direction than an other straight object (line, edge or ray).


StraightLine2D

public StraightLine2D(double xp,
                      double yp,
                      double dx,
                      double dy)
Defines a new Straight line going through the point (xp, yp) and with the direction dx, dy.


StraightLine2D

public StraightLine2D(LinearShape2D line,
                      Point2D point)
Defines a new Straight line, parallel to another straigth object (ray, straight line or edge), and going through the given point.


StraightLine2D

public StraightLine2D(double a,
                      double b,
                      double c)
Defines a new straight line, from the coefficients of the cartesian equation. The starting point of the line is then the point of the line closest to the origin, and the direction vector has unit norm.

Method Detail

create

@Deprecated
public static StraightLine2D create(Point2D point,
                                               double angle)
Deprecated. since 0.11.1

Creates a straight line going through a point and with a given angle.


create

@Deprecated
public static StraightLine2D create(Point2D p1,
                                               Point2D p2)
Deprecated. since 0.11.1

Creates a straight line through 2 points.


create

@Deprecated
public static StraightLine2D create(Point2D origin,
                                               Vector2D direction)
Deprecated. since 0.11.1

Creates a straight line through a point and with a given direction vector.


createHorizontal

public static StraightLine2D createHorizontal(Point2D origin)
Creates a vertical straight line through the given point.

Since:
0.10.3

createVertical

public static StraightLine2D createVertical(Point2D origin)
Creates a vertical straight line through the given point.

Since:
0.10.3

createMedian

public static StraightLine2D createMedian(Point2D p1,
                                          Point2D p2)
Creates a median between 2 points.

Parameters:
p1 - one point
p2 - another point
Returns:
the median of points p1 and p2
Since:
0.6.3

createParallel

public static StraightLine2D createParallel(LinearShape2D line,
                                            Point2D point)
Returns a new Straight line, parallel to another straight object (ray, straight line or edge), and going through the given point.

Since:
0.6.3

createParallel

public static StraightLine2D createParallel(LinearShape2D linear,
                                            double d)
Returns a new Straight line, parallel to another straight object (ray, straight line or edge), and going through the given point.

Since:
0.6.3

createPerpendicular

public static StraightLine2D createPerpendicular(LinearShape2D linear,
                                                 Point2D point)
Returns a new Straight line, perpendicular to a straight object (ray, straight line or edge), and going through the given point.

Since:
0.6.3

createCartesian

public static StraightLine2D createCartesian(double a,
                                             double b,
                                             double c)
Returns a new Straight line, with the given coefficient of the cartesian equation (a*x + b*y + c = 0).


getIntersection

public static Point2D getIntersection(Point2D p1,
                                      Point2D p2,
                                      Point2D p3,
                                      Point2D p4)
Computes the intersection point of the two (infinite) lines going through p1 and p2 for the first one, and p3 and p4 for the second one. Returns null if two lines are parallel.


parallel

public StraightLine2D parallel(Point2D point)
Returns a new Straight line, parallel to another straight object (ray, straight line or edge), and going through the given point.

Overrides:
parallel in class AbstractLine2D
Parameters:
point - the point to go through
Returns:
the parallel through the point

parallel

public StraightLine2D parallel(double d)
Returns the parallel line located at a distance d from the line. Distance is positive in the 'right' side of the line (outside of the limiting half-plane), and negative in the 'left' of the line.

Specified by:
parallel in interface CircleLine2D
Specified by:
parallel in interface CirculinearBoundary2D
Specified by:
parallel in interface CirculinearContinuousCurve2D
Specified by:
parallel in interface CirculinearContour2D
Specified by:
parallel in interface CirculinearCurve2D
Specified by:
parallel in interface CirculinearElement2D
Parameters:
d - the distance between the original curve and he parallel curve.
Returns:
the parallel curve
Throws:
DegeneratedLine2DException - if line direction vector is null

perpendicular

public StraightLine2D perpendicular(Point2D point)
Returns a new Straight line, parallel to another straight object (ray, straight line or edge), and going through the given point.

Overrides:
perpendicular in class AbstractLine2D
Parameters:
point - the point to go through
Returns:
the perpendicular through the point

transform

public CircleLine2D transform(CircleInversion2D inv)
Description copied from interface: CirculinearShape2D
Transforms the shape by a circle inversion. The result is still an instance a CirculinearShape2D.

Specified by:
transform in interface CircleLine2D
Specified by:
transform in interface CirculinearBoundary2D
Specified by:
transform in interface CirculinearContinuousCurve2D
Specified by:
transform in interface CirculinearContour2D
Specified by:
transform in interface CirculinearCurve2D
Specified by:
transform in interface CirculinearElement2D
Specified by:
transform in interface CirculinearShape2D
Overrides:
transform in class AbstractLine2D
Parameters:
inv - the circle inversion
Returns:
the transformed shape

domain

public CirculinearDomain2D domain()
Description copied from interface: Boundary2D
Returns the domain delimited by this boundary.

Specified by:
domain in interface CirculinearBoundary2D
Specified by:
domain in interface Boundary2D
Returns:
the domain delimited by this boundary

fill

public void fill(java.awt.Graphics2D g2)
Description copied from interface: Boundary2D
Fills the interior of the boundary, using the Graphics current Paint.

Specified by:
fill in interface Boundary2D
Parameters:
g2 - the Graphics to fill on

windingAngle

public double windingAngle(Point2D point)
Description copied from interface: OrientedCurve2D
Return the angle portion that the curve turn around the given point. Result is a signed angle.

Specified by:
windingAngle in interface OrientedCurve2D
Overrides:
windingAngle in class AbstractLine2D
Parameters:
point - a point of the plane
Returns:
a signed angle

asPolyline

public Polyline2D asPolyline(int n)
Throws an exception when called.

Specified by:
asPolyline in interface ContinuousCurve2D
Overrides:
asPolyline in class AbstractContinuousCurve2D
Parameters:
n - the number of line segments
Returns:
a polyline with n line segments.
See Also:
ContinuousCurve2D.asPolyline(int)

firstPoint

public Point2D firstPoint()
Throws an infiniteShapeException

Specified by:
firstPoint in interface Curve2D
Overrides:
firstPoint in class AbstractContinuousCurve2D
Returns:
the first point of the curve
See Also:
Curve2D.t0(), Curve2D.point(double)

lastPoint

public Point2D lastPoint()
Throws an infiniteShapeException

Specified by:
lastPoint in interface Curve2D
Overrides:
lastPoint in class AbstractContinuousCurve2D
Returns:
the last point of the curve.
See Also:
Curve2D.t1(), Curve2D.point(double)

singularPoints

public java.util.Collection<Point2D> singularPoints()
Returns an empty list of points.

Specified by:
singularPoints in interface Curve2D
Overrides:
singularPoints in class AbstractSmoothCurve2D
Returns:
a collection of Point2D.
See Also:
Curve2D.singularPoints()

isSingular

public boolean isSingular(double pos)
Returns false, whatever the position.

Specified by:
isSingular in interface Curve2D
Overrides:
isSingular in class AbstractSmoothCurve2D
Parameters:
pos - the position of the point on the curve
Returns:
true if the point at this location is singular
See Also:
Curve2D.isSingular(double)

t0

public double t0()
Returns the parameter of the first point of the line, which is always Double.NEGATIVE_INFINITY.

Specified by:
t0 in interface Curve2D

getT0

@Deprecated
public double getT0()
Deprecated. replaced by t0() (since 0.11.1).

Specified by:
getT0 in interface Curve2D

t1

public double t1()
Returns the parameter of the last point of the line, which is always Double.POSITIVE_INFINITY.

Specified by:
t1 in interface Curve2D

getT1

@Deprecated
public double getT1()
Deprecated. replaced by t1() (since 0.11.1).

Specified by:
getT1 in interface Curve2D

point

public Point2D point(double t)
Returns the point specified with the parametric representation of the line.

Specified by:
point in interface Curve2D

continuousCurves

public java.util.Collection<? extends StraightLine2D> continuousCurves()
Need to override to cast the type.

Specified by:
continuousCurves in interface CirculinearBoundary2D
Specified by:
continuousCurves in interface CirculinearCurve2D
Specified by:
continuousCurves in interface Curve2D
Specified by:
continuousCurves in interface Boundary2D
Overrides:
continuousCurves in class AbstractLine2D
Returns:
a collection of continuous curves.

reverse

public StraightLine2D reverse()
Returns the straight line with same origin but with opposite direction vector.

Specified by:
reverse in interface CircleLine2D
Specified by:
reverse in interface CirculinearBoundary2D
Specified by:
reverse in interface CirculinearContinuousCurve2D
Specified by:
reverse in interface CirculinearContour2D
Specified by:
reverse in interface CirculinearCurve2D
Specified by:
reverse in interface CirculinearElement2D
Specified by:
reverse in interface ContinuousCurve2D
Specified by:
reverse in interface Curve2D
Specified by:
reverse in interface SmoothCurve2D
Specified by:
reverse in interface Boundary2D
Specified by:
reverse in interface ContinuousOrientedCurve2D
Specified by:
reverse in interface Contour2D
Specified by:
reverse in interface OrientedCurve2D
Specified by:
reverse in interface SmoothContour2D
Specified by:
reverse in interface SmoothOrientedCurve2D

appendPath

public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
Description copied from interface: ContinuousCurve2D
Append the path of the curve to the given path.

Specified by:
appendPath in interface ContinuousCurve2D
Parameters:
path - a path to modify
Returns:
the modified path

isBounded

public boolean isBounded()
Always returns false, because a line is not bounded.

Specified by:
isBounded in interface Shape2D

distance

public double distance(double x,
                       double y)
Returns the distance of the point (x, y) to this straight line.

Specified by:
distance in interface Shape2D
Overrides:
distance in class AbstractLine2D
Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
Returns:
distance between this object and the point (x,y)

boundingBox

public Box2D boundingBox()
Description copied from interface: Shape2D
Returns the bounding box of the shape.

Specified by:
boundingBox in interface Shape2D
Returns:
the bounding box of the shape.

transform

public StraightLine2D transform(AffineTransform2D trans)
Returns the transformed line. The result is still a StraightLine2D.

Specified by:
transform in interface ContinuousCurve2D
Specified by:
transform in interface Curve2D
Specified by:
transform in interface SmoothCurve2D
Specified by:
transform in interface Boundary2D
Specified by:
transform in interface ContinuousOrientedCurve2D
Specified by:
transform in interface Contour2D
Specified by:
transform in interface OrientedCurve2D
Specified by:
transform in interface SmoothContour2D
Specified by:
transform in interface SmoothOrientedCurve2D
Specified by:
transform in interface LinearElement2D
Specified by:
transform in interface LinearShape2D
Specified by:
transform in interface Shape2D
Specified by:
transform in class AbstractLine2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

contains

public boolean contains(double x,
                        double y)
Returns true if the point (x, y) lies on the line, with precision given by Shape2D.ACCURACY.

Specified by:
contains in interface Shape2D

contains

public boolean contains(Point2D p)
Returns true if the point p lies on the line, with precision given by Shape2D.ACCURACY.

Specified by:
contains in interface Shape2D
Overrides:
contains in class AbstractLine2D

getGeneralPath

public java.awt.geom.GeneralPath getGeneralPath()
Throws an infiniteShapeException


almostEquals

public boolean almostEquals(GeometricObject2D obj,
                            double eps)
Description copied from interface: GeometricObject2D
Checks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.

Specified by:
almostEquals in interface GeometricObject2D
Parameters:
obj - the object to compare
eps - a threshold value, for example the minimal coordinate difference
Returns:
true if both object have the same value up to the threshold

toString

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

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

clone

public StraightLine2D clone()
Description copied from class: AbstractLine2D
Ensures public declaration of clone(), and ensures valid return type.

Specified by:
clone in interface Curve2D
Specified by:
clone in class AbstractLine2D
Returns:
the cloned curve