Class BinarySearchIntersectionIdentifier



  • public class BinarySearchIntersectionIdentifier
    extends IntersectionIdentifier
    This IntersectionIdentifier uses a 2D binary search to hone in on potential intersections.

    It breaks curves up according to their critical points, so each curve segment is guaranteed to only move in 1 general direction between any two give t values. TODO warning: this project is buggy. The CurveIntersectionApp can be used to highlight several instances where two cubic curves do not produce intersections (even though the human eye can tell they should). Also sometimes exceptions are thrown. The simplest starting point for these issues is: Curve 1: m 100.0 100.0 c 125.0 125.0 125.0 275.0 100.0 300.0 Curve 2: m 113.0 120.0 c 88.0 145.0 88.0 295.0 113.0 320.0

    • Constructor Detail

      • BinarySearchIntersectionIdentifier

        public BinarySearchIntersectionIdentifier()
    • Method Detail

      • lineQuadratic

        public int lineQuadratic(double ax1,
                                 double bx1,
                                 double ay1,
                                 double by1,
                                 double ax2,
                                 double bx2,
                                 double cx2,
                                 double ay2,
                                 double by2,
                                 double cy2,
                                 double[] dest,
                                 int offset,
                                 IntersectionIdentifier.Return returnType)
        Description copied from class: IntersectionIdentifier
        Identify the intersection(s) of a line and a parabola, expressed as parametric equations.
        Specified by:
        lineQuadratic in class  IntersectionIdentifier
        Parameters:
        ax1 - the coefficient "ax1" in the equation "x1(t1) = ax1*t1+bx1"
        bx1 - the coefficient "bx1" in the equation "x1(t1) = ax1*t1+bx1"
        ay1 - the coefficient "ay1" in the equation "y1(t1) = ay1*t1+by1"
        by1 - the coefficient "by1" in the equation "y1(t1) = ay1*t1+by1"
        ax2 - the coefficient "ax2" in the equation "x2(t2) = ax2*t2*t2+bx2*t2+cx2"
        bx2 - the coefficient "bx2" in the equation "x2(t2) = ax2*t2*t2+bx2*t2+cx2"
        cx2 - the coefficient "cx2" in the equation "x2(t2) = ax2*t2*t2+bx2*t2+cx2"
        ay2 - the coefficient "ay2" in the equation "y2(t2) = ay2*t2*t2+by2*t2+cy2"
        by2 - the coefficient "by2" in the equation "y2(t2) = ay2*t2*t2+by2*t2+cy2"
        cy2 - the coefficient "cy2" in the equation "y2(t2) = ay2*t2*t2+by2*t2+cy2"
        dest - the destination to write the time intersections in.
        offset - the offset in the array to start writing at.
        returnType - the type of data to store in dest.
        Returns:
        the number of intersections found.
      • lineCubic

        public int lineCubic(double ax1,
                             double bx1,
                             double ay1,
                             double by1,
                             double ax2,
                             double bx2,
                             double cx2,
                             double dx2,
                             double ay2,
                             double by2,
                             double cy2,
                             double dy2,
                             double[] dest,
                             int offset,
                             IntersectionIdentifier.Return returnType)
        Description copied from class: IntersectionIdentifier
        Identify the intersection(s) of a line and a cubic curve, expressed as parametric equations.
        Specified by:
        lineCubic in class  IntersectionIdentifier
        Parameters:
        ax1 - the coefficient "ax1" in the equation "x1(t1) = ax1*t1+bx1"
        bx1 - the coefficient "bx1" in the equation "x1(t1) = ax1*t1+bx1"
        ay1 - the coefficient "ay1" in the equation "y1(t1) = ay1*t1+by1"
        by1 - the coefficient "by1" in the equation "y1(t1) = ay1*t1+by1"
        ax2 - the coefficient "ax2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        bx2 - the coefficient "bx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        cx2 - the coefficient "cx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        dx2 - the coefficient "dx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        ay2 - the coefficient "ay2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        by2 - the coefficient "by2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        cy2 - the coefficient "by2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        dy2 - the coefficient "dy2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        dest - the destination to write the time intersections in.
        offset - the offset in the array to start writing at.
        returnType - the type of data to store in dest.
        Returns:
        the number of intersections found.
      • quadraticQuadratic

        public int quadraticQuadratic(double ax1,
                                      double bx1,
                                      double cx1,
                                      double ay1,
                                      double by1,
                                      double cy1,
                                      double ax2,
                                      double bx2,
                                      double cx2,
                                      double ay2,
                                      double by2,
                                      double cy2,
                                      double[] dest,
                                      int offset,
                                      IntersectionIdentifier.Return returnType)
        Description copied from class: IntersectionIdentifier
        Identify the intersection(s) of two parabolas, expressed as parametric equations.
        Specified by:
        quadraticQuadratic in class  IntersectionIdentifier
        Parameters:
        ax1 - the coefficient "ax1" in the equation "x1(t1) = ax1*t1*t1+bx1*t1+cx1"
        bx1 - the coefficient "bx1" in the equation "x1(t1) = ax1*t1*t1+bx1*t1+cx1"
        cx1 - the coefficient "cx1" in the equation "x1(t1) = ax1*t1*t1+bx1*t1+cx1"
        ay1 - the coefficient "ay1" in the equation "y1(t1) = ay1*t1*t1+by1*t1+cy1"
        by1 - the coefficient "by1" in the equation "y1(t1) = ay1*t1*t1+by1*t1+cy1"
        cy1 - the coefficient "by1" in the equation "y1(t1) = ay1*t1*t1+by1*t1+cy1"
        ax2 - the coefficient "ax2" in the equation "x2(t2) = ax2*t2*t2+bx2*t2+cx2"
        bx2 - the coefficient "bx2" in the equation "x2(t2) = ax2*t2*t2+bx2*t2+cx2"
        cx2 - the coefficient "cx2" in the equation "x2(t2) = ax2*t2*t2+bx2*t2+cx2"
        ay2 - the coefficient "ay2" in the equation "y2(t2) = ay2*t2*t2+by2*t2+cy2"
        by2 - the coefficient "by2" in the equation "y2(t2) = ay2*t2*t2+by2*t2+cy2"
        cy2 - the coefficient "cy2" in the equation "y2(t2) = ay2*t2*t2+by2*t2+cy2"
        dest - the destination to write the time intersections in.
        offset - the offset in the array to start writing at.
        returnType - the type of data to store in dest.
        Returns:
        the number of intersections found.
      • quadraticCubic

        public int quadraticCubic(double ax1,
                                  double bx1,
                                  double cx1,
                                  double ay1,
                                  double by1,
                                  double cy1,
                                  double ax2,
                                  double bx2,
                                  double cx2,
                                  double dx2,
                                  double ay2,
                                  double by2,
                                  double cy2,
                                  double dy2,
                                  double[] dest,
                                  int offset,
                                  IntersectionIdentifier.Return returnType)
        Description copied from class: IntersectionIdentifier
        Identify the intersection(s) of a parabola and a cubic curve, expressed as parametric equations.
        Specified by:
        quadraticCubic in class  IntersectionIdentifier
        Parameters:
        ax1 - the coefficient "ax1" in the equation "x1(t1) = ax1*t1*t1+bx1*t1+cx1"
        bx1 - the coefficient "bx1" in the equation "x1(t1) = ax1*t1*t1+bx1*t1+cx1"
        cx1 - the coefficient "cx1" in the equation "x1(t1) = ax1*t1*t1+bx1*t1+cx1"
        ay1 - the coefficient "ay1" in the equation "y1(t1) = ay1*t1*t1+by1*t1+cy1"
        by1 - the coefficient "by1" in the equation "y1(t1) = ay1*t1*t1+by1*t1+cy1"
        cy1 - the coefficient "by1" in the equation "y1(t1) = ay1*t1*t1+by1*t1+cy1"
        ax2 - the coefficient "ax2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        bx2 - the coefficient "bx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        cx2 - the coefficient "cx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        dx2 - the coefficient "dx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        ay2 - the coefficient "ay2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        by2 - the coefficient "by2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        cy2 - the coefficient "by2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        dy2 - the coefficient "dy2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        dest - the destination to write the time intersections in.
        offset - the offset in the array to start writing at.
        returnType - the type of data to store in dest.
        Returns:
        the number of intersections found.
      • cubicCubic

        public int cubicCubic(double ax1,
                              double bx1,
                              double cx1,
                              double dx1,
                              double ay1,
                              double by1,
                              double cy1,
                              double dy1,
                              double ax2,
                              double bx2,
                              double cx2,
                              double dx2,
                              double ay2,
                              double by2,
                              double cy2,
                              double dy2,
                              double[] dest,
                              int offset,
                              IntersectionIdentifier.Return returnType)
        Description copied from class: IntersectionIdentifier
        Identify the intersection(s) of two cubic curves, expressed as parametric equations.
        Specified by:
        cubicCubic in class  IntersectionIdentifier
        Parameters:
        ax1 - the coefficient "ax1" in the equation "x1(t1) = ax1*t1*t1*t1+bx1*t1*t1+cx1*t1+dx1"
        bx1 - the coefficient "bx1" in the equation "x1(t1) = ax1*t1*t1*t1+bx1*t1*t1+cx1*t1+dx1"
        cx1 - the coefficient "cx1" in the equation "x1(t1) = ax1*t1*t1*t1+bx1*t1*t1+cx1*t1+dx1"
        dx1 - the coefficient "dx1" in the equation "x1(t1) = ax1*t1*t1*t1+bx1*t1*t1+cx1*t1+dx1"
        ay1 - the coefficient "ay1" in the equation "y1(t1) = ay1*t1*t1*t1+by1*t1*t1+cy1*t1+dy1"
        by1 - the coefficient "by1" in the equation "y1(t1) = ay1*t1*t1*t1+by1*t1*t1+cy1*t1+dy1"
        cy1 - the coefficient "by1" in the equation "y1(t1) = ay1*t1*t1*t1+by1*t1*t1+cy1*t1+dy1"
        dy1 - the coefficient "dy1" in the equation "y1(t1) = ay1*t1*t1*t1+by1*t1*t1+cy1*t1+dy1"
        ax2 - the coefficient "ax2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        bx2 - the coefficient "bx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        cx2 - the coefficient "cx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        dx2 - the coefficient "dx2" in the equation "x2(t2) = ax2*t2*t2*t2+bx2*t2*t2+cx2*t2+dx2"
        ay2 - the coefficient "ay2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        by2 - the coefficient "by2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        cy2 - the coefficient "by2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        dy2 - the coefficient "dy2" in the equation "y2(t2) = ay2*t2*t2*t2+by2*t2*t2+cy2*t2+dy2"
        dest - the destination to write the time intersections in.
        offset - the offset in the array to start writing at.
        returnType - the type of data to store in dest.
        Returns:
        the number of intersections found.