Sketch Vase
Lofted vase: three constraint-sketched sections (a rounded square at the foot, a wider belly, a narrow neck) skinned smoothly and hollowed out from the top.
examples/sketch-vase.tsx on GitHub
bunx tscad dev examples/sketch-vase.tsx/**
* Lofted vase: three constraint-sketched sections (a rounded square at the foot, a wider
* belly, a narrow neck) skinned smoothly and hollowed out from the top.
*
* tscad dev examples/sketch-vase.tsx
*/
import { defineParams, type ParamValues } from "tscad"
export const params = defineParams({
height: { type: "number", default: 120, min: 60, max: 250, step: 1, unit: "mm", label: "Height" },
foot: { type: "number", default: 60, min: 30, max: 120, step: 1, unit: "mm", label: "Foot width" },
belly: { type: "number", default: 90, min: 40, max: 160, step: 1, unit: "mm", label: "Belly width" },
neck: { type: "number", default: 40, min: 20, max: 100, step: 1, unit: "mm", label: "Neck width" },
roundness: { type: "number", default: 0.3, min: 0.1, max: 0.45, step: 0.01, label: "Corner roundness" },
wall: { type: "number", default: 2.4, min: 1, max: 6, step: 0.1, unit: "mm", label: "Wall" },
})
/**
* A w × w square with corners rounded to r, centred: four lines and four tangent arcs,
* drawn once as a constraint sketch and reused for every section.
*/
function RoundedSquare({ w, r, z }: { w: number; r: number; z: number }) {
return (
<sketch z={z}>
<point id="c" fixed />
<line id="bottom" from="b0" to="b1" horizontal tangent />
<arc id="se" from="b1" to="r0" tangent="bottom" radius={r} />
<line id="right" from="r0" to="r1" vertical tangent />
<arc id="ne" from="r1" to="t0" tangent="right" equal="se" />
<line id="top" from="t0" to="t1" horizontal tangent />
<arc id="nw" from="t1" to="l0" tangent="top" equal="se" />
<line id="left" from="l0" to="l1" vertical tangent />
<arc id="sw" from="l1" to="b0" tangent="left" equal="se" />
<dimension a="b0" b="top" distance={w} />
<dimension a="r0" b="left" distance={w} />
<symmetric a="b0" b="t0" about="c" />
</sketch>
)
}
export default function Vase(p: ParamValues<typeof params>) {
const r = (w: number) => w * p.roundness
// the hollow is a second loft through the same sections inset by the wall (a boolean is
// sturdier than offsetting the skin); cap the wall so every inset section stays rounded
const wall = Math.min(p.wall, 0.5 * r(Math.min(p.foot, p.belly, p.neck)), p.height / 10)
const inner = (w: number) => ({ w: w - 2 * wall, r: r(w) - wall })
return (
<part name="vase" color="#7c9cbf">
<difference>
<loft>
<RoundedSquare w={p.foot} r={r(p.foot)} z={0} />
<RoundedSquare w={p.belly} r={r(p.belly)} z={p.height * 0.45} />
<RoundedSquare w={p.neck} r={r(p.neck)} z={p.height} />
</loft>
<loft>
<RoundedSquare {...inner(p.foot)} z={wall} />
<RoundedSquare {...inner(p.belly)} z={p.height * 0.45} />
<RoundedSquare {...inner(p.neck)} z={p.height + wall} />
</loft>
</difference>
</part>
)
}