java.lang.Object
imagingbook.common.geometry.line.AlgebraicLine
- All Implemented Interfaces:
Primitive2d
,ShapeProducer
- Direct Known Subclasses:
HessianLine
,SlopeInterceptLine
This class represents an algebraic line of the form A x + B y + C = 0. Instances are immutable and normalized such that ||(A,B)|| = 1. See Sec. 10.1 and Appendix F.1 of [1] for details.
[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).
- Version:
- 2022/11/18
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAlgebraicLine
(double[] p) Constructor.AlgebraicLine
(double A, double B, double C) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
equals
(AlgebraicLine other, double tolerance) Checks if thisAlgebraicLine
is equal to anotherAlgebraicLine
.boolean
static AlgebraicLine
from
(double[] s, double[] v) Creates a newAlgebraicLine
instance from a given start point and orientation vector.static AlgebraicLine
Creates a newAlgebraicLine
instance from two given points.static AlgebraicLine
from
(ParametricLine pl) Creates a newAlgebraicLine
instance from a givenParametricLine
.static AlgebraicLine
from
(SlopeInterceptLine sil) Creates a newAlgebraicLine
instance from a givenSlopeInterceptLine
.Returns the point on the line that is closest to the specified 2D point.double
getDistance
(double x, double y) Returns the orthogonal distance between this line and the point (x, y).double
getDistance
(Pnt2d p) Returns the orthogonal (unsigned) distance between this line and the point p.final double[]
Returns the algebraic line parameters [A, B, C].getShape
(double length) Returns a scaledShape
for this object (default scale is 1).getShape
(int width, int height) Returns aShape
for this line to be drawn in a canvas of the specified size.double
getSignedDistance
(double x, double y) Returns the orthogonal (signed) distance between this line and the point (x, y).double
Returns the orthogonal (signed) distance between this line and the specified point.double
getSquareError
(Pnt2d[] points) Calculates the sum of squared distances between this line and a given array of 2D points.double
getXref()
Returns the x-coordinate of the reference point.double
getYref()
Returns the y-coordinate of the reference point.Finds the intersection point between this line and anotherAlgebraicLine
.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface imagingbook.common.geometry.shape.ShapeProducer
getShape, getShapes, getShapes
-
Field Details
-
A
-
B
-
C
-
-
Constructor Details
-
AlgebraicLine
Constructor. Creates aAlgebraicLine
instance with parameters A, B, C.- Parameters:
A
- line parameter AB
- line parameter BC
- line parameter C
-
AlgebraicLine
Constructor. Creates aAlgebraicLine
instance from a parameter vector [A, B, C].- Parameters:
p
- parameter vector [A, B, C]
-
-
Method Details
-
from
Creates a newAlgebraicLine
instance from a given start point and orientation vector. For a point on the left side of the line (looking along the direction vector), the value returned bygetSignedDistance(Pnt2d)
is positive and negative for points on the right side.- Parameters:
s
- start pointv
- orientation vector- Returns:
- a new
AlgebraicLine
instance
-
from
Creates a newAlgebraicLine
instance from a givenParametricLine
.- Parameters:
pl
- aParametricLine
- Returns:
- a new
AlgebraicLine
instance
-
from
Creates a newAlgebraicLine
instance from two given points. The direction of the line is from the first to the second point.- Parameters:
p0
- first pointp1
- second point- Returns:
- a new
AlgebraicLine
instance
-
from
Creates a newAlgebraicLine
instance from a givenSlopeInterceptLine
. Note: This is trivial, sinceSlopeInterceptLine
is a (restricted)AlgebraicLine
itself.- Parameters:
sil
- aSlopeInterceptLine
- Returns:
- a new
AlgebraicLine
instance
-
getParameters
Returns the algebraic line parameters [A, B, C].- Returns:
- algebraic line parameters
-
getXref
Returns the x-coordinate of the reference point. For aAlgebraicLine
, the result is always zero. Inheriting classes (likeHoughLine
) override this method.- Returns:
- the x-coordinate reference
-
getYref
Returns the y-coordinate of the reference point. For aAlgebraicLine
, the result is always zero. Inheriting classes (likeHoughLine
) override this method.- Returns:
- the y-coordinate reference
-
getDistance
Returns the orthogonal distance between this line and the point (x, y). The result may be positive or negative, depending on which side of the line (x, y) is located. It is assumed that the line is normalized, i.e., ||(a,b)|| = 1.- Parameters:
x
- x-coordinate of point position.y
- y-coordinate of point position.- Returns:
- The perpendicular distance between this line and the point (x, y).
-
getDistance
Returns the orthogonal (unsigned) distance between this line and the point p. The result is always non-negative.- Specified by:
getDistance
in interfacePrimitive2d
- Parameters:
p
- point position.- Returns:
- The perpendicular distance between this line and the point p.
-
getSignedDistance
Returns the orthogonal (signed) distance between this line and the point (x, y). The result may be positive or negative, depending on which side of the line (x, y) is located. It is assumed that the line is normalized, i.e., ||(A,B)|| = 1.- Parameters:
x
- x-coordinate of point position.y
- y-coordinate of point position.- Returns:
- The perpendicular distance between this line and the point (x, y).
-
getSignedDistance
Returns the orthogonal (signed) distance between this line and the specified point. The result may be positive or negative, depending on which side of the line (the point is located. It is assumed that the line is normalized, i.e., ||(A,B)|| = 1.- Parameters:
p
- a 2D point- Returns:
- The perpendicular distance between this line and the point
-
getClosestLinePoint
Returns the point on the line that is closest to the specified 2D point. The line is assumed to be normalized.- Parameters:
p
- an arbitrary 2D point- Returns:
- the closest line point
-
getSquareError
Calculates the sum of squared distances between this line and a given array of 2D points.- Parameters:
points
- an array of points- Returns:
- the sum of squared distances
-
intersect
Finds the intersection point between this line and anotherAlgebraicLine
. Returnsnull
if the two lines are parallel.- Parameters:
l2
- anotherAlgebraicLine
- Returns:
- the intersection point or
null
if lines are parallel
-
getShape
Description copied from interface:ShapeProducer
Returns a scaledShape
for this object (default scale is 1). Must be defined by implementing classes. The interpretation of the scale factor is left to the implementing class. For example, forPnt2d
it specifies the size of the marker (seePnt2d.getShape(double)
.- Specified by:
getShape
in interfaceShapeProducer
- Parameters:
length
- the scale of the shape- Returns:
- a
Shape
instance
-
getShape
Returns aShape
for this line to be drawn in a canvas of the specified size. Since an algebraic line is of infinite extent, we need to know the drawing size. The returned line segment is sufficiently long to cover the entire canvas, i.e., both end points are outside the canvas.- Parameters:
width
- the width of the drawing canvasheight
- the height of the drawing canvas- Returns:
- a
Shape
instance for this line
-
equals
-
equals
Checks if thisAlgebraicLine
is equal to anotherAlgebraicLine
.- Parameters:
other
- anotherAlgebraicLine
tolerance
- the maximum deviation- Returns:
- true if both lines are equal
-
toString
-