import sys

width, height = 400, 400
margin = 20

input_file = open(sys.argv[1]).read().strip()
answer_file = open(sys.argv[2]).read().strip()
feedback_dir = sys.argv[3]
candidate_file = sys.stdin.read()

# get v
split_input = input_file.rstrip().split("\n")
v, _ = map(int, split_input[0].split(" "))

# get poly
raw_poly = split_input[1:]
poly = [list(map(int, vert.split(" "))) for vert in raw_poly]

# get candidate, judge answers
candidate_t, candidate_x, candidate_y = map(float, sum([line.split(" ") for line in candidate_file.split("\n")], [])[:3])
candidate_r = candidate_t * v

judge_t, judge_x, judge_y = map(float, sum([line.split(" ") for line in answer_file.split("\n")], [])[:3])
judge_r = judge_t * v

# get bounds
xs, ys = zip(*poly)
min_x, max_x = min(xs), max(xs)
min_y, max_y = min(ys), max(ys)

# fit coords to target canvas size
scale_x = (width - 2*margin) / (max_x - min_x) if max_x != min_x else 1
scale_y = (height - 2*margin) / (max_y - min_y) if max_y != min_y else 1
scale = min(scale_x, scale_y)

def transform(pt):
    x, y = pt
    tx = (x - min_x) * scale + margin
    ty = height - ((y - min_y) * scale + margin)
    return tx, ty

# form svg
svg = [
    f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}">',
    f'<rect width="100%" height="100%" fill="#eee" />'
]

# draw poly
points_str = " ".join(f"{transform((x, y))[0]},{transform((x, y))[1]}" for x, y in poly)
svg.append(f'<polygon points="{points_str}" fill="none" stroke="black" stroke-width="2"/>')

# draw judge circle
tx, ty = transform((judge_x, judge_y))
r_scaled = judge_r * scale
svg.append(f'<circle cx="{tx}" cy="{ty}" r="{r_scaled}" fill="none" stroke="green" stroke-width="2"/>')

# draw candidate circle
cx, cy = transform((candidate_x, candidate_y))
r_scaled = candidate_r * scale
svg.append(f'<circle cx="{cx}" cy="{cy}" r="{r_scaled}" fill="none" stroke="red" stroke-width="2"/>')

# Add radius info at top
svg.append(f'<text x="{margin}" y="{margin - 4}" fill="green" font-size="14">Judge r = {judge_r:.2f}</text>')
svg.append(f'<text x="{margin + 150}" y="{margin - 4}" fill="red" font-size="14">Candidate r = {candidate_r:.2f}</text>')

svg.append("</svg>")

with open(feedback_dir + "/judgeimage.svg" , "w") as f:
    f.write("\n".join(svg))