Skip to content

hertzforge.drawing.viz.geometry

geometry

Drawing decisions for geometry: what a figure needs to know, with none of the code that draws it.

Functions:

Name Description
color_text

A color index as a cell says it: the index and its color's name, '3 green'.

color_index

The color index a typed color names: a whole number from 0 (a name after it is

color_rgb

The RGB triple (0 to 1) of a color index, wrapping past 9.

axis_unit_text

The unit text the labeled axes show, such as '[mm]'. A

display_points

The coordinates to draw for a geometry, and the axis unit text.

element_shapes

(polygons, lines) one element is drawn by on its own, as its nodes: a face

element_cells

How the elements are drawn: (faces, lines, points), each keyed by

dof_axis

0, 1 or 2 for the axis of a DOF direction, or None if it has none.

dof_arrow_vectors

For each DOF, (node row, global direction, axis) for its arrow, or

dof_arrows_on

For each DOF, (node row of geometry, global direction, axis) for its arrow, or

dof_arrow_solids

The arrows of a shape3d: one solid arrow per DOF, length long, or each its own

dof_arrow_length

One length for every arrow on a plot: 12 % of extent, reduced to

Classes

Functions:

color_text

color_text(index: int) -> str

A color index as a cell says it: the index and its color's name, '3 green'.

color_index

color_index(text: str) -> int

The color index a typed color names: a whole number from 0 (a name after it is ignored, so '3 green' reads as 3), or a palette color's name.

color_rgb

color_rgb(index: int) -> tuple[float, float, float]

The RGB triple (0 to 1) of a color index, wrapping past 9.

axis_unit_text

axis_unit_text(geometry: Geometry, unit_system: UnitSystem) -> str

The unit text the labeled axes show, such as '[mm]'. A geometry whose units are undefined shows '[units undefined]' instead of a unit.

display_points

display_points(geometry: Geometry, unit_system: UnitSystem) -> tuple[ndarray, str]

The coordinates to draw for a geometry, and the axis unit text.

Coordinates are converted from SI to unit_system. A geometry whose units are undefined is drawn with the file's raw coordinates, because converting them would scale values whose unit is unknown, and its axis text says the units are undefined.

element_shapes

element_shapes(code: int, conn: Sequence[int]) -> tuple[list[list[int]], list[list[int]]]

(polygons, lines) one element is drawn by on its own, as its nodes: a face element its corner nodes (face_corners), a solid every face of its cell (solid_faces), a line element its first two nodes, a point element nothing. element_cells draws every element from these, and the 3-D view highlights one element by them.

element_cells

element_cells(geometry: Geometry, indices: Sequence[int] | None = None, separate_skins: bool = False) -> tuple

How the elements are drawn: (faces, lines, points), each keyed by element color, with every entry given as node rows (positions in node_id), not node ids; with separate_skins, (faces, lines, points, skins), the solids' skins kept apart from the face elements so a scene can draw them see-through.

A face element is drawn as its corner nodes (face_corners), since a quad8's midside nodes are not corners of the outline. A solid is drawn as the outer surface of its color: each cell's faces (solid_faces), less every face that two cells share. A line element is its first two nodes, and a point element is its nodes. The 3-D view, the report's scenes and the HTML export all use this one function.

Parameters:

Name Type Description Default
geometry Geometry

The geometry.

required
indices sequence of int

Which elements, by row; every element when omitted.

None
separate_skins bool

Return the solids' skins as a fourth dict instead of among the faces.

False

Returns:

Type Description
tuple of dict

Faces and lines as lists of row lists, points as a row list, each by element color; and the skins, when asked for.

dof_axis

dof_axis(direction: str) -> int | None

0, 1 or 2 for the axis of a DOF direction, or None if it has none.

A rotation counts as its axis: 'RZ-' is 2, and draws blue like 'Z+'.

dof_arrow_vectors

dof_arrow_vectors(geometry: Geometry, dofs: Sequence[str]) -> list[tuple[int, ndarray, int] | None]

For each DOF, (node row, global direction, axis) for its arrow, or None for a DOF at a node the geometry lacks or with no axis.

The direction is turned by the node's displacement coordinate system the same way the animation turns the motion (deform.dof_directions), so '101X+' on a node measured in a turned system points along that system's X. A rotational DOF points along its axis, turned the same way. The axis, which picks the color, is the DOF's own letter, not the nearest global axis.

dof_arrows_on

dof_arrows_on(geometry: Geometry, dofs: Sequence[str], measured_on: Geometry | None = None, distance: float | None = None) -> list[tuple[int, ndarray, int]]

For each DOF, (node row of geometry, global direction, axis) for its arrow, or ValueError naming the DOFs that have no place on geometry.

measured_on is the geometry whose node ids the DOFs name. When it is None or geometry itself the ids are geometry's own (dof_arrow_vectors). Otherwise each DOF's node is found on measured_on, its direction turned by that node's displacement system there, and the arrow is drawn at the node of geometry nearest it, as DOF Mapping matches a test geometry to a model (core.correlate.project_shapes): no further than distance (meters when the units are defined), or the match distance (core.correlate.match_distance) when none is given. A test's node 101 is usually some other node of a finite element mesh, so the ids are never read across two geometries.

dof_arrow_solids

dof_arrow_solids(xyz: ndarray, drawn: Sequence[tuple[bool, tuple[int, ndarray, int]]], length: float | Sequence[float], labels: Sequence[str]) -> dict[str, Any]

The arrows of a shape3d: one solid arrow per DOF, length long, or each its own length when length holds one per arrow. drawn is (points in, (node row, direction, axis)) per arrow; an arrow pointing in ends on its node, the others start there. tails f32 [A, 3] is where each starts, directions f32 [A, 3] the unit vector it points along, and axes u8 [A] the DOF's own axis (0 X, 1 Y, 2 Z), which picks its color. With one length each they are lengths f32 [A], and length is the longest. labels names each arrow's DOF and inward u8 [A] is 1 for an arrow that points in, so a label can sit at the end away from the node. A caller whose arrows move with the model adds follow u32 [A], the row of the view's nodes whose motion each arrow takes.

dof_arrow_length

dof_arrow_length(points: ArrayLike, extent: float) -> float

One length for every arrow on a plot: 12 % of extent, reduced to 0.9 times the closest spacing of the arrowed points so that arrows on closely spaced nodes do not overlap.