/** * Calculate dx, dy values for a point * * @param t : parameter * @param delta : where to store dx, dy values */ private void calcTangentAt(double t, FPoint2 delta) { final boolean db = false; if (db) { System.out.println("calcTangentAt " + t); } t = toInt(t); if (db) { System.out.println(" flipped=" + flipped() + " ti=" + t); } double a = toW2.get(0, 0), b = toW2.get(0, 1), c = toW2.get(0, 2); double d = toW2.get(1, 0), e = toW2.get(1, 1), f = toW2.get(1, 2); if (db) { System.out.println(" a=" + a + " b=" + b + " c=" + c + "\n d=" + d + " e=" + e + " f=" + f); } double rt = Polyn.sqrt(A + B * t * t); double dx = a * B * t / rt + b; double dy = d * B * t / rt + e; if (flipped()) { dx = -dx; dy = -dy; } if (db) { System.out.println(" dx=" + dx + "\n dy=" + dy); System.out.println(" ratio=" + (dy / dx)); } delta.setLocation(dx, dy); }
/** * Determine where point is relative to arm * * @param x : * @param y : point to test * @return an integer, which is 0 if it's on the arm, 1 if it's to the right of the arm, -1 if * it's to the left of the arm */ public int testPoint(double x, double y) { final FPoint2 ept = new FPoint2(), eps = new FPoint2(); eps.setLocation(x, y); toCurveSpace(eps, ept); FPoint2 as = calcPointInArmSpace(toExt(ept.y)); int out = 0; double diff = ept.x - as.x; if (diff > 0) { out = 1; } else if (diff < 0) { out = -1; } if (flipped()) { out = -out; } return out; }
public void render(Color c, int stroke, int markType) { final boolean db = false; // Get array of visible segments. If no such array exists, // use default. DArray vseg = visSeg; boolean dashed = false; // if (step == 0) { double step = renderStep(); // } // vp V = TestBed.view(); if (db) Streams.out.println(" step=" + step); // plot each visible segment for (int seg = 0; seg < vseg.size(); seg += 2) { double t0 = vseg.getDouble(seg + 0), t1 = vseg.getDouble(seg + 1); t0 = MyMath.clamp(t0, -500.0, 500.0); t1 = MyMath.clamp(t1, -500.0, 500.0); // render() expects external parameters. double s0 = toExt(t0), s1 = toExt(t1); if (s0 > s1) { double tmp = s0; s0 = s1; s1 = tmp; } FPoint2 p0 = calcPoint(s0), p1 = calcPoint(s1); if (db) Streams.out.println(" p0=" + p0 + ", p1=" + p1); if (isLine() && !dashed) { V.drawLine(p0, p1); } else { /* if (Math.abs(s0) >= 500 ||Math.abs(s1) >= 500) System.out.println("Rendering "+t0+" to "+t1+" step "+step); */ if (dashed) V.pushStroke(Globals.STRK_RUBBERBAND); { // int count = 0; boolean first = true; for (double t = t0; ; t += step) { // , count++) { boolean last = (t >= t1); if (last) { t = t1; } calcPointInternal(t, p1); if (!p1.isValid()) { if (last) { break; } continue; } if (db) { System.out.println(" calcPt " + Tools.f(toExt(t)) + " = " + p1.x + "," + p1.y); } if (!first) { V.drawLine(p0, p1); if (false) { Tools.warn("highlighting int"); V.mark(p0); } } if (last) { break; } p0.setLocation(p1); first = false; } } if (dashed) V.popStroke(); } } }