Skip to content

New shapes: Line and Line2D#383

Merged
JonathanMaes merged 11 commits into
3.11.2from
feature/line-shape
Mar 18, 2026
Merged

New shapes: Line and Line2D#383
JonathanMaes merged 11 commits into
3.11.2from
feature/line-shape

Conversation

@JonathanMaes

Copy link
Copy Markdown
Contributor

As suggested by @Mat1629, this PR adds two new shapes to create lines. This can be convenient for, e.g., defining 3D ASI structures.

Line(x1, y1, z1, x2, y2, z2, diam, linecap) generates a line from $(x_1, y_1, z_1)$ to $(x_2, y_2, z_2)$ with a diameter diam. The behavior of the line at these two endpoints is determined by the last argument linecap, which can be

  • "infinite": the line extends indefinitely beyond the two specified points.
  • "round": a sphere of radius diam is placed at the two endpoints, yielding a smooth shape.
  • "flat": the line stops abruptly at the two endpoints in a flat plane perpendicular to the line.

Line2D(x1, y1, x2, y2, diam, linecap) behaves the same, but extends indefinitely along the Z-axis. Hence, this basically creates a plane in 3D space whose normal vector always lies in the XY-plane.

A special case was implemented for diam=0, in which case the shape will be a minimally connected geometry of all cells intersected by the line.

Warning

If a diam=0 line is scaled or rotated afterwards, it is no longer guaranteed that this shape is fully connected, since the shape function then has no way of knowing what cells it would eventually intersect.

Visual examples

Below are some geometries from test/line.mx3 (but after an additional relax()).

Line Line2D
"round" image image
"flat" image image
"infinite" image image
"infinite" with diam=0 image image

@JonathanMaes JonathanMaes added this to the 3.12 milestone Mar 14, 2026

@JLeliaert JLeliaert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for the line cap is 0, which returns an error message
type mismatch: can not use type int as string

@JLeliaert

Copy link
Copy Markdown
Contributor

A special case was implemented for diam=0, in which case the shape will be a minimally connected geometry of all cells intersected by the line.

When the line goes exactly through the corner, single precision leads to situations where a cell that should be selected is not, so that the geometry is no longer a face-connected set but is missing a "bridge" cell between two corner-connected cells.

see this example in 2D with a line along the diagonal
image

Adding a small buffer fixes this
if tmax < tmin-1e-15 {
image

@JonathanMaes
JonathanMaes merged commit 80e163b into 3.11.2 Mar 18, 2026
@JonathanMaes
JonathanMaes deleted the feature/line-shape branch March 18, 2026 14:57
@JonathanMaes JonathanMaes mentioned this pull request Mar 18, 2026
4 tasks
Comment thread engine/shape.go
Comment thread engine/shape.go
Comment thread engine/shape.go
Comment thread engine/shape.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants