"""Isometric-like cutaway of the holiday flat (oblique projection), generated from plan coordinates (800 x 548 scan). Output: SVG with floors, low walls and simple furniture; also prints the projected room polygons for click areas. """ import json import sys SHEAR, SQUASH = 0.2, 0.86 # oblique projection: X = x + SHEAR * y, Y = SQUASH * y - z OX, OY = 40, 30 # margin NAVY, PAPER, LINE = '#13294B', '#FBFAF7', '#13294B' def project(x, y, z=0.0): return x + SHEAR * y, SQUASH * y - z shapes = [] # (depth, svg) def poly(points, fill, stroke=LINE, width=1.2, extra=''): pts = ' '.join(f'{round(px + OX, 1)},{round(py + OY, 1)}' for px, py in points) return f'' def signed_area(points): return sum(points[i][0] * points[(i + 1) % len(points)][1] - points[(i + 1) % len(points)][0] * points[i][1] for i in range(len(points))) / 2 def prism(base, height, top, side, front=None, depth=None, z0=0.0, outline=LINE): """Convex prism over a plan polygon; side faces drawn back-to-front with back-face culling.""" front = front or side faces = [] n = len(base) for i in range(n): (x1, y1), (x2, y2) = base[i], base[(i + 1) % n] quad = [project(x1, y1, z0), project(x2, y2, z0), project(x2, y2, z0 + height), project(x1, y1, z0 + height)] if signed_area(quad) <= 0: continue colour = front if abs(y1 - y2) < 1e-6 else side faces.append((max(y1, y2), poly(quad, colour, outline, 1.1))) faces.sort(key=lambda f: f[0]) svg = ''.join(f for _, f in faces) + poly([project(x, y, z0 + height) for x, y in base], top, outline, 1.1) shapes.append((depth if depth is not None else max(y for _, y in base) + 0.001 * min(x for x, _ in base), svg)) def box(x, y, w, d, h, top, side, front=None, z0=0.0, depth=None): prism([(x, y), (x + w, y), (x + w, y + d), (x, y + d)], h, top, side, front, depth, z0) def wall(x1, y1, x2, y2, t=6, h=22): dx, dy = x2 - x1, y2 - y1 length = (dx * dx + dy * dy) ** 0.5 nx, ny = -dy / length * t / 2, dx / length * t / 2 base = [(x1 + nx, y1 + ny), (x2 + nx, y2 + ny), (x2 - nx, y2 - ny), (x1 - nx, y1 - ny)] if signed_area(base) < 0: base.reverse() prism(base, h, NAVY, '#FFFFFF', '#F1EFEA') # Rooms (same polygons as the click areas in the scan). ROOMS = { 'terrasse': [(8, 150), (60, 150), (60, 300), (8, 300)], 'wohnen': [(65, 150), (400, 150), (400, 245), (240, 245), (240, 350), (130, 350), (65, 290)], 'kueche': [(240, 245), (400, 245), (400, 350), (240, 350)], 'diele': [(400, 150), (548, 150), (548, 245), (400, 245)], 'bad': [(403, 245), (531, 245), (531, 350), (403, 350)], 'schlafen': [(548, 195), (720, 195), (720, 350), (535, 350), (535, 265)], } FLOORS = {'terrasse': '#C9976A', 'wohnen': '#E7D2AD', 'kueche': '#E9E7E1', 'diele': '#E9E7E1', 'bad': '#DCEFF5', 'schlafen': '#EAD9BC'} floor_svg = [] # lawn around the terrace and along the front floor_svg.append(poly([project(-40, 120), project(64, 120), project(64, 372), project(-40, 372)], '#CFE3C1', '#CFE3C1', 0)) for key, points in ROOMS.items(): floor_svg.append(poly([project(x, y) for x, y in points], FLOORS[key], '#B8B2A6', 0.8)) # deck planks and tile grids for x in range(14, 60, 9): floor_svg.append(f'') for (x0, y0, x1, y1) in ((242, 247, 398, 348), (405, 247, 529, 348), (402, 152, 546, 243)): step = 16 for x in range(x0, x1, step): floor_svg.append(f'') for y in range(y0, y1, step): floor_svg.append(f'') # Walls (outer and inner, with openings). for seg in [ (65, 148, 238, 148), (238, 148, 548, 148), # north (548, 148, 548, 195), (548, 195, 720, 195), # entry corner, bedroom north (720, 195, 720, 352), # east ]: wall(*seg) # Front walls are cut low (architectural model), so the rooms stay visible. for seg in [ (720, 352, 610, 352), (560, 352, 130, 352), # south (gap = bedroom window) (130, 352, 65, 290), # diagonal (65, 290, 65, 262), (65, 182, 65, 148), # west (gap = terrace door) ]: wall(*seg, h=7) for seg in [ (400, 148, 400, 200), # living / hall partial (400, 245, 440, 245), (472, 245, 531, 245), # bath north with door (403, 245, 403, 352), (531, 245, 531, 352), # bath west/east (540, 195, 540, 252), (540, 292, 540, 352), # bedroom west with door ]: wall(*seg) # Furniture WOOD, WHITE, LEATHER, GLASS = '#B7895C', '#FFFFFF', '#2A4C7A', '#BFE4EE' box(238, 154, 116, 18, 28, '#F4F1EA', '#E6E1D6') # Schrankbett cabinet box(405, 154, 132, 18, 28, '#F4F1EA', '#E6E1D6') # hall wardrobe box(100, 160, 104, 34, 15, LEATHER, '#1F3B61') # sofa box(100, 160, 104, 10, 26, LEATHER, '#1F3B61', depth=162) # sofa back box(118, 208, 74, 34, 9, GLASS, '#9CCFDD') # glass table box(150, 258, 46, 40, 15, LEATHER, '#1F3B61') # relax chair box(84, 300, 52, 26, 20, WHITE, '#E9E6DF') # TV cabinet box(262, 252, 32, 92, 13, '#3A3A3A', '#2A2A2A') # dining table for cx, cy in ((246, 262), (246, 318), (298, 262), (298, 318)): box(cx, cy, 14, 14, 9, '#5B5B5B', '#444444') # chairs box(368, 250, 32, 100, 17, '#F7F6F2', '#E4E1D9') # kitchen counter (east) box(300, 322, 68, 28, 17, '#F7F6F2', '#E4E1D9') # kitchen counter (south) box(410, 262, 30, 34, 12, WHITE, '#E7EEF1') # toilet box(410, 310, 30, 30, 18, WHITE, '#E7EEF1') # wash basin box(478, 300, 48, 48, 30, '#E3F4F8', '#C6E6EE') # shower glass box(605, 238, 110, 106, 11, '#FFFFFF', '#E9E4DA') # bed box(605, 238, 110, 8, 24, WOOD, '#9C7149', depth=239) # headboard for px in (612, 662): box(px, 250, 44, 18, 15, '#F4F4F4', '#E2E2E2') # pillows box(580, 238, 22, 22, 15, WOOD, '#9C7149') # nightstands box(580, 320, 22, 22, 15, WOOD, '#9C7149') box(18, 196, 30, 30, 11, '#3A3A3A', '#2A2A2A') # terrace table for cx, cy in ((8, 204), (50, 204)): box(cx, cy, 10, 12, 14, '#4A4A4A', '#333333') # terrace chairs # hob and sink on the kitchen counter extras = [] for hx, hy in ((378, 268), (390, 268), (378, 282), (390, 282)): X, Y = project(hx, hy, 17) extras.append(f'') X, Y = project(384, 318, 17) extras.append(f'') shapes.append((351, ''.join(extras))) # room names on the floors LABELS = {'wohnen': (180, 330, 'Wohnbereich'), 'kueche': (334, 300, 'Küche'), 'diele': (470, 232, 'Diele'), 'bad': (468, 264, 'Bad'), 'schlafen': (660, 300, 'Schlafzimmer'), 'terrasse': (34, 292, 'Terrasse')} labels = [] for key, (lx, ly, text) in LABELS.items(): X, Y = project(lx, ly) labels.append(f'{text}') shapes.sort(key=lambda s: s[0]) # rhododendron bushes on the lawn bush = [] for cx, cy, r in ((-14, 172, 20), (-18, 236, 18), (-10, 300, 22)): X, Y = project(cx, cy, 10) bush.append(f'') for i, (dx, dy) in enumerate(((-8, -5), (4, -8), (9, 2), (-3, 4), (-10, 5), (6, 8))): bush.append(f'') xs, ys = [], [] for x in (-40, 730): for y in (100, 395): for z in (0, 60): px, py = project(x, y, z) xs.append(px + OX); ys.append(py + OY) width, height = round(max(xs) + 20), round(max(ys) + 20) min_y = round(min(ys) - 10) svg = (f'' 'Grundriss der Ferienwohnung' + ''.join(floor_svg) + ''.join(s for _, s in shapes) + ''.join(bush) + ''.join(labels) + '') open(sys.argv[1], 'w', encoding='utf-8').write(svg) areas = {key: ' '.join(f'{round(project(x, y)[0] + OX, 1)},{round(project(x, y)[1] + OY, 1)}' for x, y in pts) for key, pts in ROOMS.items()} print(json.dumps({'viewBox': f'0 {min_y} {width} {height - min_y}', 'areas': areas}, indent=1))