def draw_zebra_crossing(ctx, frame: Polygon, stripe_width: float = 0.04, offset: float = 0.02): """Draw a zebra crossing in the given frame. Args: frame: Frame of the zebra crossing. **Points of the frame must be given in the right order!** first point : start on left line second point: end on left line third point : end on right line fourth point: start on right line """ points = frame.get_points() left = Line([points[0], points[3]]) right = Line([points[1], points[2]]) flag = True min_length = min(left.length, right.length) x = offset while x < min_length: l, r = left.interpolate(x), right.interpolate(x) if flag: ctx.move_to(l.x, l.y) ctx.line_to(r.x, r.y) flag = False else: ctx.line_to(r.x, r.y) ctx.line_to(l.x, l.y) ctx.close_path() ctx.fill() flag = True x += stripe_width
def _get_stop_line(line1: Line, line2: Line, kind) -> SurfaceMarkingRect: """Return a line perpendicular to both provided (assumed parallel) lines. The returned line will be at the first point where both lines are parallel to each other plus 2cm offset. """ beginning_line1 = line1.interpolate(0.02) beginning_line2 = line2.interpolate(0.02) # Test which line to draw the stop line at if beginning_line1.distance(line2) < beginning_line2.distance(line1): # End of line 1 is the starting point of the stop line p1 = beginning_line1 p2 = line2.interpolate(line2.project(beginning_line1)) else: # End of line 2 is the starting point p1 = line1.interpolate(line1.project(beginning_line2)) p2 = beginning_line2 line = Line([p1, p2]) width = line.length center = 0.5 * (Vector(line.coords[0]) + Vector(line.coords[1])) angle = line1.interpolate_direction(arc_length=0).argument return SurfaceMarkingRect(kind, *center.xy, angle=angle, width=width, normalize_x=False, depth=0.04)
def draw_start_lane(ctx, frame: Polygon): """Draw the checkerboard pattern to mark the beginning of a parking area in the given frame. Args: frame: Frame of the start lane. **Points of the frame must be given in the right order!** first point : start on left line second point: end on left line third point : end on right line fourth point: start on right line """ TILE_LENGTH = 0.02 points = frame.get_points() left = Line([points[0], points[1]]) right = Line([points[3], points[2]]) for i in range(3): utils.draw_line( ctx, MarkedLine( [ left.interpolate(TILE_LENGTH * (i + 0.5)), right.interpolate(TILE_LENGTH * (i + 0.5)), ], style=RoadSection.DASHED_LINE_MARKING, prev_length=(i % 2 + 0.5) * TILE_LENGTH, ), dash_length=TILE_LENGTH, )
def draw_start_lane(ctx, frame: Polygon): TILE_LENGTH = 0.02 points = frame.get_points() left = Line([points[0], points[1]]) right = Line([points[3], points[2]]) for i in range(3): utils.draw_line( ctx, MarkedLine( [ left.interpolate(TILE_LENGTH * (i + 0.5)), right.interpolate(TILE_LENGTH * (i + 0.5)), ], style=RoadSection.DASHED_LINE_MARKING, prev_length=(i % 2 + 0.5) * TILE_LENGTH, ), dash_length=TILE_LENGTH, )
def draw_zebra_crossing(ctx, frame: Polygon, stripe_width: float = 0.04, offset: float = 0.02): points = frame.get_points() left = Line([points[0], points[3]]) right = Line([points[1], points[2]]) flag = True min_length = min(left.length, right.length) x = offset while x < min_length: l, r = left.interpolate(x), right.interpolate(x) if flag: ctx.move_to(l.x, l.y) ctx.line_to(r.x, r.y) flag = False else: ctx.line_to(r.x, r.y) ctx.line_to(l.x, l.y) ctx.close_path() ctx.fill() flag = True x += stripe_width