Class AlgebraicLine

java.lang.Object
imagingbook.common.geometry.line.AlgebraicLine
All Implemented Interfaces:
Primitive2d, ShapeProducer
Direct Known Subclasses:
HessianLine, SlopeInterceptLine

public class AlgebraicLine extends Object implements ShapeProducer, Primitive2d

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 Details

    • A

      public final double A
    • B

      public final double B
    • C

      public final double C
  • Constructor Details

    • AlgebraicLine

      public AlgebraicLine(double A, double B, double C)
      Constructor. Creates a AlgebraicLine instance with parameters A, B, C.
      Parameters:
      A - line parameter A
      B - line parameter B
      C - line parameter C
    • AlgebraicLine

      public AlgebraicLine(double[] p)
      Constructor. Creates a AlgebraicLine instance from a parameter vector [A, B, C].
      Parameters:
      p - parameter vector [A, B, C]
  • Method Details

    • from

      public static AlgebraicLine from(double[] s, double[] v)
      Creates a new AlgebraicLine 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 by getSignedDistance(Pnt2d) is positive and negative for points on the right side.
      Parameters:
      s - start point
      v - orientation vector
      Returns:
      a new AlgebraicLine instance
    • from

      public static AlgebraicLine from(ParametricLine pl)
      Creates a new AlgebraicLine instance from a given ParametricLine.
      Parameters:
      pl - a ParametricLine
      Returns:
      a new AlgebraicLine instance
    • from

      public static AlgebraicLine from(Pnt2d p0, Pnt2d p1)
      Creates a new AlgebraicLine instance from two given points. The direction of the line is from the first to the second point.
      Parameters:
      p0 - first point
      p1 - second point
      Returns:
      a new AlgebraicLine instance
    • from

      public static AlgebraicLine from(SlopeInterceptLine sil)
      Creates a new AlgebraicLine instance from a given SlopeInterceptLine. Note: This is trivial, since SlopeInterceptLine is a (restricted) AlgebraicLine itself.
      Parameters:
      sil - a SlopeInterceptLine
      Returns:
      a new AlgebraicLine instance
    • getParameters

      public final double[] getParameters()
      Returns the algebraic line parameters [A, B, C].
      Returns:
      algebraic line parameters
    • getXref

      public double getXref()
      Returns the x-coordinate of the reference point. For a AlgebraicLine, the result is always zero. Inheriting classes (like HoughLine) override this method.
      Returns:
      the x-coordinate reference
    • getYref

      public double getYref()
      Returns the y-coordinate of the reference point. For a AlgebraicLine, the result is always zero. Inheriting classes (like HoughLine) override this method.
      Returns:
      the y-coordinate reference
    • getDistance

      public double getDistance(double x, double y)
      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

      public double getDistance(Pnt2d p)
      Returns the orthogonal (unsigned) distance between this line and the point p. The result is always non-negative.
      Specified by:
      getDistance in interface Primitive2d
      Parameters:
      p - point position.
      Returns:
      The perpendicular distance between this line and the point p.
    • getSignedDistance

      public double getSignedDistance(double x, double y)
      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

      public double getSignedDistance(Pnt2d p)
      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

      public double getSquareError(Pnt2d[] points)
      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 another AlgebraicLine. Returns null if the two lines are parallel.
      Parameters:
      l2 - another AlgebraicLine
      Returns:
      the intersection point or null if lines are parallel
    • getShape

      public Shape getShape(double length)
      Description copied from interface: ShapeProducer
      Returns a scaled Shape 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, for Pnt2d it specifies the size of the marker (see Pnt2d.getShape(double).
      Specified by:
      getShape in interface ShapeProducer
      Parameters:
      length - the scale of the shape
      Returns:
      a Shape instance
    • getShape

      public Shape getShape(int width, int height)
      Returns a Shape 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 canvas
      height - the height of the drawing canvas
      Returns:
      a Shape instance for this line
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(AlgebraicLine other, double tolerance)
      Checks if this AlgebraicLine is equal to another AlgebraicLine.
      Parameters:
      other - another AlgebraicLine
      tolerance - the maximum deviation
      Returns:
      true if both lines are equal
    • toString

      public String toString()
      Overrides:
      toString in class Object