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 TypeMethodDescriptionbooleanequals(AlgebraicLine other, double tolerance) Checks if thisAlgebraicLineis equal to anotherAlgebraicLine.booleanstatic AlgebraicLinefrom(double[] s, double[] v) Creates a newAlgebraicLineinstance from a given start point and orientation vector.static AlgebraicLineCreates a newAlgebraicLineinstance from two given points.static AlgebraicLinefrom(ParametricLine pl) Creates a newAlgebraicLineinstance from a givenParametricLine.static AlgebraicLinefrom(SlopeInterceptLine sil) Creates a newAlgebraicLineinstance from a givenSlopeInterceptLine.Returns the point on the line that is closest to the specified 2D point.doublegetDistance(double x, double y) Returns the orthogonal distance between this line and the point (x, y).doublegetDistance(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 scaledShapefor this object (default scale is 1).getShape(int width, int height) Returns aShapefor this line to be drawn in a canvas of the specified size.doublegetSignedDistance(double x, double y) Returns the orthogonal (signed) distance between this line and the point (x, y).doubleReturns the orthogonal (signed) distance between this line and the specified point.doublegetSquareError(Pnt2d[] points) Calculates the sum of squared distances between this line and a given array of 2D points.doublegetXref()Returns the x-coordinate of the reference point.doublegetYref()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, waitMethods inherited from interface imagingbook.common.geometry.shape.ShapeProducer
getShape, getShapes, getShapes
-
Field Details
-
A
-
B
-
C
-
-
Constructor Details
-
AlgebraicLine
Constructor. Creates aAlgebraicLineinstance with parameters A, B, C.- Parameters:
A- line parameter AB- line parameter BC- line parameter C
-
AlgebraicLine
Constructor. Creates aAlgebraicLineinstance from a parameter vector [A, B, C].- Parameters:
p- parameter vector [A, B, C]
-
-
Method Details
-
from
Creates a newAlgebraicLineinstance 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
AlgebraicLineinstance
-
from
Creates a newAlgebraicLineinstance from a givenParametricLine.- Parameters:
pl- aParametricLine- Returns:
- a new
AlgebraicLineinstance
-
from
Creates a newAlgebraicLineinstance 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
AlgebraicLineinstance
-
from
Creates a newAlgebraicLineinstance from a givenSlopeInterceptLine. Note: This is trivial, sinceSlopeInterceptLineis a (restricted)AlgebraicLineitself.- Parameters:
sil- aSlopeInterceptLine- Returns:
- a new
AlgebraicLineinstance
-
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:
getDistancein 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. Returnsnullif the two lines are parallel.- Parameters:
l2- anotherAlgebraicLine- Returns:
- the intersection point or
nullif lines are parallel
-
getShape
Description copied from interface:ShapeProducerReturns a scaledShapefor 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, forPnt2dit specifies the size of the marker (seePnt2d.getShape(double).- Specified by:
getShapein interfaceShapeProducer- Parameters:
length- the scale of the shape- Returns:
- a
Shapeinstance
-
getShape
Returns aShapefor 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
Shapeinstance for this line
-
equals
-
equals
Checks if thisAlgebraicLineis equal to anotherAlgebraicLine.- Parameters:
other- anotherAlgebraicLinetolerance- the maximum deviation- Returns:
- true if both lines are equal
-
toString
-