# Tactiverge Academy — companion code for "What CAD is and why parametric design matters"
# Lesson: https://tactiverge.win/academy/mechanical-design/cad-fundamentals/what-is-cad/
# Licence: MIT (see https://tactiverge.win/open-engineering/). Examples appear in lesson order.

# ── Example 1 ────────────────────────────────────────
import math

def bracket(hole_d, hole_spacing, margin, thickness):
    """Derive a flat mounting plate from four design parameters (mm)."""
    length = hole_spacing + 2 * margin
    width = 2 * margin
    hole_area = math.pi * (hole_d / 2) ** 2
    volume = (length * width - 2 * hole_area) * thickness
    return length, width, volume

for hole_d in [3.4, 5.5]:
    length, width, volume = bracket(hole_d, hole_spacing=40, margin=3 * hole_d, thickness=4)
    print(f"hole {hole_d} mm -> plate {length:.1f} x {width:.1f} mm, volume {volume / 1000:.2f} cm³")
