Closed-form ray diagrams: object, focal points, three construction rays and the computed image — all from lens/mirror parameters.
A textbook ray diagram needs the optical centre, focal points, and three construction rays whose intersections fix the image. Writing that geometry by hand is error-prone — in the Diagram DSL you declare the physics and the engine solves every ray path.
lens takes the optical centre cx/cy, focal length
f, object distance u and height h_obj.
The image distance comes from the thin-lens equation — object on the left,
real inverted image on the right when u > f:
canvas 480x260 lens l1 cx=240 cy=130 f=90 u=170 h_obj=60 lens_h=150
Every part is anchored — F_left, F_right,
obj_top, img_top, rayN:t — so labels and
extra construction lines can attach exactly:
canvas 480x260 lens l1 cx=240 cy=130 f=90 u=170 h_obj=60 lens_h=150 label f1 pos=l1.F_left+(0,-14) text="F" size=13 label f2 pos=l1.F_right+(0,-14) text="F" size=13 label im pos=l1.img_top+(10,0) text="image" size=11
mirror works the same way with radius of curvature
R (F = R/2). Add convex=1 for a convex
mirror — the rays diverge and the virtual image appears behind it:
canvas 480x260 mirror m1 cx=380 cy=130 R=140 u=210 h_obj=55 half_deg=35
prism solves Snell's law at both faces — give apex angle
A, refractive index mu and incidence angle
i; the emergent ray and deviation angle are computed:
canvas 480x260 prism p1 cx=240 base_y=190 A=60 mu=1.5 i=45 size=170
axis:t and rayN:t place marks
anywhere along a ray — e.g. l1.ray2:0.5.u past f to show the virtual-image case —
the geometry updates automatically.dashed=1 on extra lines for construction rays.