def check_open_directions_for_circle_avoiding_segment(): placements = [] radius = 0.25 step = 0.15 center = P(0.5, 0.5) circ = Circle(center, radius) m = 0 for i in range(10000): p = P.polar(0.35, i / 1000 * 2 * np.pi) + P(0.5, 0.5) q = p + P.polar(0.2, i / 314 * 2 * np.pi) seg = S(p, q) directions = GRegion.open_directions_for_circle_avoiding_segment( circ, seg, step) shift = seg.dir.perp().resize(radius) box = Polygon([p - shift, p + shift, q + shift, q - shift]) l = [(Circle(center, step), "lightgreen"), (box, "lightgrey"), (Circle(p, radius), "lightgrey"), (Circle(q, radius), "lightgrey"), (directions, "black"), (seg, "red"), (Circle(center, 0.004), "red")] pp, dist = seg.closest_point(center) if dist >= radius: for r in directions.regions: for t in r: cut = seg.intersect_with_circle(center + t.resize(step), radius) if cut and cut.length() > 0.00000001: l += [(Circle(center + t.resize(step), radius), "pink")] m = max(m, cut.length()) print(m) placements.append(l) movie = Movie() movie.run_animation(placements, 10) exit()
def check_open_directions_for_circle_avoiding_segment3(): placements = [] radius = 0.25 step = 0.15 center = P(0.5, 0.5) circ = Circle(center, radius) for i in range(1000): p = P.polar(0.37, i / 1000 * 2 * np.pi) + P(0.43, 0.38) q = p + P(0.1, 0.2) seg = S(p, q) directions = GRegion.open_directions_for_circle_avoiding_segment( circ, seg, step) if len(directions.regions) > 1: shift = seg.dir.perp().resize(radius) print(seg.p.x, seg.p.y, seg.q.x, seg.q.y) box = Polygon([p - shift, p + shift, q + shift, q - shift]) l = [(Circle(center, step), "lightgreen"), (box, "lightgrey"), (Circle(p, radius), "lightgrey"), (Circle(q, radius), "lightgrey"), (directions, "black"), (seg, "red"), (Circle(center, 0.004), "red")] placements.append(l) movie = Movie() movie.background(l) movie.just_draw() break exit(0)
def square(p, size, angle): sq = [p] for i in range(3): p = p + P.polar(size, angle) sq.append(p) angle += np.pi / 2 return Polygon(sq)
def point_at_angle(self, angle, size=1.0): """ Generate vector within the region. :param angle: relative angle (within the region) of the generated vector :param size: norm of the generated vector :return: the vector generated (class P) """ return P.polar(size, self.p1.angle() + angle)
def check_open_directions_for_point(): placements = [] for i in range(1000): stones = PolygonSet() stones.add( Polygon.square( P.polar(0.3, i / 1000 * 2 * np.pi) + P(0.3, 0.40), 0.2, 0.2)) directions = stones.open_directions_for_point(P(0.5, 0.5), 0.4) placements.append([(s, "red") for s in stones] + [(directions, "green")]) movie.run_animation(placements, 10) exit()
def tilted_rectangle(p, size1, size2, angle): sq = [p] size = size1 for i in range(3): p += P.polar(size, angle) sq.append(p) angle -= np.pi / 2 if size == size1: size = size2 else: size = size1 return Polygon(sq)
def check_open_directions_for_circle_avoiding_point(): placements = [] radius = 0.2 step = 0.15 center = P(0.55, 0.5) circ = Circle(center, radius) for i in range(1000): p = P.polar(0.35, i / 1000 * 2 * np.pi) + P(0.4, 0.40) dirs = GRegion.open_directions_for_circle_avoiding_point(circ, p, step) directions = GRegion(center=circ.center) if dirs: directions.intersect_with(dirs) placements.append([(Circle(center, step), "green"), (Circle(p, radius), "lightgrey"), (directions, "black")]) movie = Movie() movie.run_animation(placements, 10) exit()
def check_segment_stuff2(): s = S(P(0.3, 0.5), P(0.7, 0.4)) radius = 0.2 movie.background([(s, "black")]) placements = [] for i in range(5000): center = P.polar(i / 10000, i / 1000 * 2 * np.pi) + P(0.5, 0.5) current = [(Circle(center, radius), "red")] intersect = s.intersect_with_circle(center, radius) closest, dist = s.closest_point(center) if intersect: current.append((intersect, "yellow")) current.append((closest, "green")) if dist < radius and not intersect: print("WHAT??") placements.append(current) movie.run_animation(placements, 10) exit()