def overlap(self): """Try to figure out if there is an overlap """ self.overlappers = list() for fbox in self.fboxes: for gbox in self.gboxes: # TODO: remove illustration tmp = NaivePlot(60, 20, -1, 7, -1, 11) cf = Curve(self.f, 0.0, 1.0, 0.001) cg = Curve(self.g, 0.0, 1.0, 0.001) cfb = Curve(fbox, 0.0, 1.0, 0.001) cgb = Curve(gbox, 0.0, 1.0, 0.001) tmp.add_curve(cf, "/", "white") tmp.add_curve(cg, "\\", "white") tmp.add_curve(cfb, "f", "red") tmp.add_curve(cgb, "g", "blue") tmp.fit_curve(cf) tmp.fit_curve(cg) print tmp if fbox.overlap(gbox): self.overlappers.append((fbox, gbox)) return len(self.overlappers) > 0
if __name__ == '__main__': print "Demo Plot 1" plot = NaivePlot(xmin=-3.5, xmax=3.3, ymin=-3.3, ymax=2.7) c1 = Curve(Func(lambda x: 1-x/2), -pi, pi, 0.02) c2 = Curve(ParaFunc(lambda t: sin(2*t)-2, lambda t: 2*cos(t)), 0, 2*pi, 0.02) c3 = Curve(ParaFunc(lambda t: 2+sin(t), lambda t: cos(t)-2), 0, 2*pi, 0.02) for (curve, cross) in [(c1, '~'), (c2, '8'), (c3, 'o')]: plot.add_curve(curve, cross) plot.fit_curve(curve) for p in [1, -1, 2, -2]: plot.add_curve(Point(p, -p), 'X') plot.add_curve(Point(p, p), 'X') print plot print "Demo Plot 2" heart = NaivePlot() pf1 = ParaFunc(heartx, hearty) c1 = Curve(pf1, -pi, pi, 0.001) heart.add_curve(c1, 'o', 'red') heart.fit_curve(c1) pf2 = ParaFunc(curvex, curvey) heart.add_curve(Curve(pf2, -20, 20, 0.01), 'x', 'white')