Skip to content
AI-Ready Docs
/llms.txt/llms-mcp.txt

Hidden lines for drawings ​

A drawing view shows a part as lines: its edges and its outline, solid where they can be seen and dashed where something stands in front of them. projectBrepHiddenLines(breps, view, options) makes such a view from one or more B-reps. The view is orthographic: every point moves straight toward the viewer, along one direction. The result is a list of exact 2D curves (lines, elliptic arcs and polylines), each split into visible and hidden pieces, and each named after the edge or face it comes from.

The Drawings tab draws its front, top, right and isometric views this way, and sections and detail views start from the same projection. The method is in packages/barocss-cad/src/brep/brep-hidden-line.ts. The figures use a box with a round boss on top; their numbers come from the built kernel, or are worked out in the page where a figure says so.

The stages at a glance ​

StageWhat it doesWhere
1. CandidatesEvery edge but seams, coplanar and smooth joints; lines and circles projected exactlythe edge loop in projectBrepHiddenLines, arcOut
2. SilhouettesWhere a curved face's normal turns square to the view, from the tessellation's vertex normalsthe silhouette pass, chainSegments, simplify
3. OccludersEvery face's triangles, in view coordinates, in a uniform gridtriangleGrid
4. VisibilityEach curve sampled, each sample tested, the changes bisected into runsintervals, triangleGrid.covers
5. PrecedenceHidden runs lying on visible lines dropped; silhouettes along visible edges droppedsegmentGrid, the run passes
6. OutputEdges with their pieces, names and 3D ends; the drawing's extentthe end of projectBrepHiddenLines

The view is given by two directions: toward, from the model to the viewer, and up, the direction shown upwards (it need not be square to toward). Most tolerances scale with size, the diagonal of the box around every triangle of the B-reps.

1. Which curves are drawn ​

