/** * Find intersections between two hyperbolas * * @param a Hyperbola * @param b Hyperbola * @param iPts where to store intersection points; null to construct */ public static DArray findIntersections(Hyperbola a, Hyperbola b, DArray iPts) { final boolean db = false; if (iPts == null) iPts = new DArray(); iPts.clear(); final DArray jPts = new DArray(); // a.initClipIfNec(); // b.initClipIfNec(); if (db) { System.out.println( "finding intersections between:\n" + a.toString(true) + "\n" + b.toString(true)); } PlaneCurve.findIntersect(a.getCurve(), b.getCurve(), jPts); // filter out false intersections if (db) { System.out.println("prefilter # intersections= " + jPts.size()); } FPoint2 ptc = new FPoint2(); for (int i = 0; i < jPts.size(); i++) { FPoint2 pt = jPts.getFPoint2(i); // make sure calculated intersect point is actually on both arms { FPoint2 data = a.calcParameterAndDistance(pt); if (data.y > .001) continue; data = b.calcParameterAndDistance(pt); if (data.y > .001) continue; } if (!a.isLine()) { // put in curve space to verify it's to the right of the y axis a.toCurveSpace(pt, ptc); if (db) { System.out.println("Filter " + i + " in curveA= " + ptc); } if (ptc.x <= 0) { if (db) { System.out.println(" < 0"); } continue; } } if (!b.isLine()) { b.toCurveSpace(pt, ptc); if (db) { System.out.println(" in curveB= " + ptc); } if (ptc.x <= 0) { if (db) { System.out.println(" < 0"); } continue; } } if (db) { System.out.println(" adding " + pt); } iPts.add(pt); } return iPts; }