Each edge of the B-rep is a candidate, except:

  • a seam, an edge whose two sides belong to one face (where a closed surface meets itself);
  • an edge between two coplanar planar faces: |n₁·n₂| > 1 − 10⁻⁹ and the planes less than 10⁻⁶ × size apart;
  • a smooth joint: the two faces' normals at the edge's middle agree, to within 1° when both faces are planes or cylinders, and within 1.5 facet turns (1.5 × 90° / 12 by default) for normals read from the tessellation. Such a joint is drawn only where it lies on the outline (the normal square to the view, |n·toward| < 10⁻⁶): it is then a silhouette, named <edge>~sil. With tangentEdges the other smooth joints between different surfaces (a fillet's boundaries) are drawn too, marked tangent.
  • Between two facets of a mesh solid (an STL, a modelled thread) the joint counts as smooth within 20°; it is drawn only where one facet faces the viewer and the other faces away.

The curves are then projected. A point p goes to (p·right, p·up), with right = unit(up × toward) and the drawn up recomputed as toward × right. Projection is linear, so a straight edge stays the straight line between its ends' images, and a circular arc stays an exact curve:

3D curve2D curveExceptions
Line from A to Bline from P(A) to P(B)image shorter than 10⁻⁹ × size (seen end-on): left out
Circle c + r(e₁ cos t + e₂ sin t)arc: P(c) + U cos t + V sin t, U = r P(e₁), V = r P(e₂), from t₀ to t₁|U × V| ≤ 10⁻⁹ × max(|U|, |V|)²: seen edge-on, the line it covers
Any other edgepolyline through the tessellation's samples of the edge—

The arc is an ellipse unless U and V are square and equal, which is when the circle faces the viewer.

Which curves are drawn, and how they project
toward = (0.577, -0.577, 0.577) |U × V| = 36.95
1. The edges of the B-rep

Every edge of the part is a candidate. Three kinds are left out: a seam (both sides of the edge belong to one face), an edge between two coplanar planar faces, and a smooth joint, where the two faces' normals agree. Here the boss's wall is two faces of one cylinder, so its two straight joints (dashed) are left out: their normals agree exactly.

joint left out ⇔ |na·nb| > cos 1° (planes and cylinders)
All curves are drawn alike here; which pieces are visible is the next step. The joints' positions (x = 12 and 28 at y = 15) and the numbers in step 3 are the kernel's, read from the built package; the figure's rims are whole circles where the B-rep has two half circles each.

2. Silhouettes ​

A curved face also has an outline that is no edge of the B-rep: where the surface turns away from the viewer, its normal square to the view direction. The kernel finds it on the tessellation (segmentsPerQuarter, default 12 — see Tessellating a B-rep), face by face:

  1. At each vertex of the face's triangles, s = n·toward / |n|; a value within 10⁻⁹ of zero is zero.
  2. A triangle with one or two corners where s < 0 is crossed by the silhouette. On each of its two sides that change sign, the crossing is at the zero of s taken as linear: p = pᵢ + (pⱼ − pᵢ) sᵢ / (sᵢ − sⱼ). Each side's two ends are put in one order (by position) first, so the two triangles sharing a side compute the same point.
  3. The short segments are chained end to end (ends within 10⁻⁷ × size join), repeated and collinear points are dropped, and the chains are sorted by their middle point's place in the view. A face's chains are named <face>~sil0, ~sil1, ….

On a cylinder the vertex normals are used as the face's tessellation gives them, and each chain's points are moved onto the exact generator line c + a t ± r w, with w = unit(a × toward). The chain then has two points: an exact line. A cylinder seen along its axis (|a × toward| < 10⁻⁶) has no silhouette. Planar faces have none.

On other surfaces (spheres, tori, fillets, NURBS patches) a vertex's normal is first replaced by the sum of the normals of every vertex at the same point (on this face or a neighbouring one) that turns from it by at most 3 facet turns (3 × 90° / 12 = 22.5° by default). A silhouette crossing from one face to the next then meets itself at the shared edge. The result stays a polyline through the crossings. The groups of vertices at one point are found once per B-rep, keyed by their exact coordinates.

A cylinder's silhouette from its facets
along the axis (section)the viewarrow: to the viewerθ = 60° |a × toward| = 0.866 silhouettes: 2
1. Facets and their normals

The silhouette is found on the tessellation. Each vertex of a curved face's triangles has a normal; on a cylinder they point about straight out from the axis. The left panel looks along the axis: a row of triangles shows as the chords of the section, and a vertex column as one point.

The section has 2 facets a quarter (the kernel's default is 12) and φ = −22.5°; the view panel is drawn exactly, with the bottom rim's back half dashed as the kernel finds it hidden. Off cylinders the same crossings are kept as a polyline, with normals first averaged across neighbouring faces (see the text).

3. Visible or hidden ​

What hides a point. The occluders are every face's triangles, at the same tessellation, in view coordinates: x, y and a depth d = p·toward, larger nearer the viewer. Triangles seen edge-on (the cross product of two projected sides ≤ 10⁻¹² × size²) cover nothing and are left out. The rest go in a uniform grid of G × G cells over the view, G = round(√(n / 2)) kept between 4 and 128 for n triangles. A point p of a curve is hidden when some triangle in its cell covers P(p) (barycentric coordinates all ≥ −10⁻⁷) and the triangle's depth there, interpolated from its corners, is greater than p·toward + ε. This is a ray from p toward the viewer meeting a face: in the view the ray is one point, so the test is a point in a triangle and a depth comparison. ε is 10⁻⁵ × size.

Two exceptions keep a curve from being hidden by the facets it lies on. An arc is tested where the tessellation draws it, on its chord, not on the exact circle. A silhouette is not hidden by its own face's triangles close to it: on a cylinder, those less than 4 × the face's sag (plus ε) nearer; on other surfaces, those whose centre is within 2.5 × the face's longest facet side. A face's sag is the most its facets stand off the surface, estimated per facet side as length × normal turn / 8.

Where the answer changes. Each curve is sampled about every h = size / 300 along its image (a line: ⌈L / h⌉ steps; an arc: also at least one step per π/32 of its turn; at most 4000 steps). Between two samples whose answers differ, the change is found by bisection, at most 30 halvings or until the interval is 10⁻¹² of the parameter wide. The cuts divide the curve into runs. A run shorter than 2 × 10⁻³ × size in the view is joined to its neighbour; it is numerical noise at a tangency.

Visible lines take precedence. The passes run in an order. Visible runs of edges come first; then the silhouettes' visible runs, less any part lying on a visible edge; last, the hidden runs, less any part lying on visible ink. "On ink" means within 10⁻⁵ × size of a visible piece running the same way, to within 5°; a curve that merely crosses a visible one keeps its piece there. An edge all of whose runs are dropped comes back with no pieces: in a front view, the back edges of a box lie behind the front ones.

Visible or hidden: sample, test, bisect
samples: 25 of 25 (kernel: 181)
1. Samples along a curve

Each curve is sampled along its length, about every h = size / 300 in the view, size being the diagonal of the part's box. Here size = 54.6 mm, h = 0.18 mm, and this edge, 32.7 mm long in the view, gets 180 steps (181 samples); the figure shows 24 steps. An arc gets at least one sample every π/32 of its turn.

samples = ⌈L / h⌉ (at most 4000), h = size / 300
Steps 1–4 use 25 samples (the kernel: 181) and test each sample exactly against the boss's cylinder; the kernel tests against its triangles, so its second cut lands at x = 21.629 rather than the exact 21.626 (the top rim's facets sit just inside the circle). Steps 5–6 are the kernel's output for this part, rounded.

4. What comes out ​

FieldWhat it holds
right, up, towardThe view's unit vectors; a 2D point (x, y) is x·right + y·up in the model
edges[].nameThe edge's persistent name (n1.side0|n1.top), or <face>~sil<k> for a face's silhouette, <edge>~sil for a joint on the outline; prefixes[i] goes before each name of the i-th B-rep
edges[].kindline, circle, curve or silhouette; tangent: true for a smooth joint drawn with tangentEdges
edges[].endsIts 3D end points (none for a whole circle)
edges[].circleA circular edge's centre, radius, normal, whether it is whole, and its sweep
edges[].pieces{ curve, visible }: the curve a line, arc (centre, u, v, t₀, t₁) or polyline
min, maxThe box around every piece in the view

The back top edge of the figure's box, for instance, comes back as three lines:

json
{ "name": "b.side2|b.top", "kind": "line", "ends": [[40, 30, 10], [0, 30, 10]],
  "pieces": [
    { "visible": true,  "curve": { "kind": "line", "a": [49.497, 4.082],  "b": [32.749, 13.752] } },
    { "visible": false, "curve": { "kind": "line", "a": [32.749, 13.752], "b": [21.629, 20.172] } },
    { "visible": true,  "curve": { "kind": "line", "a": [21.629, 20.172], "b": [21.213, 20.412] } } ] }

Keeping it fast ​

ShortcutWhat is skippedWhy the answer is the same
One tessellation per B-rep and qualitytessellating the part again for each of a drawing's viewsthe mesh depends only on the B-rep and segmentsPerQuarter
Face geometry read once per facerecognising a face's plane or cylinder at every viewit depends only on the face
Triangle gridtesting a sample against triangles in other cellsa triangle outside a cell does not cover a point in it
Segment grid for visible inkcomparing a run with far visible piecesonly pieces within the cover distance count
Vertex groups found onceregrouping a face's vertices by position while averaging normalsthe groups are the same for every vertex; a copy per insert made it O(k²) (commit 29c323346, projection −11 %)

The bench case hidden-lines-tee in packages/barocss-cad/scripts/perf-bench.mjs projects a filleted pipe tee; the kernel performance report (apps/cad-studio/handover/notes/report-kernel-performance-2026-10-28.md) lists "hidden lines of a filleted tee" at 2.14 s before and 1.26 s after that round of changes.

Where it is in the code ​

FileResponsibility
packages/barocss-cad/src/brep/brep-hidden-line.tsprojectBrepHiddenLines: candidates, silhouettes, occluders, runs, output; arcOut, intervals, chainSegments, simplify, triangleGrid, segmentGrid, sameSurface
packages/barocss-cad/src/brep/brep-tessellate.tstessellateBrep (the triangles, vertex normals and edge polylines), circleOf (an edge's exact circle)
packages/barocss-cad/src/brep/analytic-boolean.tsfaceGeometry: a face's plane or cylinder
packages/barocss-cad-model/src/drawing/project.tsprojectViews: the drawing's standard views of the part
packages/barocss-cad-model/src/drawing/section.tsSection views, projected from the cut part

How it is checked ​

packages/barocss-cad/test/brep-hidden-line.test.mjs runs the built kernel on small parts:

  • a plate with a through hole in the front view: the outline visible, the hole as two exact hidden lines, the back edges and rims dropped on the outline;
  • the top view: the hole as an exact circle of radius 4 at its centre, and the persistent edge names with their 3D ends;
  • a cylinder seen at an angle: two exact silhouette generators the full height, and its base turning hidden at ±45° from the X axis, where the silhouettes meet it (to within 10⁻⁴ rad);
  • through a wide hole, the far rim of its bottom visible exactly where the sight line clears the top (to 0.01 rad);
  • a cylinder seen along its axis has no silhouette; side on, its rims are lines;
  • a torus seen along its axis: both silhouette circles visible, on the inner and outer equators to 0.05 mm;
  • one body hiding another behind it; prefixes telling copies apart; tangent edges on request; and the refusal of an up along toward.

In packages/barocss-cad-model/test/, drawing-detail.test.ts checks a detail view's hidden line of a hole at 5:1 and drawing-section-kinds.test.ts the visible and hidden walls of a half section.

Limits ​

  • Orthographic only. There is no perspective view.
  • Visibility comes from the tessellation. Cuts are exact where the occluding outline is a silhouette or an edge the facets meet, and otherwise within a facet's sag: in the figure the exact cut is at x = 21.626, the kernel's at 21.629, because the boss's top rim facets sit just inside the circle. A finer segmentsPerQuarter narrows it.
  • Only lines and circles are exact. Other edges and the silhouettes of non-cylindrical faces are polylines through the tessellation's points.
  • Changes between samples. Visibility is compared from one sample to the next, so a hidden or visible stretch shorter than the sample spacing h can be missed, and one shorter than 2 × 10⁻³ × size is joined to its neighbour.
  • Refused. An up parallel to toward (|unit(up × toward)| < 0.5) throws The view up direction is parallel to the view direction.