volmdlr_tools.parametrics package#
The parametric descriptions recognition produces: the kinds a sketch can draw and the parameters of each, the projection a wire is read through, and the measurements that fit an arrangement to a set of positions.
Everything here reads geometry: points, wires and the frames they are projected onto. Nothing in it knows how a feature is recognised or how code for a shape is written, which is what lets recognition and the code that redraws a shape read one definition rather than each carrying its own.
Submodules#
volmdlr_tools.parametrics.profiles module#
Classification of closed planar wires into parametric profile shapes.
A closed planar outline is walked once and matched against the shapes a sketch can
draw directly, giving a ProfileShape that names the kind and carries its
parameters — or None when the outline is not one of them.
Five kinds are recognised, tried in this order:
rectangle— four sides, right corners, at any rotation.regular_polygon— equal sides on a common circle, at any rotation.slot— two parallel sides capped by tangent half circles.rectangle_rounded— a rectangle whose four corners carry one fillet radius.fillet_polyline— any other closed outline whose corners all carry one radius.
Precedence matters where two kinds could both match: a rectangle is reported as a
rectangle rather than as a four-sided regular polygon, and a rounded rectangle as
rectangle_rounded rather than as a fillet_polyline that happens to be
rectangular. An outline containing a spline, a whole circle, corners of differing
radii, or sides that do not meet end to end is not one of these kinds and yields
None, which is an ordinary answer rather than a failure.
The kind names and the meaning of each field are the contract with the code that draws each kind as a single sketch primitive, so they are not free to change on their own.
This is the one place that vocabulary is defined. Emission reads a shape off a payload and recognition puts one there, so both sides name the same kinds and the same fields, and a second copy of them could only drift: a kind added to one and not the other would be advertised by a classifier that can never return it, or returned by one whose consumer cannot draw it.
Classification works on a wire already projected onto its sketch frame, as
wire_edge_tuples() produces:
project first, then call classify_edge_tuples(). A caller holding projected
edges already needs only the second.
- class volmdlr_tools.parametrics.profiles.ProfileShape(kind: Literal['rectangle', 'regular_polygon', 'slot', 'rectangle_rounded', 'fillet_polyline', 'hull'], center: tuple[float, float], width: float | None = None, height: float | None = None, radius: float | None = None, side_count: int | None = None, rotation_deg: float = 0.0, corner_radius: float | None = None, points: tuple[tuple[float, float], ...] | None = None, radii: tuple[float, ...] | None = None)#
Bases:
objectOne recognised profile shape, in sketch-plane coordinates.
Which fields carry a value depends on
kind:kind
fields that carry a value
rectanglecenter,width,height,rotation_degregular_polygoncenter,radius,side_count,rotation_degslotcenter,width,height,rotation_degrectangle_roundedcenter,width,height,rotation_deg,corner_radiusfillet_polylinecenter,points,corner_radiushullcenter,points,radii- Parameters:
kind – Which of the five shapes this is.
center –
(cx, cy)the shape is positioned by. For every kind butfillet_polylinethis is the shape’s own centre; forfillet_polylineit is the mean ofpoints, which is not the outline’s centroid unless the outline happens to be symmetric.fillet_polylineis drawn frompointsalone, so itscenterpositions nothing and is only a handle for grouping.width – Extent along the rotation direction. For
slot, the overall length including both caps.height – Extent across the rotation direction. For
slot, the width across the caps, which is twice the cap radius.radius – Distance from
centerto a vertex of a regular polygon.side_count – Number of sides of a regular polygon.
rotation_deg – Rotation of the shape about
center, in degrees. Canonical in[0, 90)forrectangleandrectangle_rounded, whose quarter turns are the same shape with width and height exchanged; in[0, 180)forslot, whose half turns are the same shape; and in[0, 360)forregular_polygon, measured to its first vertex.corner_radius – The one radius every rounded corner carries.
points – The corners a
fillet_polylineis drawn through, in order. These are the sharp corners the outline would have had unrounded, not points on the outline itself. For ahullthey are the centres of its circles.radii – The radius of each circle of a
hull, one per point.
- center: tuple[float, float]#
- corner_radius: float | None = None#
- height: float | None = None#
- kind: Literal['rectangle', 'regular_polygon', 'slot', 'rectangle_rounded', 'fillet_polyline', 'hull']#
- points: tuple[tuple[float, float], ...] | None = None#
- radii: tuple[float, ...] | None = None#
- radius: float | None = None#
- rotation_deg: float = 0.0#
- side_count: int | None = None#
- width: float | None = None#
- volmdlr_tools.parametrics.profiles.classify_edge_tuples(edges_2d: list[tuple[str, dict]], *, extent: float | None = None) ProfileShape | None#
Return the shape
edges_2ddraws, orNonewhen it is not one of the five.- Parameters:
edges_2d – Ordered
(edge_type, data)tuples, aswire_edge_tuples()produces."line"carriesstartandend;"arc"carriesstart,midandend, and carriesradiuswhen it projected as a circle rather than an ellipse. Any other edge type — a whole"circle", or an"unsupported"curve — means the outline is not one of these shapes.extent – The extent of the part the outline belongs to, when known: see
length_tolerance().
- Returns:
The recognised shape, or
None.
- volmdlr_tools.parametrics.profiles.hull_profile(edges_2d: list[tuple[str, dict]], *, extent: float | None = None) ProfileShape | None#
Return the convex hull of circles that
edges_2ddraws, orNonewhen it is not one.The outline is a hull of circles when it alternates arcs and straight sides, every side runs tangent to the arcs on either end of it, and all the arcs turn the same way. The circles are those the arcs belong to. This is not one of the kinds
classify_edge_tuples()returns: it is asked for by a caller that knows its outline is a plate drawn round a few circles, such as a flange round its hub and its bolt lobes.- Parameters:
edges_2d – Ordered
(edge_type, data)tuples, as forclassify_edge_tuples().extent – The extent of the part the outline belongs to, when known: see
length_tolerance().
- Returns:
A
hullshape whosepointsandradiiare the circles in order round the outline, orNone.
- volmdlr_tools.parametrics.profiles.length_tolerance(edges_2d: list[tuple[str, dict]], extent: float | None = None) float#
Return the length under which two lengths of this outline count as equal.
It is a fixed share of the outline’s extent, the diagonal of the box its edges’ end points and middle points fit in, so an outline gets the same verdict in any unit. Projection uses it as well, to drop an edge too short to be told from a point, so the two cannot disagree.
- Parameters:
edges_2d – Ordered
(edge_type, data)tuples, as forclassify_edge_tuples().extent – The extent of the part the outline belongs to, when known, such as the diagonal of its bounding box. The share is then taken of the larger of the two extents, so a small outline is judged as the part’s other lengths are rather than more tightly.
- Returns:
The tolerance, zero for an outline with no extent and no part extent given.
- volmdlr_tools.parametrics.profiles.reframe_profile_shape(shape: ProfileShape, from_frame: Frame3D, to_frame: Frame3D) ProfileShape#
Re-express a shape measured in one sketch frame in another frame.
centerandpointsare carried through 3D;rotation_degis carried by transporting the direction it names. Rectangle-family kinds keep rotation canonical by exchanging width and height, so a shape square to its frame stays square to the new one after a quarter-turn change of frame.The two frames must describe the same plane, or planes parallel to it: only the in-plane position and direction are mapped, while
width,height,radiusandcorner_radiusare carried across untouched. A frame whose third axis is not parallel to the original’s would need those re-measured, which this cannot do, so the caller is responsible for not asking.
volmdlr_tools.parametrics.projection module#
Describe the edges of a wire as the primitives a sketch draws.
One projection, used wherever a wire is read on a plane — whether it is about to be drawn or about to be classified. Two projections would let the same wire be measured one way for recognition and another for emission, and a profile that classified as one shape but drew as another would be the result.
- volmdlr_tools.parametrics.projection.project_edge(ocp_edge: object, frame: Frame3D) list[tuple[str, dict]]#
Describe one edge of a shape as the sketch primitives that draw it.
One edge usually gives one primitive. A B-spline gives one spline through its knots when that is the curve it is, and one primitive per Bézier segment otherwise. Every wire walked for a sketch comes through here, so no kind of edge can be handled in one sketch and misread in another.
- Returns:
The primitives, empty when the edge contributes nothing to the sketch.
- volmdlr_tools.parametrics.projection.wire_edge_tuples(wire: object, frame: Frame3D, *, extent: float | None = None) list[tuple[str, dict]]#
Walk a wire in order and describe each edge on
frameas a sketch primitive.The projection every sketch is read through, so a wire is described the same way wherever it is read — whether it is about to be drawn or about to be classified by
classify_edge_tuples(). It lives besideproject_edge(), which does the per-edge work.An edge whose two ends coincide once projected is dropped: it draws nothing, and left in it would read as an extra vertex. The threshold is the classifier’s own
length_tolerance(), taken over the wire as projected, so an edge too short for the classifier to tell apart from a point never reaches it, in whatever unit the wire is measured.- Parameters:
wire – A volmdlr wire.
frame – Sketch-plane frame the edges are projected onto.
extent – The extent of the part the wire belongs to, when known, as for
length_tolerance(). Pass the same one to the classifier.
- Returns:
Ordered
(edge_type, data)tuples.
volmdlr_tools.parametrics.pattern_math module#
Fitting a set of points to the arrangement that repeats them.
A circle through scattered centres, the shortest spacing that explains a ring, the two directions a grid runs in: the measurements that turn a set of positions into a pattern. Plain coordinates in, parameters out — nothing here knows what sits at those positions, which is what lets both the code that finds patterns and the code that redraws them measure the same way.
- volmdlr_tools.parametrics.pattern_math.compute_grid_coords(pts_2d: ndarray, origin: ndarray, u: ndarray, v: ndarray, tol_fraction: float = 0.01) list[tuple[int, int]] | None#
Check all points lie on integer grid coordinates.
- Parameters:
pts_2d – Nx2 array of 2D points.
origin – 2D origin point.
u – First basis vector.
v – Second basis vector.
tol_fraction – Relative tolerance for grid-snap check.
- Returns:
List of (i, j) integer coordinates, or None if any point is off-grid.
- volmdlr_tools.parametrics.pattern_math.find_fundamental_spacing(deltas: ndarray, angle_tol: float = 2.0) float | None#
Find the fundamental angular spacing from consecutive angle deltas.
All deltas must be positive integer multiples of the fundamental spacing.
The candidate fundamental is the mode of the deltas (the mean of the most-populated tolerance bin), not the min. The mode is robust against a single near-coincident pair producing a tiny outlier delta that would otherwise hijack a min-based pick and cause every real delta to fail the integer-ratio test.
- Parameters:
deltas – Array of consecutive angular differences (degrees).
angle_tol – Tolerance in degrees for angle comparisons.
- Returns:
Fundamental spacing in degrees, or None if no regular pattern.
- volmdlr_tools.parametrics.pattern_math.find_grid_basis(pts_2d: ndarray, collinear_tol: float = 0.01) tuple[ndarray, ndarray, int] | None#
Find two non-collinear basis vectors from shortest pairwise distances.
- Parameters:
pts_2d – Nx2 array of 2D points.
collinear_tol – Relative cross-product threshold for collinearity.
- Returns:
(u, v, origin_index) or None.
- volmdlr_tools.parametrics.pattern_math.fit_circle_kasa(xs: ndarray, ys: ndarray) tuple[float, float, float] | None#
Algebraic circle fit (Kasa method).
Near-collinear input makes the algebraic solver return a geometrically valid but practically useless huge-radius circle. The radius/bbox guard below rejects those fits before they reach a downstream consistency check (which would pass — the points really do lie on that huge circle).
- Parameters:
xs – X coordinates of points.
ys – Y coordinates of points.
- Returns:
(cx, cy, r) or None on failure / degenerate fit.
volmdlr_tools.parametrics.features module#
The parameters a recognised feature is described by, and the patterns that repeat it.
These records are the vocabulary the code that reads a feature and the code that redraws it share: a hole’s steps measured from its entry, a boss’s outline and blends, a pocket’s depth, a groove’s profile, the profiles an extruded body was drawn from, the profile a turned body was turned from, and the lines, grids, circles and mirrors features repeat in. They are plain frozen data in the units of the part, and depend on nothing but geometry.
- class volmdlr_tools.parametrics.features.AdditionParameters(frame: Frame3D, outline: Loop2D, length: float, face_ids: frozenset[int], end_face_ids: frozenset[int])#
Bases:
objectMaterial added to a part by extruding a profile straight along a direction.
With one end face, the extrusion starts where its walls meet the rest of the part and ends at that face, and its direction is that face’s outward normal. With two, it starts at the one of the lower face number and runs towards the other.
- Parameters:
frame – The frame of the profile: its origin is on the plane the extrusion starts from, its third axis is the direction the extrusion goes in, from its start to its end, and its first two axes span the plane the profile is drawn in.
outline – The outer boundary of the profile in frame, counter-clockwise. A window through the addition is a feature of its own.
length – The distance from the start of the extrusion to its end, along its direction; greater than zero.
face_ids – The faces read.
end_face_ids – The faces among face_ids that close the addition at its start or at its end.
- property direction: Vector3D#
The direction the extrusion goes in, from its start to its end.
- end_face_ids: frozenset[int]#
- face_ids: frozenset[int]#
- frame: Frame3D#
- kind: Literal['addition'] = 'addition'#
- length: float#
- class volmdlr_tools.parametrics.features.BaseSurface(kind: Literal['plane', 'cylinder'], origin: Point3D, axis: Vector3D, radius: float | None = None, face_ids: tuple[int, ...] = ())#
Bases:
objectThe surface a feature stands on or opens in.
- Parameters:
kind –
"plane"or"cylinder".origin – A point on the surface; on a cylinder, a point on its axis.
axis – The unit normal pointing out of the material for a plane, the unit axis for a cylinder.
radius – The radius of a cylinder,
Nonefor a plane.face_ids – The faces of the part that lie on the surface.
- axis: Vector3D#
- face_ids: tuple[int, ...] = ()#
- kind: Literal['plane', 'cylinder']#
- origin: Point3D#
- radius: float | None = None#
- class volmdlr_tools.parametrics.features.BlendParameters(radius: float, widest_radius: float, certain: bool, vexity: Literal['convex', 'concave'] | None, edges: tuple[WorkedEdge, ...], stops_at: frozenset[int], after: tuple[int, ...], layer: int, face_ids: frozenset[int])#
Bases:
objectA round worked on edges of a part: a fillet filling inside corners, or a round taking outside edges off.
- Parameters:
radius – The radius the round is made with, in the units of the part; where it varies along the round, the smallest.
widest_radius – The largest radius along the round: radius again for a round of one radius.
certain –
Truewhen every radius was read off the geometry of the round or measured when it was recognised;Falsewhen one was only estimated from how its face curves.vexity – Which way the edges it rounds turned,
Nonewhen that cannot be told.edges – The edges the round was worked on, each where two faces of the part met; a corner where the round turns from one edge onto the next names none.
stops_at – The faces of the part the round runs into at its ends, which it is not tangent to.
after – The records of the rounds of a larger radius this one runs on over where they meet, which are made before it, by their position in the document.
layer – How many rounds of a larger radius come before this one, each running on over the one before:
0for a round that runs on over none.face_ids – The faces of the round.
- after: tuple[int, ...]#
- certain: bool#
- edges: tuple[WorkedEdge, ...]#
- face_ids: frozenset[int]#
- kind: Literal['blend'] = 'blend'#
- layer: int#
- radius: float#
- stops_at: frozenset[int]#
- property varying: bool#
Whether the radius changes along the round by more than a twentieth of itself.
- vexity: Literal['convex', 'concave'] | None#
- widest_radius: float#
- class volmdlr_tools.parametrics.features.BlendRadius(value: float, certain: bool, face_ids: tuple[int, ...])#
Bases:
objectThe radius of a blend and how far it can be trusted.
- Parameters:
value – The radius, in the units of the part: as read when it is certain, and rounded to the value a designer would have typed when it is not.
certain –
Truewhen the radius was read off the geometry of the blend faces or measured when the blend was recognised;Falsewhen it is estimated from curvature, which is what a spline blend allows, or when the faces of the blend disagree.face_ids – The blend faces the radius was read from.
- certain: bool#
- face_ids: tuple[int, ...]#
- value: float#
- volmdlr_tools.parametrics.features.BodyParameters = volmdlr_tools.parametrics.features.ExtrudedBodyParameters | volmdlr_tools.parametrics.features.RevolvedBodyParameters#
The parameters of a body the part was made from: a profile extruded, or a profile turned.
- class volmdlr_tools.parametrics.features.BossParameters(base: BaseSurface, frame: Frame3D, outlines: tuple[Loop2D, ...], draft_angle: float, face_ids: frozenset[int], tilt: float, height: float, root_blend: BlendRadius | None, top_blend: BlendRadius | None, top_face_ids: frozenset[int] = frozenset({}), until: Literal['height', 'next', 'plane'] = 'height', top_plane: BaseSurface | None = None, *, host_face_ids: frozenset[int] = frozenset({}), breaks: tuple[EdgeBreak, ...] = ())#
Bases:
_PrismBaseA boss or pad: an outline drawn on its base and extruded to a top.
- Parameters:
height – The distance from the base to the top along the frame’s third axis.
root_blend – The blend where the boss meets its base,
Nonewhen sharp.top_blend – The rounding of the top edges,
Nonewhen sharp.top_face_ids – The faces of the top.
until –
"height"when the boss stops at its own top, height above its base;"next"when it rises until it meets the part, which is its top, and height is only how far that is on average;"plane"when its top is a plane leaning from its base, top_plane, and height is how high its walls reach, under the highest point of that top. Such a boss is its outline carried height along the frame’s third axis, then cut back to the plane, as a wedge rising from its base to a sloping top is.top_plane – The plane the boss is cut back to when until is
"plane": a point of it and its normal out of the material, with the faces of the top;Noneotherwise.
- property circular: bool#
Whether the boss is one circle.
- height: float#
- kind: Literal['boss'] = 'boss'#
- root_blend: BlendRadius | None#
- top_blend: BlendRadius | None#
- top_face_ids: frozenset[int] = frozenset({})#
- top_plane: BaseSurface | None = None#
- until: Literal['height', 'next', 'plane'] = 'height'#
- class volmdlr_tools.parametrics.features.ChamferParameters(distances: tuple[float, float], vexity: Literal['convex', 'concave'], edges: tuple[WorkedEdge, ...], face_ids: frozenset[int])#
Bases:
objectA chamfer worked on edges of a part: a face cut across each edge, or filling an inside corner.
- Parameters:
distances – How far the chamfer cuts back along each of the two faces of the edges it was worked on, the shorter first, in the units of the part; along a face of an inside corner, how far it reaches up it.
vexity – Which way the edges it was worked on turned: an inside bevel filling a corner is
"concave".edges – The edges the chamfer was worked on, each where two faces of the part met, the face the shorter distance runs along first; a corner where the chamfer turns from one edge onto the next names none.
face_ids – The faces of the chamfer.
- property distance: float#
The distance of a chamfer cut back equally, the mean of its two distances.
- distances: tuple[float, float]#
- edges: tuple[WorkedEdge, ...]#
- property equal: bool#
Whether the chamfer cuts back as far along each face, to within a twentieth of the longer distance.
- face_ids: frozenset[int]#
- kind: Literal['chamfer'] = 'chamfer'#
- vexity: Literal['convex', 'concave']#
- class volmdlr_tools.parametrics.features.EdgeBreak(kind: Literal['chamfer', 'blend'], size: float | None, face_ids: frozenset[int], edges: tuple[RimEdge, ...])#
Bases:
objectThe chamfers or blends along a feature’s rim, of one size.
- Parameters:
kind –
"chamfer"for faces cut square to the bisector of the edge,"blend"for rounded ones.size – How far the break reaches along each face it joins,
Nonewhen it is not the same on both.face_ids – The faces that make the break.
edges – The sharp edges the break stands for.
- face_ids: frozenset[int]#
- kind: Literal['chamfer', 'blend']#
- size: float | None#
- class volmdlr_tools.parametrics.features.ExtrudedBodyParameters(profiles: tuple[ExtrudedProfile, ...], face_ids: frozenset[int])#
Bases:
objectThe profiles an extruded body or a slab of the part was drawn from, one per stretch, from the lowest up.
A body extruded in one go gives one profile; a body read as several slabs stacked along its direction, as a stepped plate, gives one per slab, each with its own outlines, drafts and levels.
- Parameters:
profiles – The profiles, from the lowest along their common direction up; never empty.
face_ids – The faces read.
- property direction: tuple[float, float, float]#
The unit direction the profiles are extruded along.
- face_ids: frozenset[int]#
- kind: Literal['extruded_body'] = 'extruded_body'#
- property levels: tuple[float, float]#
Where the body starts and stops along its direction, as
ExtrudedProfile.levelsmeasures it.
- profiles: tuple[ExtrudedProfile, ...]#
- class volmdlr_tools.parametrics.features.ExtrudedProfile(frame: Frame3D, levels: tuple[float, float], loops: tuple[ProfileLoop, ...], ends: tuple[Literal['cap', 'parent', 'read'], Literal['cap', 'parent', 'read']], tolerance: float, parting_level: float | None = None, left_out: tuple[str, ...] = ())#
Bases:
objectThe profile one extruded body or slab was drawn from, and how far it is extruded.
- Parameters:
frame – The plane the outlines are drawn in: its
waxis is the unit direction the profile is extruded along, its origin lies on that line at the level the outlines were read at.levels – Where the profile starts and stops along the direction, measured from the origin of space in the model’s own length units; the start is the lower.
loops – The outlines, the outer outlines first.
ends – What closes the profile at its start, and at its end.
tolerance – How far an outline may stand off the walls it was read from.
parting_level – For a slab of a run of slabs that leave the mould the same way, the level of the plane their walls are drafted about: below the run when it is pulled out along the direction, above it otherwise.
Nonewhen the walls are drafted from where the profile is drawn.left_out – Why the profile gives less than the part’s section does, one reason each: an outline of it that is not in the profile, or a section that could not be cut, at the slab or at a neighbour its parting level was read with; empty when the profile holds every outline and every section was cut.
- property complete: bool#
Whether the profile holds every outline of the part’s section at it, every section read having been cut.
- property direction: tuple[float, float, float]#
The unit direction the profile is extruded along.
- property drawn_at: float#
The level of the plane the outlines are drawn in.
- ends: tuple[Literal['cap', 'parent', 'read'], Literal['cap', 'parent', 'read']]#
- frame: Frame3D#
- property holes: tuple[ProfileLoop, ...]#
The holes in the material.
- property islands: tuple[ProfileLoop, ...]#
The islands of material standing in a hole.
- left_out: tuple[str, ...] = ()#
- levels: tuple[float, float]#
- loops: tuple[ProfileLoop, ...]#
- loops_at(level: float) tuple[Loop2D, ...]#
Return the outlines carried along their walls to another level, each edge by its own draft.
An outline whose edges, each carried by its own draft, no longer meet, as a straight wall beside a corner leaning a little more, is carried by its own draft as a whole instead.
- Parameters:
level – Where to carry them, as
levelsmeasures it.- Returns:
One outline per loop of the profile, in order, in the frame’s
(u, v)axes.- Raises:
FeatureRecognitionError – When an outline cannot be carried that far, as when it shrinks to nothing.
- property outlines: tuple[ProfileLoop, ...]#
The outer outlines, one per separate piece of material.
- parting_level: float | None = None#
- property release: Literal['up', 'down'] | None#
The way the profile leaves the mould:
"up"along its direction,"down"against it.An outline that shrinks along the direction and a hole that widens both let the material out along it.
Nonewhen no wall leans by half a degree or more, or walls lean both ways.
- tolerance: float#
- exception volmdlr_tools.parametrics.features.FeatureParameterError#
Bases:
ValueErrorRaised when a recognised feature cannot be read as parameters.
The message names the feature’s faces and says what they do not satisfy, so the feature can be inspected or handed to another reader.
- volmdlr_tools.parametrics.features.FinishingParameters = volmdlr_tools.parametrics.features.BlendParameters | volmdlr_tools.parametrics.features.ChamferParameters#
The parameters of the work done on a part’s edges last.
- volmdlr_tools.parametrics.features.FinishingVexity#
Which way the edge a round or a chamfer was worked on turned:
"convex"for an outside edge, cut back or rounded off;"concave"for an inside corner, filled.alias of
Literal[‘convex’, ‘concave’]
- class volmdlr_tools.parametrics.features.GridRepeat(members: tuple[int, ...], origin: Point3D, direction_x: Vector3D, direction_y: Vector3D, spacing_x: float, spacing_y: float, count_x: int, count_y: int)#
Bases:
objectIdentical features on a rectangular lattice.
- Parameters:
members – Indices of the features, row by row along the first direction.
origin – Anchor of the corner feature with the smallest indices.
direction_x – Unit direction of the first lattice axis.
direction_y – Unit direction of the second lattice axis.
spacing_x – Spacing along the first axis.
spacing_y – Spacing along the second axis.
count_x – Features along the first axis.
count_y – Features along the second axis.
- count_x: int#
- count_y: int#
- direction_x: Vector3D#
- direction_y: Vector3D#
- kind: Literal['grid'] = 'grid'#
- members: tuple[int, ...]#
- origin: Point3D#
- spacing_x: float#
- spacing_y: float#
- class volmdlr_tools.parametrics.features.GrooveParameters(axis_origin: Point3D, axis: Vector3D, frame: Frame3D, profile: Loop2D, opens_on: BaseSurface, face_ids: frozenset[int], full_turn: bool = True)#
Bases:
objectA groove cut about an axis: a profile turned through a whole revolution and taken from the part.
- Parameters:
axis_origin – The point of the axis halfway along the groove.
axis – Unit direction of the axis.
frame – The frame of the meridian half plane: its first axis is the radial direction the profile is drawn towards, its second axis the direction of the groove’s axis, its origin the point halfway along it.
profile – The closed meridian profile in that frame, as (radius, axial position): the groove’s walls closed by a line on the surface the groove opens in.
opens_on – The surface the groove is cut into.
face_ids – The faces of the groove.
full_turn – Whether the groove runs the whole way round,
Falsewhen windows cut through its walls.
- axis: Vector3D#
- axis_origin: Point3D#
- face_ids: frozenset[int]#
- frame: Frame3D#
- full_turn: bool = True#
- kind: Literal['groove'] = 'groove'#
- opens_on: BaseSurface#
- class volmdlr_tools.parametrics.features.HoleStack(origin: Point3D, axis: Vector3D, entry: BaseSurface, steps: tuple[HoleStep, ...], through: bool, interruptions: tuple[Interruption, ...], face_ids: frozenset[int], entry_face_id: int | None = None, entry_planar: bool = True)#
Bases:
objectA round hole read from its entry.
- Parameters:
origin – The point where the axis meets the entry plane. When the hole names the face it opens through, entry_face_id, it is a point of the part, where the axis meets that face.
axis – Unit direction of the axis, pointing into the material.
entry – The plane the hole is drilled from, with its normal pointing out of the material: the plane of the flat face the hole opens through, or, when it opens through a curved face, the plane square to the axis through origin, which touches that face only there.
steps – The stretches of the profile in order of depth. A wall reaching out past the entry, on the side where the face the hole opens through falls away from the axis, starts at the entry.
through – Whether the hole leaves the part at the far end.
interruptions – The faces that cross the hole.
face_ids – Every face the hole is made of.
entry_face_id – The face of the part the hole opens through, the one its axis meets at origin;
Nonewhen the hole is not read so, as one whose axis meets no face beside its walls at its mouth.entry_planar – Whether the face the hole opens through is flat.
Falsefor a curved one, as the cone under a turned disc or the round of a shaft: the entry plane then only touches it at origin.
- axis: Vector3D#
- property bore: HoleStep | None#
The narrowest cylinder of the hole, the one the other steps are cut around.
Nonefor a hole with no cylinder, such as a countersink alone.
- property depth: float#
The depth of the deepest step, to the tip of a drill point.
- entry: BaseSurface#
- entry_face_id: int | None = None#
- entry_planar: bool = True#
- face_ids: frozenset[int]#
- interruptions: tuple[Interruption, ...]#
- kind: Literal['hole'] = 'hole'#
- origin: Point3D#
- step_of(kind: Literal['chamfer', 'countersink', 'counterbore', 'bore', 'taper', 'drill_point', 'recess']) HoleStep | None#
Return the first step of a kind, or
None.
- through: bool#
- class volmdlr_tools.parametrics.features.HoleStep(kind: Literal['chamfer', 'countersink', 'counterbore', 'bore', 'taper', 'drill_point', 'recess'], start_depth: float, end_depth: float, start_diameter: float, end_diameter: float, face_ids: tuple[int, ...])#
Bases:
objectOne stretch of a hole’s profile, measured from the entry plane along the axis.
- Parameters:
kind – What the stretch does:
"chamfer"or"countersink"a cone widening to the entry, a chamfer when it widens the bore by at most a third of the bore’s radius,"counterbore"the wide cylinder at the entry that a narrower one follows through a flat shoulder,"bore"any other cylinder,"recess"a wider cylinder away from the entry,"taper"a cone inside the hole,"drill_point"the cone ending a blind hole, or the cone narrowing to the far end of a hole whose drill point broke out through the part.start_depth – Depth at which the stretch starts.
end_depth – Depth at which the stretch ends.
start_diameter – Diameter at the start.
end_diameter – Diameter at the end;
0for a drill point that comes to a tip, the width of the opening for one that broke out through the part.face_ids – The faces of the part the stretch is made of.
- end_depth: float#
- end_diameter: float#
- face_ids: tuple[int, ...]#
- property included_angle_degrees: float | None#
The angle in degrees between the opposite generators of a cone,
0for a cylinder.Nonefor a stretch with no length, which has no angle to read.
- kind: Literal['chamfer', 'countersink', 'counterbore', 'bore', 'taper', 'drill_point', 'recess']#
- property length: float#
The length of the stretch along the axis.
- property radial_size: float#
How far the stretch’s diameter changes, counted on the radius.
- start_depth: float#
- start_diameter: float#
- class volmdlr_tools.parametrics.features.Interruption(start_depth: float, end_depth: float, face_ids: tuple[int, ...])#
Bases:
objectFaces that cross a hole and break its wall, such as a slot cut through it.
- Parameters:
start_depth – Depth at which the crossing faces begin along the hole’s axis.
end_depth – Depth at which they end.
face_ids – The crossing faces.
- end_depth: float#
- face_ids: tuple[int, ...]#
- start_depth: float#
- class volmdlr_tools.parametrics.features.LinearRepeat(members: tuple[int, ...], origin: Point3D, step: Vector3D)#
Bases:
objectIdentical features at equal steps along a line.
- Parameters:
members – Indices of the features among those given, in order along the line.
origin – Anchor of the first feature.
step – The vector from one feature to the next.
- property count: int#
The number of features.
- kind: Literal['linear'] = 'linear'#
- members: tuple[int, ...]#
- origin: Point3D#
- step: Vector3D#
- class volmdlr_tools.parametrics.features.MirrorRepeat(members: tuple[int, int], plane_origin: Point3D, plane_normal: Vector3D)#
Bases:
objectTwo identical features mirrored across a plane.
- Parameters:
members – Indices of the two features: the original first.
plane_origin – A point on the mirror plane.
plane_normal – Unit normal of the mirror plane.
- kind: Literal['mirror'] = 'mirror'#
- members: tuple[int, int]#
- plane_normal: Vector3D#
- plane_origin: Point3D#
- class volmdlr_tools.parametrics.features.PocketParameters(base: BaseSurface, frame: Frame3D, outlines: tuple[Loop2D, ...], draft_angle: float, face_ids: frozenset[int], tilt: float, depth: float, floor_blend: BlendRadius | None, rim_blend: BlendRadius | None, floor_face_ids: frozenset[int] = frozenset({}), from_floor: bool = False, through: bool = False, *, host_face_ids: frozenset[int] = frozenset({}), breaks: tuple[EdgeBreak, ...] = ())#
Bases:
_PrismBaseA pocket: an outline drawn on its base and cut to a floor.
- Parameters:
depth – The distance from the base to the floor along the direction into the material.
floor_blend – The blend between the walls and the floor,
Nonewhen sharp.rim_blend – The rounding of the pocket’s rim on its base,
Nonewhen sharp.floor_face_ids – The faces of the floor.
from_floor –
Truewhen the frame sits on one end of the cut and the cut runs outward from it along the frame’s third axis, because the floor does not lie parallel to the base and the pocket has no one depth, or because the cut starts at a level that is not on the base.through – Whether the cut leaves the part at both ends, a window rather than a pocket with a floor; depth is then the distance through the part.
- property circular: bool#
Whether the pocket is one circle.
- depth: float#
- floor_blend: BlendRadius | None#
- floor_face_ids: frozenset[int] = frozenset({})#
- from_floor: bool = False#
- kind: Literal['pocket'] = 'pocket'#
- rim_blend: BlendRadius | None#
- through: bool = False#
- class volmdlr_tools.parametrics.features.PolarRepeat(members: tuple[int, ...], center: Point3D, axis: Vector3D, radius: float, start_angle_degrees: float, angular_spacing_degrees: float, full_circle: bool, reference: Vector3D, rotated: bool = False)#
Bases:
objectIdentical features at equal angles on a circle.
- Parameters:
members – Indices of the features, in order of increasing angle from the first.
center – The centre of the circle.
axis – Unit normal of the circle’s plane.
radius – The circle’s radius.
start_angle_degrees – Angle of the first feature in degrees, from reference.
angular_spacing_degrees – Angle between neighbours in degrees.
full_circle – Whether the features go all the way round.
reference – Unit direction in the circle’s plane from which start_angle_degrees is measured.
rotated – Whether each copy is turned about the axis as far as it is carried round it, as a flat on a nut or a hole drilled towards the axis is; a round feature on a circle is not.
- angular_spacing_degrees: float#
- axis: Vector3D#
- center: Point3D#
- property count: int#
The number of features.
- full_circle: bool#
- kind: Literal['polar'] = 'polar'#
- members: tuple[int, ...]#
- radius: float#
- reference: Vector3D#
- rotated: bool = False#
- start_angle_degrees: float#
- volmdlr_tools.parametrics.features.ProfileEnd#
What closes a profile at one of its levels:
"cap", flat faces square to its direction;"parent", the body it stands on or is cut into, which it meets there and is carried into;"read", neither, as at a rim a blend rounds, where the level is the end of the stretch the walls were read over.alias of
Literal[‘cap’, ‘parent’, ‘read’]
- class volmdlr_tools.parametrics.features.ProfileLoop(loop: Loop2D, role: Literal['outline', 'hole', 'island'], depth: int, draft_angle: float, edge_drafts: tuple[float, ...], edge_face_ids: tuple[int | None, ...] = ())#
Bases:
objectOne outline of a profile, as it is drawn and as its walls lean.
- Parameters:
loop – The outline, counter-clockwise, in the
(u, v)axes of the profile’s frame.role – What the outline is: see
ProfileLoopRole.depth – How many other outlines of the profile enclose it.
draft_angle – How far the outline’s walls lean, in radians, as the middle of its edges’ drafts weighed by length: positive when the outline grows along the profile’s direction, a hole widening as an outline does; zero when its walls stand straight.
edge_drafts – The draft of each edge of the outline, in order and signed as draft_angle.
edge_face_ids – The face of the part each edge of the outline runs along, in order: the wall it was cut from, a wall another record may hold, as a slot opening on the outline;
Nonefor an edge that bridges a gap the walls leave. Empty when the walls are not read, as for a slab.
- depth: int#
- draft_angle: float#
- edge_drafts: tuple[float, ...]#
- edge_face_ids: tuple[int | None, ...] = ()#
- property face_ids: frozenset[int]#
The faces of the part the outline runs along, its walls; empty when they are not read.
- property is_hole: bool#
Whether the outline is a hole in the material.
- role: Literal['outline', 'hole', 'island']#
- property uniform: bool#
Whether every edge of the outline leans by the outline’s draft, to within half a degree.
- volmdlr_tools.parametrics.features.ProfileLoopRole#
What an outline of a profile is: the outer outline of a piece of material, a hole in the material, or an island of material standing in a hole.
alias of
Literal[‘outline’, ‘hole’, ‘island’]
- volmdlr_tools.parametrics.features.ProfileRelease#
The way a profile leaves the mould:
"up"along its direction,"down"against it.alias of
Literal[‘up’, ‘down’]
- class volmdlr_tools.parametrics.features.RevolvedBodyParameters(frame: Frame3D, chains: tuple[RevolvedChain, ...], angle: float, face_ids: frozenset[int])#
Bases:
objectThe profile a turned body of the part was turned from, the axis it was turned about, and how far round.
The profile is drawn in the half plane the turn starts from, as
(t, r):talong the axis from the frame’s origin,rthe distance from the axis, never negative. A point(t, r)of the profile is the pointorigin + t u + r vof space before it is turned.- Parameters:
frame – The frame of the half plane: its origin lies on the axis, its
uaxis is the unit direction of the axis, itsvaxis the radial direction the turn starts from, and itswaxis,ucrossed withv, the way the profile turns from there.chains – The pieces of the profile, none crossing itself or another; never empty. A corner a chamfer of the part bevels is sharp: the chamfer is worked on the circle it turns into afterwards.
angle – The angle the profile is turned through, in radians, from
vtowardsw: a whole turn, or less for a body turned only part of the way round.face_ids – The faces read.
- Raises:
ValueError – When there is no chain, or the angle is not more than nothing and at most a whole turn.
- angle: float#
- property axis: Vector3D#
The unit direction of the axis, along which
tgrows.
- property axis_origin: Point3D#
The point of the axis where
tis zero.
- chains: tuple[RevolvedChain, ...]#
- face_ids: frozenset[int]#
- frame: Frame3D#
- property full_turn: bool#
Whether the profile is turned the whole way round.
- kind: Literal['revolved_body'] = 'revolved_body'#
- property profile: tuple[Primitive2D, ...]#
The lines and arcs of every chain, chain after chain.
- class volmdlr_tools.parametrics.features.RevolvedChain(primitives: tuple[Primitive2D, ...], closed: bool)#
Bases:
objectOne connected piece of the profile a body was turned from, in the
(t, r)axes of its frame.- Parameters:
primitives – The lines and arcs of the piece, each starting where the one before ends.
closed – Whether the piece returns to where it starts. One that does not runs from the axis out and back to the axis, and is closed along the axis when it is turned.
- closed: bool#
- primitives: tuple[Primitive2D, ...]#
- class volmdlr_tools.parametrics.features.RimEdge(midpoint: Point3D, direction: Vector3D | None = None, circle_center: Point3D | None = None, circle_radius: float | None = None, circle_axis: Vector3D | None = None, length: float | None = None)#
Bases:
objectThe sharp edge a feature’s wall makes where an edge break takes it away.
- Parameters:
midpoint – Middle of the edge as it would be without the break.
direction – Unit direction of a straight edge,
Nonefor a curved one.circle_center – Centre of the circle a circular edge lies on,
Nonefor any other edge.circle_radius – Radius of that circle.
circle_axis – Unit normal of that circle’s plane.
length – Length of the edge.
- circle_axis: Vector3D | None = None#
- circle_center: Point3D | None = None#
- circle_radius: float | None = None#
- direction: Vector3D | None = None#
- length: float | None = None#
- midpoint: Point3D#
- volmdlr_tools.parametrics.features.STRAIGHT_DRAFT = 0.008726646259971648#
A wall leaning by less than this, in radians, off the direction a profile is extruded along stands straight.
- class volmdlr_tools.parametrics.features.SlotParameters(base: BaseSurface, frame: Frame3D, outlines: tuple[Loop2D, ...], draft_angle: float, face_ids: frozenset[int], tilt: float, shape: ProfileShape, depth: float, through: bool, floor_blend: BlendRadius | None, rim_blend: BlendRadius | None, symmetric: bool = False, *, host_face_ids: frozenset[int] = frozenset({}), breaks: tuple[EdgeBreak, ...] = ())#
Bases:
_PrismBaseA slot: two parallel sides closed by half circles, cut to a floor or through the part; or a slit.
A slit (symmetric) is a thin cut that two parallel walls bound and that is open on every other side, such as a saw cut. It is drawn and cut the other way round from a slot: its shape is a rectangle drawn in the plane midway between its walls, and it is cut across that plane by its depth, half on either side.
- Parameters:
shape – The slot as a profile shape in the frame: its centre, overall length, width and rotation; a slit’s is the rectangle covering its walls.
depth – The distance from the base to the floor, or to the far side of the part; a slit’s is the distance between its walls.
through – Whether the slot runs through the part.
floor_blend – The blend between the walls and the floor,
Nonewhen sharp or through.rim_blend – The rounding of the slot’s rim,
Nonewhen sharp.symmetric –
Truefor a slit, whose frame lies midway between its walls and is cut half its depth to either side.
- depth: float#
- floor_blend: BlendRadius | None#
- kind: Literal['slot'] = 'slot'#
- rim_blend: BlendRadius | None#
- shape: ProfileShape#
- symmetric: bool = False#
- through: bool#
- volmdlr_tools.parametrics.features.VARYING_RADIUS = 0.05#
Two radii of a round, or two distances of a chamfer, that differ by less than this share of the larger are one.
- class volmdlr_tools.parametrics.features.WorkedEdge(face_ids: tuple[int, int], sharp: RimEdge | None, break_face_ids: frozenset[int])#
Bases:
objectAn edge of the part a round or a chamfer was worked on: the two faces that met along it, and where it ran.
- Parameters:
face_ids – The two faces of the part that met along the edge before it was worked, which the round or the chamfer now joins. A round names them lower number first; a chamfer names first the face its shorter distance runs along, the lower number first when its distances are equal.
sharp – Where the edge ran before it was worked: where the two faces, carried on past the round or the chamfer, meet.
Nonewhen that cannot be told, as where the faces run on tangent to each other.break_face_ids – The faces of the round or the chamfer that took this edge away.
- break_face_ids: frozenset[int]#
- face_ids: tuple[int, int]#
- volmdlr_tools.parametrics.features.anchor(record: HoleStack | BossParameters | PocketParameters | SlotParameters | GrooveParameters) Point3D#
Return the point a feature is placed by.
That is where a hole’s axis meets its entry, the origin of a pad’s frame, and the point of a groove’s axis.
- volmdlr_tools.parametrics.features.is_circle(loop: Loop2D) bool#
Whether an outline is one whole circle.
- volmdlr_tools.parametrics.features.mould_release(walls: Iterable[tuple[float, bool]]) Literal['up', 'down'] | None#
Return the way a profile leaves the mould from how its walls lean,
Nonewhen they do not say.An outline that shrinks along the direction and a hole that widens both let the material out along it.
- Parameters:
walls – Each wall of the profile as its draft angle, in radians, and whether it is a wall of a hole.
- Returns:
"up"along the direction of the profile,"down"against it;Nonewhen no wall leans bySTRAIGHT_DRAFTor more, or walls lean both ways.
volmdlr_tools.parametrics.curves2d module#
Plain 2D geometry for outlines read off plane sections.
An outline is a closed chain of Primitive2D — straight segments, circular arcs and arcs
of ellipses. Each segment or circular arc lies on a Carrier, the infinite line or full
circle it was cut from.
Carriers are what matter when comparing outlines: a blend or a boss changes where a primitive
starts and stops but not the carrier of its neighbours, and two walls of one sheet lie on
carriers that are offsets of each other.
The module is numpy only. Sampled curves come in through fit_points() and
fit_piecewise(); primitives read in no particular order are chained into closed loops by
assemble_loops(); exact outlines are rebuilt from carriers through junction_point()
and rebuild_chain(); offset_pairing() says which carriers of one outline are offsets
of which carriers of another.
- class volmdlr_tools.parametrics.curves2d.Carrier(kind: Literal['line', 'circle'], point: tuple[float, float] | None = None, direction: tuple[float, float] | None = None, center: tuple[float, float] | None = None, radius: float | None = None)#
Bases:
objectThe infinite line or full circle a primitive lies on.
A line is given by
point, a point of the line where it was observed, and a unitdirectionwhose first non-zero component is positive, so one line has one direction whichever way it was travelled. A circle is given bycenterandradius.Two lines are compared where they were observed, never at a fixed place such as the origin of the plane: two walls that lean apart by a fraction of a degree are as far apart as they are where the outline has them, wherever the outline lies.
- center: tuple[float, float] | None = None#
- classmethod circle(center: tuple[float, float], radius: float) Carrier#
Return the circle of the given center and radius.
- direction: tuple[float, float] | None = None#
- distance_to(point: tuple[float, float]) float#
Return how far point is from this carrier.
- kind: Literal['line', 'circle']#
- classmethod line(through: tuple[float, float], direction: tuple[float, float]) Carrier#
Return the line passing through a point along direction.
- nearest_point(point: tuple[float, float]) tuple[float, float]#
Return the point of this line nearest to point, the foot of the perpendicular from it.
- Raises:
SectionError – when the carrier is a circle.
- point: tuple[float, float] | None = None#
- radius: float | None = None#
- class volmdlr_tools.parametrics.curves2d.Loop2D(primitives: tuple[Primitive2D, ...])#
Bases:
objectA closed outline: ordered primitives, each ending where the next begins.
- contains(point: tuple[float, float]) bool#
Return whether point lies inside the outline, by counting crossings of a ray.
- crossing() tuple[float, float] | None#
Return a point where the outline meets itself away from its joints, or
Nonewhen it is a simple loop.Pieces may meet only where one ends and the next begins. Two others that cross, touch or run over one another make a loop that bounds no region. Pieces that continue one another along a line, and a tangent blend, are simple.
- distances_to(points: ndarray) ndarray#
Return how far each of the
(n, 2)points is from the outline.
- property is_ccw: bool#
Return whether the loop runs counter-clockwise.
- property length: float#
Return the perimeter.
- merged(tol: float) Loop2D#
Return the loop with consecutive primitives on one carrier merged into one.
The seam between the last and first primitive is merged too.
- primitives: tuple[Primitive2D, ...]#
- sample(n: int = 400) ndarray#
Return about n points spread along the perimeter, for comparing outlines.
- property signed_area: float#
Return the enclosed area, positive when the loop runs counter-clockwise.
Exact: the polygon through the primitives’ ends plus the segment each arc, of a circle or of an ellipse, adds or takes away.
- class volmdlr_tools.parametrics.curves2d.OffsetPairing(pairs: tuple[tuple[int, int], ...], mid_carriers: tuple[Carrier, ...], unpaired_a: tuple[int, ...], unpaired_b: tuple[int, ...], distance: float)#
Bases:
objectWhich carriers of one outline are offsets of which carriers of another.
pairsholds(index in a, index in b); an index can occur twice when a carrier is interrupted and so appears as several primitives.mid_carriers[k]lies halfway between the carriers ofpairs[k].distanceis the common offset.unpaired_aandunpaired_bare the primitives of each outline that are an offset of no carrier of the other at that distance.- distance: float#
- pairs: tuple[tuple[int, int], ...]#
- unpaired_a: tuple[int, ...]#
- unpaired_b: tuple[int, ...]#
- class volmdlr_tools.parametrics.curves2d.Primitive2D(kind: Literal['line', 'arc', 'ellipse'], start: tuple[float, float], end: tuple[float, float], center: tuple[float, float] | None = None, radius: float | None = None, ccw: bool | None = None, closed: bool = False, minor_radius: float | None = None, rotation: float = 0.0)#
Bases:
objectA straight segment, a circular arc or an arc of an ellipse, travelled from
starttoend.An arc carries its
center,radiusand senseccw.closedmarks the full circle: its ends coincide and it turns through a whole revolution however close the two ends happen to be, so a circle whose ends differ by rounding is not read as an arc of zero sweep.An arc of an ellipse (
kind="ellipse") carries the same, withradiusits major radius,minor_radiusits minor one androtationthe angle in radians from the first axis to its major axis. Its angles are those of the ellipse’s own parametrisation,center + radius cos(a) major + minor_radius sin(a) minor, andclosedmarks the whole ellipse.- carrier() Carrier#
Return the line or circle this primitive lies on.
- Raises:
SectionError – For an arc of an ellipse, which lies on neither.
- ccw: bool | None = None#
- center: tuple[float, float] | None = None#
- closed: bool = False#
- ellipse_coordinates(point: tuple[float, float]) tuple[float, float]#
Return
(cos(a), sin(a))of a point of an ellipse: its offsets along the axes over their radii.
- end: tuple[float, float]#
- property is_full_circle: bool#
Return whether the primitive is a whole circle.
- kind: Literal['line', 'arc', 'ellipse']#
- left_normal_at(fraction: float) tuple[float, float]#
Return the unit normal a fraction of the way along the primitive, to the left of the way it is travelled.
- property length: float#
Return the length of the primitive.
- midpoint() tuple[float, float]#
Return the point halfway along the primitive.
- minor_radius: float | None = None#
- point_at(fraction: float) tuple[float, float]#
Return the point a fraction of the way along the primitive: of its length, of its angle for an arc.
- radius: float | None = None#
- reversed() Primitive2D#
Return the same primitive travelled the other way.
- rotation: float = 0.0#
- sample(n: int) ndarray#
Return n points evenly spread along the primitive, both ends included: the points of
point_at().
- start: tuple[float, float]#
- property sweep: float#
Return the signed angle an arc turns through, positive when counter-clockwise.
- tangent_at(fraction: float) tuple[float, float]#
Return the unit direction of travel a fraction of the way along the primitive.
- tangent_at_end() tuple[float, float]#
Return the unit direction of travel at the end.
- tangent_at_start() tuple[float, float]#
Return the unit direction of travel at the start.
- to_edge_tuple() tuple[str, dict]#
Return the primitive in the sketch edge vocabulary of
volmdlr_tools.parametrics.
- exception volmdlr_tools.parametrics.curves2d.SectionError#
Bases:
ValueErrorRaised when the outline of a section cannot be read as closed 2D geometry.
It is a
ValueErrorbecause the input geometry is what is wrong, not the call: an open chain of edges, two carriers that never meet, or a plane that lies along a face. The message names the location of the failure so the section can be inspected.
- volmdlr_tools.parametrics.curves2d.assemble_loops(primitives: list[Primitive2D], tol: float) list[Loop2D]#
Chain unordered primitives into closed loops by matching their ends.
Primitives are turned around as needed. Ends match when they are within tol.
- Raises:
SectionError – when a chain runs out of primitives before it closes.
- volmdlr_tools.parametrics.curves2d.carrier_offset(a: Primitive2D, b: Primitive2D, tol: float = 1e-06) float | None#
Return the signed distance from the carrier of a to the carrier of b.
Positive when b lies outward of a, to the right of a’s direction of travel on a counter-clockwise loop, and negative when it lies inward; a wall that leans outward from one level to the next has a positive offset. Concentric circles and parallel lines are offsets of each other; anything else has none. Lines are measured halfway between the middles of the two primitives, so the offset does not depend on where the outline lies.
- Parameters:
a – primitive of the outline at one level, travelled counter-clockwise.
b – primitive of the outline at the other level.
tol – distance within which circles count as concentric.
- Returns:
the offset, or
Nonewhen the carriers are not offsets of one another.
- volmdlr_tools.parametrics.curves2d.distances_to(points: ndarray, primitives: tuple[Primitive2D, ...] | list[Primitive2D]) ndarray#
Return how far each of the
(n, 2)points is from the nearest of primitives, ends included.
- volmdlr_tools.parametrics.curves2d.fit_piecewise(points: ndarray, tol: float, min_points: int = 5) list[Primitive2D]#
Fit ordered points with as few lines and arcs as hold to within tol.
A curve that no single line or arc follows — a tilted section of a cylinder, a B-spline — is split where it leaves its chord furthest and each half is fitted again. Neighbouring pieces that land on the same carrier are merged back into one.
- Parameters:
points –
(N, 2)samples in travel order.tol – largest distance from the fitted curves any sample may have.
min_points – below this many samples a piece that fits neither is kept as straight segments between its samples instead of being split further.
- Returns:
primitives in travel order, each ending where the next begins.
- volmdlr_tools.parametrics.curves2d.fit_points(points: ndarray, tol: float) Primitive2D | None#
Fit ordered points with one line or one arc, or return
Nonewhen neither holds.A line is preferred whenever every sample lies within tol of it, so the gentle arcs a curve fit leaves behind on straight walls come back as lines. Otherwise a circle is fitted and accepted when every sample lies within tol of it. Samples that return to their start give a full circle.
- Parameters:
points –
(N, 2)samples in travel order.tol – largest distance from the fitted curve any sample may have.
- Returns:
the fitted primitive, ending on the first and last sample.
- volmdlr_tools.parametrics.curves2d.junction_point(a: Carrier, b: Carrier, hint: tuple[float, float], tol: float = 1e-06) tuple[float, float]#
Return where two consecutive carriers of an outline meet.
Carriers that touch without crossing — a blend tangent to its neighbour — meet at the tangent point. Carriers that cross meet at the crossing nearest hint, the place the outline was observed to turn.
- Parameters:
a – carrier before the junction.
b – carrier after it.
hint – where the junction was observed, used to pick among crossings.
tol – distance within which carriers count as touching.
- Raises:
SectionError – when the carriers do not meet.
- volmdlr_tools.parametrics.curves2d.merge_primitives(primitives: list[Primitive2D], tol: float, cyclic: bool = False) list[Primitive2D]#
Merge consecutive primitives whose union is still one line or one arc to within tol.
A smooth curve that a fit broke into many short pieces comes back as the single line or arc it really is. Every candidate is tested against the samples of the original pieces, so merging cannot drift by more than tol from them however long the run. The cost is linear in the number of primitives.
- Parameters:
primitives – primitives in travel order, each ending where the next begins.
tol – largest distance the merged curve may have from the pieces it replaces.
cyclic – whether the last primitive is followed by the first, so the seam can merge too.
- volmdlr_tools.parametrics.curves2d.mid_carrier(first: Carrier, second: Carrier) Carrier#
Return the carrier midway between two offset carriers of the same kind.
Concentric circles give the circle of the mean radius; parallel lines give the line halfway between them.
- volmdlr_tools.parametrics.curves2d.offset_loop(loop: Loop2D, distance: float | Sequence[float], tol: float) Loop2D#
Move every primitive of loop by distance to the right of its travel, then rejoin them.
A line moves sideways and an arc changes radius about its centre, so on a counter-clockwise outline a positive distance moves it outward. This is what a draft does to a section over a change of height. distance may also give one distance per primitive, in order, for an outline whose walls lean by different drafts.
- Raises:
SectionError – When an arc shrinks to nothing, or the outline holds an arc of an ellipse, whose offset is no ellipse.
ValueError – When the distances given are not one per primitive.
- volmdlr_tools.parametrics.curves2d.offset_pairing(loop_a: Loop2D, loop_b: Loop2D, tol: float, *, min_paired_fraction: float = 0.5, min_pairs: int = 2, allow_zero: bool = False) OffsetPairing | None#
Find the one distance by which the carriers of loop_b are offsets of loop_a’s.
Every pair of same-kind carriers — concentric circles, parallel lines — that run the same way round their outlines proposes a distance, measured outward from loop_a; the distance backed by the most primitive length wins, so a boss or a blend that has no partner cannot outvote the walls. Carriers that agree with the winning distance are paired; the rest are reported as unpaired on their own side.
A distance backed by a few chance pairs is not an offset of the outlines: the pairing is only returned when it covers min_paired_fraction of the length of both loops and pairs at least min_pairs carriers (fewer when a loop has fewer primitives, as a circle has one).
- Parameters:
loop_a – one outline.
loop_b – an outline expected to be an offset of loop_a by a constant distance.
tol – distance within which carriers count as concentric, and offsets as equal.
min_paired_fraction – least share of each loop’s length that must be paired.
min_pairs – least number of paired carriers.
allow_zero – also pair carriers that coincide, so the same wall at two levels of an undrafted part pairs at distance zero.
- Returns:
the pairing, or
Nonewhen no carriers are offsets of each other or the winning distance is not backed widely enough.
- volmdlr_tools.parametrics.curves2d.rebuild_chain(carriers: list[Carrier], hints: list[tuple[float, float]], senses: list[bool | None], tol: float = 1e-06) Loop2D#
Rebuild a clean closed loop from an ordered cyclic list of carriers.
Every junction is computed from the two carriers it joins, so noise and interruptions in a measured outline drop out and the result is exact geometry.
- Parameters:
carriers – carriers in travel order; the last joins the first.
hints –
hints[i]is where carrieriwas observed to meet carrieri + 1.senses – counter-clockwise flag of each arc carrier as travelled,
Nonefor lines.tol – distance within which carriers count as touching.
- volmdlr_tools.parametrics.curves2d.snap_junctions(primitives: list[Primitive2D], tol: float, anchors: list[tuple[float, float] | None] | None = None) list[Primitive2D]#
Make each primitive of a closed chain end exactly where the next begins.
Fitted primitives stray from the outline they were fitted to, so their ends do not quite meet. Junction
k, between primitivekand the next, is placed at the crossing of the two carriers when that lies within a few tol of where the outline was observed to turn, and at the observed point otherwise.- Parameters:
primitives – closed chain in travel order; the last joins the first.
tol – the fitting tolerance.
anchors –
anchors[k]is a measured position of junctionk, orNoneto use the midpoint of the two ends.
Module contents#
The parametric descriptions recognition produces and emission consumes.
A recognised profile has to be named in terms the code that redraws it can use, and a repeated feature has to be described by where its copies sit. Both sides therefore need one vocabulary, and this package is where it is defined — not beside either of them, so that neither can extend it alone and leave the other unable to read the result.
Everything here reads geometry: points, wires and the frames they are projected onto. Nothing in it knows how a feature is recognised or how code for a shape is written, which is what lets both sides import it.
- class volmdlr_tools.parametrics.AdditionParameters(frame: Frame3D, outline: Loop2D, length: float, face_ids: frozenset[int], end_face_ids: frozenset[int])#
Bases:
objectMaterial added to a part by extruding a profile straight along a direction.
With one end face, the extrusion starts where its walls meet the rest of the part and ends at that face, and its direction is that face’s outward normal. With two, it starts at the one of the lower face number and runs towards the other.
- Parameters:
frame – The frame of the profile: its origin is on the plane the extrusion starts from, its third axis is the direction the extrusion goes in, from its start to its end, and its first two axes span the plane the profile is drawn in.
outline – The outer boundary of the profile in frame, counter-clockwise. A window through the addition is a feature of its own.
length – The distance from the start of the extrusion to its end, along its direction; greater than zero.
face_ids – The faces read.
end_face_ids – The faces among face_ids that close the addition at its start or at its end.
- property direction: Vector3D#
The direction the extrusion goes in, from its start to its end.
- end_face_ids: frozenset[int]#
- face_ids: frozenset[int]#
- frame: Frame3D#
- kind: Literal['addition'] = 'addition'#
- length: float#
- class volmdlr_tools.parametrics.BaseSurface(kind: Literal['plane', 'cylinder'], origin: Point3D, axis: Vector3D, radius: float | None = None, face_ids: tuple[int, ...] = ())#
Bases:
objectThe surface a feature stands on or opens in.
- Parameters:
kind –
"plane"or"cylinder".origin – A point on the surface; on a cylinder, a point on its axis.
axis – The unit normal pointing out of the material for a plane, the unit axis for a cylinder.
radius – The radius of a cylinder,
Nonefor a plane.face_ids – The faces of the part that lie on the surface.
- axis: Vector3D#
- face_ids: tuple[int, ...] = ()#
- kind: Literal['plane', 'cylinder']#
- origin: Point3D#
- radius: float | None = None#
- class volmdlr_tools.parametrics.BlendParameters(radius: float, widest_radius: float, certain: bool, vexity: Literal['convex', 'concave'] | None, edges: tuple[WorkedEdge, ...], stops_at: frozenset[int], after: tuple[int, ...], layer: int, face_ids: frozenset[int])#
Bases:
objectA round worked on edges of a part: a fillet filling inside corners, or a round taking outside edges off.
- Parameters:
radius – The radius the round is made with, in the units of the part; where it varies along the round, the smallest.
widest_radius – The largest radius along the round: radius again for a round of one radius.
certain –
Truewhen every radius was read off the geometry of the round or measured when it was recognised;Falsewhen one was only estimated from how its face curves.vexity – Which way the edges it rounds turned,
Nonewhen that cannot be told.edges – The edges the round was worked on, each where two faces of the part met; a corner where the round turns from one edge onto the next names none.
stops_at – The faces of the part the round runs into at its ends, which it is not tangent to.
after – The records of the rounds of a larger radius this one runs on over where they meet, which are made before it, by their position in the document.
layer – How many rounds of a larger radius come before this one, each running on over the one before:
0for a round that runs on over none.face_ids – The faces of the round.
- after: tuple[int, ...]#
- certain: bool#
- edges: tuple[WorkedEdge, ...]#
- face_ids: frozenset[int]#
- kind: Literal['blend'] = 'blend'#
- layer: int#
- radius: float#
- stops_at: frozenset[int]#
- property varying: bool#
Whether the radius changes along the round by more than a twentieth of itself.
- vexity: Literal['convex', 'concave'] | None#
- widest_radius: float#
- class volmdlr_tools.parametrics.BlendRadius(value: float, certain: bool, face_ids: tuple[int, ...])#
Bases:
objectThe radius of a blend and how far it can be trusted.
- Parameters:
value – The radius, in the units of the part: as read when it is certain, and rounded to the value a designer would have typed when it is not.
certain –
Truewhen the radius was read off the geometry of the blend faces or measured when the blend was recognised;Falsewhen it is estimated from curvature, which is what a spline blend allows, or when the faces of the blend disagree.face_ids – The blend faces the radius was read from.
- certain: bool#
- face_ids: tuple[int, ...]#
- value: float#
- class volmdlr_tools.parametrics.BossParameters(base: BaseSurface, frame: Frame3D, outlines: tuple[Loop2D, ...], draft_angle: float, face_ids: frozenset[int], tilt: float, height: float, root_blend: BlendRadius | None, top_blend: BlendRadius | None, top_face_ids: frozenset[int] = frozenset({}), until: Literal['height', 'next', 'plane'] = 'height', top_plane: BaseSurface | None = None, *, host_face_ids: frozenset[int] = frozenset({}), breaks: tuple[EdgeBreak, ...] = ())#
Bases:
_PrismBaseA boss or pad: an outline drawn on its base and extruded to a top.
- Parameters:
height – The distance from the base to the top along the frame’s third axis.
root_blend – The blend where the boss meets its base,
Nonewhen sharp.top_blend – The rounding of the top edges,
Nonewhen sharp.top_face_ids – The faces of the top.
until –
"height"when the boss stops at its own top, height above its base;"next"when it rises until it meets the part, which is its top, and height is only how far that is on average;"plane"when its top is a plane leaning from its base, top_plane, and height is how high its walls reach, under the highest point of that top. Such a boss is its outline carried height along the frame’s third axis, then cut back to the plane, as a wedge rising from its base to a sloping top is.top_plane – The plane the boss is cut back to when until is
"plane": a point of it and its normal out of the material, with the faces of the top;Noneotherwise.
- property circular: bool#
Whether the boss is one circle.
- height: float#
- kind: Literal['boss'] = 'boss'#
- root_blend: BlendRadius | None#
- top_blend: BlendRadius | None#
- top_face_ids: frozenset[int] = frozenset({})#
- top_plane: BaseSurface | None = None#
- until: Literal['height', 'next', 'plane'] = 'height'#
- class volmdlr_tools.parametrics.ChamferParameters(distances: tuple[float, float], vexity: Literal['convex', 'concave'], edges: tuple[WorkedEdge, ...], face_ids: frozenset[int])#
Bases:
objectA chamfer worked on edges of a part: a face cut across each edge, or filling an inside corner.
- Parameters:
distances – How far the chamfer cuts back along each of the two faces of the edges it was worked on, the shorter first, in the units of the part; along a face of an inside corner, how far it reaches up it.
vexity – Which way the edges it was worked on turned: an inside bevel filling a corner is
"concave".edges – The edges the chamfer was worked on, each where two faces of the part met, the face the shorter distance runs along first; a corner where the chamfer turns from one edge onto the next names none.
face_ids – The faces of the chamfer.
- property distance: float#
The distance of a chamfer cut back equally, the mean of its two distances.
- distances: tuple[float, float]#
- edges: tuple[WorkedEdge, ...]#
- property equal: bool#
Whether the chamfer cuts back as far along each face, to within a twentieth of the longer distance.
- face_ids: frozenset[int]#
- kind: Literal['chamfer'] = 'chamfer'#
- vexity: Literal['convex', 'concave']#
- class volmdlr_tools.parametrics.EdgeBreak(kind: Literal['chamfer', 'blend'], size: float | None, face_ids: frozenset[int], edges: tuple[RimEdge, ...])#
Bases:
objectThe chamfers or blends along a feature’s rim, of one size.
- Parameters:
kind –
"chamfer"for faces cut square to the bisector of the edge,"blend"for rounded ones.size – How far the break reaches along each face it joins,
Nonewhen it is not the same on both.face_ids – The faces that make the break.
edges – The sharp edges the break stands for.
- face_ids: frozenset[int]#
- kind: Literal['chamfer', 'blend']#
- size: float | None#
- class volmdlr_tools.parametrics.ExtrudedBodyParameters(profiles: tuple[ExtrudedProfile, ...], face_ids: frozenset[int])#
Bases:
objectThe profiles an extruded body or a slab of the part was drawn from, one per stretch, from the lowest up.
A body extruded in one go gives one profile; a body read as several slabs stacked along its direction, as a stepped plate, gives one per slab, each with its own outlines, drafts and levels.
- Parameters:
profiles – The profiles, from the lowest along their common direction up; never empty.
face_ids – The faces read.
- property direction: tuple[float, float, float]#
The unit direction the profiles are extruded along.
- face_ids: frozenset[int]#
- kind: Literal['extruded_body'] = 'extruded_body'#
- property levels: tuple[float, float]#
Where the body starts and stops along its direction, as
ExtrudedProfile.levelsmeasures it.
- profiles: tuple[ExtrudedProfile, ...]#
- class volmdlr_tools.parametrics.ExtrudedProfile(frame: Frame3D, levels: tuple[float, float], loops: tuple[ProfileLoop, ...], ends: tuple[Literal['cap', 'parent', 'read'], Literal['cap', 'parent', 'read']], tolerance: float, parting_level: float | None = None, left_out: tuple[str, ...] = ())#
Bases:
objectThe profile one extruded body or slab was drawn from, and how far it is extruded.
- Parameters:
frame – The plane the outlines are drawn in: its
waxis is the unit direction the profile is extruded along, its origin lies on that line at the level the outlines were read at.levels – Where the profile starts and stops along the direction, measured from the origin of space in the model’s own length units; the start is the lower.
loops – The outlines, the outer outlines first.
ends – What closes the profile at its start, and at its end.
tolerance – How far an outline may stand off the walls it was read from.
parting_level – For a slab of a run of slabs that leave the mould the same way, the level of the plane their walls are drafted about: below the run when it is pulled out along the direction, above it otherwise.
Nonewhen the walls are drafted from where the profile is drawn.left_out – Why the profile gives less than the part’s section does, one reason each: an outline of it that is not in the profile, or a section that could not be cut, at the slab or at a neighbour its parting level was read with; empty when the profile holds every outline and every section was cut.
- property complete: bool#
Whether the profile holds every outline of the part’s section at it, every section read having been cut.
- property direction: tuple[float, float, float]#
The unit direction the profile is extruded along.
- property drawn_at: float#
The level of the plane the outlines are drawn in.
- ends: tuple[Literal['cap', 'parent', 'read'], Literal['cap', 'parent', 'read']]#
- frame: Frame3D#
- property holes: tuple[ProfileLoop, ...]#
The holes in the material.
- property islands: tuple[ProfileLoop, ...]#
The islands of material standing in a hole.
- left_out: tuple[str, ...] = ()#
- levels: tuple[float, float]#
- loops: tuple[ProfileLoop, ...]#
- loops_at(level: float) tuple[Loop2D, ...]#
Return the outlines carried along their walls to another level, each edge by its own draft.
An outline whose edges, each carried by its own draft, no longer meet, as a straight wall beside a corner leaning a little more, is carried by its own draft as a whole instead.
- Parameters:
level – Where to carry them, as
levelsmeasures it.- Returns:
One outline per loop of the profile, in order, in the frame’s
(u, v)axes.- Raises:
FeatureRecognitionError – When an outline cannot be carried that far, as when it shrinks to nothing.
- property outlines: tuple[ProfileLoop, ...]#
The outer outlines, one per separate piece of material.
- parting_level: float | None = None#
- property release: Literal['up', 'down'] | None#
The way the profile leaves the mould:
"up"along its direction,"down"against it.An outline that shrinks along the direction and a hole that widens both let the material out along it.
Nonewhen no wall leans by half a degree or more, or walls lean both ways.
- tolerance: float#
- exception volmdlr_tools.parametrics.FeatureParameterError#
Bases:
ValueErrorRaised when a recognised feature cannot be read as parameters.
The message names the feature’s faces and says what they do not satisfy, so the feature can be inspected or handed to another reader.
- class volmdlr_tools.parametrics.GridRepeat(members: tuple[int, ...], origin: Point3D, direction_x: Vector3D, direction_y: Vector3D, spacing_x: float, spacing_y: float, count_x: int, count_y: int)#
Bases:
objectIdentical features on a rectangular lattice.
- Parameters:
members – Indices of the features, row by row along the first direction.
origin – Anchor of the corner feature with the smallest indices.
direction_x – Unit direction of the first lattice axis.
direction_y – Unit direction of the second lattice axis.
spacing_x – Spacing along the first axis.
spacing_y – Spacing along the second axis.
count_x – Features along the first axis.
count_y – Features along the second axis.
- count_x: int#
- count_y: int#
- direction_x: Vector3D#
- direction_y: Vector3D#
- kind: Literal['grid'] = 'grid'#
- members: tuple[int, ...]#
- origin: Point3D#
- spacing_x: float#
- spacing_y: float#
- class volmdlr_tools.parametrics.GrooveParameters(axis_origin: Point3D, axis: Vector3D, frame: Frame3D, profile: Loop2D, opens_on: BaseSurface, face_ids: frozenset[int], full_turn: bool = True)#
Bases:
objectA groove cut about an axis: a profile turned through a whole revolution and taken from the part.
- Parameters:
axis_origin – The point of the axis halfway along the groove.
axis – Unit direction of the axis.
frame – The frame of the meridian half plane: its first axis is the radial direction the profile is drawn towards, its second axis the direction of the groove’s axis, its origin the point halfway along it.
profile – The closed meridian profile in that frame, as (radius, axial position): the groove’s walls closed by a line on the surface the groove opens in.
opens_on – The surface the groove is cut into.
face_ids – The faces of the groove.
full_turn – Whether the groove runs the whole way round,
Falsewhen windows cut through its walls.
- axis: Vector3D#
- axis_origin: Point3D#
- face_ids: frozenset[int]#
- frame: Frame3D#
- full_turn: bool = True#
- kind: Literal['groove'] = 'groove'#
- opens_on: BaseSurface#
- class volmdlr_tools.parametrics.HoleStack(origin: Point3D, axis: Vector3D, entry: BaseSurface, steps: tuple[HoleStep, ...], through: bool, interruptions: tuple[Interruption, ...], face_ids: frozenset[int], entry_face_id: int | None = None, entry_planar: bool = True)#
Bases:
objectA round hole read from its entry.
- Parameters:
origin – The point where the axis meets the entry plane. When the hole names the face it opens through, entry_face_id, it is a point of the part, where the axis meets that face.
axis – Unit direction of the axis, pointing into the material.
entry – The plane the hole is drilled from, with its normal pointing out of the material: the plane of the flat face the hole opens through, or, when it opens through a curved face, the plane square to the axis through origin, which touches that face only there.
steps – The stretches of the profile in order of depth. A wall reaching out past the entry, on the side where the face the hole opens through falls away from the axis, starts at the entry.
through – Whether the hole leaves the part at the far end.
interruptions – The faces that cross the hole.
face_ids – Every face the hole is made of.
entry_face_id – The face of the part the hole opens through, the one its axis meets at origin;
Nonewhen the hole is not read so, as one whose axis meets no face beside its walls at its mouth.entry_planar – Whether the face the hole opens through is flat.
Falsefor a curved one, as the cone under a turned disc or the round of a shaft: the entry plane then only touches it at origin.
- axis: Vector3D#
- property bore: HoleStep | None#
The narrowest cylinder of the hole, the one the other steps are cut around.
Nonefor a hole with no cylinder, such as a countersink alone.
- property depth: float#
The depth of the deepest step, to the tip of a drill point.
- entry: BaseSurface#
- entry_face_id: int | None = None#
- entry_planar: bool = True#
- face_ids: frozenset[int]#
- interruptions: tuple[Interruption, ...]#
- kind: Literal['hole'] = 'hole'#
- origin: Point3D#
- step_of(kind: Literal['chamfer', 'countersink', 'counterbore', 'bore', 'taper', 'drill_point', 'recess']) HoleStep | None#
Return the first step of a kind, or
None.
- through: bool#
- class volmdlr_tools.parametrics.HoleStep(kind: Literal['chamfer', 'countersink', 'counterbore', 'bore', 'taper', 'drill_point', 'recess'], start_depth: float, end_depth: float, start_diameter: float, end_diameter: float, face_ids: tuple[int, ...])#
Bases:
objectOne stretch of a hole’s profile, measured from the entry plane along the axis.
- Parameters:
kind – What the stretch does:
"chamfer"or"countersink"a cone widening to the entry, a chamfer when it widens the bore by at most a third of the bore’s radius,"counterbore"the wide cylinder at the entry that a narrower one follows through a flat shoulder,"bore"any other cylinder,"recess"a wider cylinder away from the entry,"taper"a cone inside the hole,"drill_point"the cone ending a blind hole, or the cone narrowing to the far end of a hole whose drill point broke out through the part.start_depth – Depth at which the stretch starts.
end_depth – Depth at which the stretch ends.
start_diameter – Diameter at the start.
end_diameter – Diameter at the end;
0for a drill point that comes to a tip, the width of the opening for one that broke out through the part.face_ids – The faces of the part the stretch is made of.
- end_depth: float#
- end_diameter: float#
- face_ids: tuple[int, ...]#
- property included_angle_degrees: float | None#
The angle in degrees between the opposite generators of a cone,
0for a cylinder.Nonefor a stretch with no length, which has no angle to read.
- kind: Literal['chamfer', 'countersink', 'counterbore', 'bore', 'taper', 'drill_point', 'recess']#
- property length: float#
The length of the stretch along the axis.
- property radial_size: float#
How far the stretch’s diameter changes, counted on the radius.
- start_depth: float#
- start_diameter: float#
- class volmdlr_tools.parametrics.Interruption(start_depth: float, end_depth: float, face_ids: tuple[int, ...])#
Bases:
objectFaces that cross a hole and break its wall, such as a slot cut through it.
- Parameters:
start_depth – Depth at which the crossing faces begin along the hole’s axis.
end_depth – Depth at which they end.
face_ids – The crossing faces.
- end_depth: float#
- face_ids: tuple[int, ...]#
- start_depth: float#
- class volmdlr_tools.parametrics.LinearRepeat(members: tuple[int, ...], origin: Point3D, step: Vector3D)#
Bases:
objectIdentical features at equal steps along a line.
- Parameters:
members – Indices of the features among those given, in order along the line.
origin – Anchor of the first feature.
step – The vector from one feature to the next.
- property count: int#
The number of features.
- kind: Literal['linear'] = 'linear'#
- members: tuple[int, ...]#
- origin: Point3D#
- step: Vector3D#
- class volmdlr_tools.parametrics.Loop2D(primitives: tuple[Primitive2D, ...])#
Bases:
objectA closed outline: ordered primitives, each ending where the next begins.
- contains(point: tuple[float, float]) bool#
Return whether point lies inside the outline, by counting crossings of a ray.
- crossing() tuple[float, float] | None#
Return a point where the outline meets itself away from its joints, or
Nonewhen it is a simple loop.Pieces may meet only where one ends and the next begins. Two others that cross, touch or run over one another make a loop that bounds no region. Pieces that continue one another along a line, and a tangent blend, are simple.
- distances_to(points: ndarray) ndarray#
Return how far each of the
(n, 2)points is from the outline.
- property is_ccw: bool#
Return whether the loop runs counter-clockwise.
- property length: float#
Return the perimeter.
- merged(tol: float) Loop2D#
Return the loop with consecutive primitives on one carrier merged into one.
The seam between the last and first primitive is merged too.
- primitives: tuple[Primitive2D, ...]#
- sample(n: int = 400) ndarray#
Return about n points spread along the perimeter, for comparing outlines.
- property signed_area: float#
Return the enclosed area, positive when the loop runs counter-clockwise.
Exact: the polygon through the primitives’ ends plus the segment each arc, of a circle or of an ellipse, adds or takes away.
- class volmdlr_tools.parametrics.MirrorRepeat(members: tuple[int, int], plane_origin: Point3D, plane_normal: Vector3D)#
Bases:
objectTwo identical features mirrored across a plane.
- Parameters:
members – Indices of the two features: the original first.
plane_origin – A point on the mirror plane.
plane_normal – Unit normal of the mirror plane.
- kind: Literal['mirror'] = 'mirror'#
- members: tuple[int, int]#
- plane_normal: Vector3D#
- plane_origin: Point3D#
- class volmdlr_tools.parametrics.PocketParameters(base: BaseSurface, frame: Frame3D, outlines: tuple[Loop2D, ...], draft_angle: float, face_ids: frozenset[int], tilt: float, depth: float, floor_blend: BlendRadius | None, rim_blend: BlendRadius | None, floor_face_ids: frozenset[int] = frozenset({}), from_floor: bool = False, through: bool = False, *, host_face_ids: frozenset[int] = frozenset({}), breaks: tuple[EdgeBreak, ...] = ())#
Bases:
_PrismBaseA pocket: an outline drawn on its base and cut to a floor.
- Parameters:
depth – The distance from the base to the floor along the direction into the material.
floor_blend – The blend between the walls and the floor,
Nonewhen sharp.rim_blend – The rounding of the pocket’s rim on its base,
Nonewhen sharp.floor_face_ids – The faces of the floor.
from_floor –
Truewhen the frame sits on one end of the cut and the cut runs outward from it along the frame’s third axis, because the floor does not lie parallel to the base and the pocket has no one depth, or because the cut starts at a level that is not on the base.through – Whether the cut leaves the part at both ends, a window rather than a pocket with a floor; depth is then the distance through the part.
- property circular: bool#
Whether the pocket is one circle.
- depth: float#
- floor_blend: BlendRadius | None#
- floor_face_ids: frozenset[int] = frozenset({})#
- from_floor: bool = False#
- kind: Literal['pocket'] = 'pocket'#
- rim_blend: BlendRadius | None#
- through: bool = False#
- class volmdlr_tools.parametrics.PolarRepeat(members: tuple[int, ...], center: Point3D, axis: Vector3D, radius: float, start_angle_degrees: float, angular_spacing_degrees: float, full_circle: bool, reference: Vector3D, rotated: bool = False)#
Bases:
objectIdentical features at equal angles on a circle.
- Parameters:
members – Indices of the features, in order of increasing angle from the first.
center – The centre of the circle.
axis – Unit normal of the circle’s plane.
radius – The circle’s radius.
start_angle_degrees – Angle of the first feature in degrees, from reference.
angular_spacing_degrees – Angle between neighbours in degrees.
full_circle – Whether the features go all the way round.
reference – Unit direction in the circle’s plane from which start_angle_degrees is measured.
rotated – Whether each copy is turned about the axis as far as it is carried round it, as a flat on a nut or a hole drilled towards the axis is; a round feature on a circle is not.
- angular_spacing_degrees: float#
- axis: Vector3D#
- center: Point3D#
- property count: int#
The number of features.
- full_circle: bool#
- kind: Literal['polar'] = 'polar'#
- members: tuple[int, ...]#
- radius: float#
- reference: Vector3D#
- rotated: bool = False#
- start_angle_degrees: float#
- class volmdlr_tools.parametrics.Primitive2D(kind: Literal['line', 'arc', 'ellipse'], start: tuple[float, float], end: tuple[float, float], center: tuple[float, float] | None = None, radius: float | None = None, ccw: bool | None = None, closed: bool = False, minor_radius: float | None = None, rotation: float = 0.0)#
Bases:
objectA straight segment, a circular arc or an arc of an ellipse, travelled from
starttoend.An arc carries its
center,radiusand senseccw.closedmarks the full circle: its ends coincide and it turns through a whole revolution however close the two ends happen to be, so a circle whose ends differ by rounding is not read as an arc of zero sweep.An arc of an ellipse (
kind="ellipse") carries the same, withradiusits major radius,minor_radiusits minor one androtationthe angle in radians from the first axis to its major axis. Its angles are those of the ellipse’s own parametrisation,center + radius cos(a) major + minor_radius sin(a) minor, andclosedmarks the whole ellipse.- carrier() Carrier#
Return the line or circle this primitive lies on.
- Raises:
SectionError – For an arc of an ellipse, which lies on neither.
- ccw: bool | None = None#
- center: tuple[float, float] | None = None#
- closed: bool = False#
- ellipse_coordinates(point: tuple[float, float]) tuple[float, float]#
Return
(cos(a), sin(a))of a point of an ellipse: its offsets along the axes over their radii.
- end: tuple[float, float]#
- property is_full_circle: bool#
Return whether the primitive is a whole circle.
- kind: Literal['line', 'arc', 'ellipse']#
- left_normal_at(fraction: float) tuple[float, float]#
Return the unit normal a fraction of the way along the primitive, to the left of the way it is travelled.
- property length: float#
Return the length of the primitive.
- midpoint() tuple[float, float]#
Return the point halfway along the primitive.
- minor_radius: float | None = None#
- point_at(fraction: float) tuple[float, float]#
Return the point a fraction of the way along the primitive: of its length, of its angle for an arc.
- radius: float | None = None#
- reversed() Primitive2D#
Return the same primitive travelled the other way.
- rotation: float = 0.0#
- sample(n: int) ndarray#
Return n points evenly spread along the primitive, both ends included: the points of
point_at().
- start: tuple[float, float]#
- property sweep: float#
Return the signed angle an arc turns through, positive when counter-clockwise.
- tangent_at(fraction: float) tuple[float, float]#
Return the unit direction of travel a fraction of the way along the primitive.
- tangent_at_end() tuple[float, float]#
Return the unit direction of travel at the end.
- tangent_at_start() tuple[float, float]#
Return the unit direction of travel at the start.
- to_edge_tuple() tuple[str, dict]#
Return the primitive in the sketch edge vocabulary of
volmdlr_tools.parametrics.
- class volmdlr_tools.parametrics.ProfileLoop(loop: Loop2D, role: Literal['outline', 'hole', 'island'], depth: int, draft_angle: float, edge_drafts: tuple[float, ...], edge_face_ids: tuple[int | None, ...] = ())#
Bases:
objectOne outline of a profile, as it is drawn and as its walls lean.
- Parameters:
loop – The outline, counter-clockwise, in the
(u, v)axes of the profile’s frame.role – What the outline is: see
ProfileLoopRole.depth – How many other outlines of the profile enclose it.
draft_angle – How far the outline’s walls lean, in radians, as the middle of its edges’ drafts weighed by length: positive when the outline grows along the profile’s direction, a hole widening as an outline does; zero when its walls stand straight.
edge_drafts – The draft of each edge of the outline, in order and signed as draft_angle.
edge_face_ids – The face of the part each edge of the outline runs along, in order: the wall it was cut from, a wall another record may hold, as a slot opening on the outline;
Nonefor an edge that bridges a gap the walls leave. Empty when the walls are not read, as for a slab.
- depth: int#
- draft_angle: float#
- edge_drafts: tuple[float, ...]#
- edge_face_ids: tuple[int | None, ...] = ()#
- property face_ids: frozenset[int]#
The faces of the part the outline runs along, its walls; empty when they are not read.
- property is_hole: bool#
Whether the outline is a hole in the material.
- role: Literal['outline', 'hole', 'island']#
- property uniform: bool#
Whether every edge of the outline leans by the outline’s draft, to within half a degree.
- class volmdlr_tools.parametrics.ProfileShape(kind: Literal['rectangle', 'regular_polygon', 'slot', 'rectangle_rounded', 'fillet_polyline', 'hull'], center: tuple[float, float], width: float | None = None, height: float | None = None, radius: float | None = None, side_count: int | None = None, rotation_deg: float = 0.0, corner_radius: float | None = None, points: tuple[tuple[float, float], ...] | None = None, radii: tuple[float, ...] | None = None)#
Bases:
objectOne recognised profile shape, in sketch-plane coordinates.
Which fields carry a value depends on
kind:kind
fields that carry a value
rectanglecenter,width,height,rotation_degregular_polygoncenter,radius,side_count,rotation_degslotcenter,width,height,rotation_degrectangle_roundedcenter,width,height,rotation_deg,corner_radiusfillet_polylinecenter,points,corner_radiushullcenter,points,radii- Parameters:
kind – Which of the five shapes this is.
center –
(cx, cy)the shape is positioned by. For every kind butfillet_polylinethis is the shape’s own centre; forfillet_polylineit is the mean ofpoints, which is not the outline’s centroid unless the outline happens to be symmetric.fillet_polylineis drawn frompointsalone, so itscenterpositions nothing and is only a handle for grouping.width – Extent along the rotation direction. For
slot, the overall length including both caps.height – Extent across the rotation direction. For
slot, the width across the caps, which is twice the cap radius.radius – Distance from
centerto a vertex of a regular polygon.side_count – Number of sides of a regular polygon.
rotation_deg – Rotation of the shape about
center, in degrees. Canonical in[0, 90)forrectangleandrectangle_rounded, whose quarter turns are the same shape with width and height exchanged; in[0, 180)forslot, whose half turns are the same shape; and in[0, 360)forregular_polygon, measured to its first vertex.corner_radius – The one radius every rounded corner carries.
points – The corners a
fillet_polylineis drawn through, in order. These are the sharp corners the outline would have had unrounded, not points on the outline itself. For ahullthey are the centres of its circles.radii – The radius of each circle of a
hull, one per point.
- center: tuple[float, float]#
- corner_radius: float | None = None#
- height: float | None = None#
- kind: Literal['rectangle', 'regular_polygon', 'slot', 'rectangle_rounded', 'fillet_polyline', 'hull']#
- points: tuple[tuple[float, float], ...] | None = None#
- radii: tuple[float, ...] | None = None#
- radius: float | None = None#
- rotation_deg: float = 0.0#
- side_count: int | None = None#
- width: float | None = None#
- class volmdlr_tools.parametrics.RevolvedBodyParameters(frame: Frame3D, chains: tuple[RevolvedChain, ...], angle: float, face_ids: frozenset[int])#
Bases:
objectThe profile a turned body of the part was turned from, the axis it was turned about, and how far round.
The profile is drawn in the half plane the turn starts from, as
(t, r):talong the axis from the frame’s origin,rthe distance from the axis, never negative. A point(t, r)of the profile is the pointorigin + t u + r vof space before it is turned.- Parameters:
frame – The frame of the half plane: its origin lies on the axis, its
uaxis is the unit direction of the axis, itsvaxis the radial direction the turn starts from, and itswaxis,ucrossed withv, the way the profile turns from there.chains – The pieces of the profile, none crossing itself or another; never empty. A corner a chamfer of the part bevels is sharp: the chamfer is worked on the circle it turns into afterwards.
angle – The angle the profile is turned through, in radians, from
vtowardsw: a whole turn, or less for a body turned only part of the way round.face_ids – The faces read.
- Raises:
ValueError – When there is no chain, or the angle is not more than nothing and at most a whole turn.
- angle: float#
- property axis: Vector3D#
The unit direction of the axis, along which
tgrows.
- property axis_origin: Point3D#
The point of the axis where
tis zero.
- chains: tuple[RevolvedChain, ...]#
- face_ids: frozenset[int]#
- frame: Frame3D#
- property full_turn: bool#
Whether the profile is turned the whole way round.
- kind: Literal['revolved_body'] = 'revolved_body'#
- property profile: tuple[Primitive2D, ...]#
The lines and arcs of every chain, chain after chain.
- class volmdlr_tools.parametrics.RevolvedChain(primitives: tuple[Primitive2D, ...], closed: bool)#
Bases:
objectOne connected piece of the profile a body was turned from, in the
(t, r)axes of its frame.- Parameters:
primitives – The lines and arcs of the piece, each starting where the one before ends.
closed – Whether the piece returns to where it starts. One that does not runs from the axis out and back to the axis, and is closed along the axis when it is turned.
- closed: bool#
- primitives: tuple[Primitive2D, ...]#
- class volmdlr_tools.parametrics.RimEdge(midpoint: Point3D, direction: Vector3D | None = None, circle_center: Point3D | None = None, circle_radius: float | None = None, circle_axis: Vector3D | None = None, length: float | None = None)#
Bases:
objectThe sharp edge a feature’s wall makes where an edge break takes it away.
- Parameters:
midpoint – Middle of the edge as it would be without the break.
direction – Unit direction of a straight edge,
Nonefor a curved one.circle_center – Centre of the circle a circular edge lies on,
Nonefor any other edge.circle_radius – Radius of that circle.
circle_axis – Unit normal of that circle’s plane.
length – Length of the edge.
- circle_axis: Vector3D | None = None#
- circle_center: Point3D | None = None#
- circle_radius: float | None = None#
- direction: Vector3D | None = None#
- length: float | None = None#
- midpoint: Point3D#
- class volmdlr_tools.parametrics.SlotParameters(base: BaseSurface, frame: Frame3D, outlines: tuple[Loop2D, ...], draft_angle: float, face_ids: frozenset[int], tilt: float, shape: ProfileShape, depth: float, through: bool, floor_blend: BlendRadius | None, rim_blend: BlendRadius | None, symmetric: bool = False, *, host_face_ids: frozenset[int] = frozenset({}), breaks: tuple[EdgeBreak, ...] = ())#
Bases:
_PrismBaseA slot: two parallel sides closed by half circles, cut to a floor or through the part; or a slit.
A slit (symmetric) is a thin cut that two parallel walls bound and that is open on every other side, such as a saw cut. It is drawn and cut the other way round from a slot: its shape is a rectangle drawn in the plane midway between its walls, and it is cut across that plane by its depth, half on either side.
- Parameters:
shape – The slot as a profile shape in the frame: its centre, overall length, width and rotation; a slit’s is the rectangle covering its walls.
depth – The distance from the base to the floor, or to the far side of the part; a slit’s is the distance between its walls.
through – Whether the slot runs through the part.
floor_blend – The blend between the walls and the floor,
Nonewhen sharp or through.rim_blend – The rounding of the slot’s rim,
Nonewhen sharp.symmetric –
Truefor a slit, whose frame lies midway between its walls and is cut half its depth to either side.
- depth: float#
- floor_blend: BlendRadius | None#
- kind: Literal['slot'] = 'slot'#
- rim_blend: BlendRadius | None#
- shape: ProfileShape#
- symmetric: bool = False#
- through: bool#
- class volmdlr_tools.parametrics.WorkedEdge(face_ids: tuple[int, int], sharp: RimEdge | None, break_face_ids: frozenset[int])#
Bases:
objectAn edge of the part a round or a chamfer was worked on: the two faces that met along it, and where it ran.
- Parameters:
face_ids – The two faces of the part that met along the edge before it was worked, which the round or the chamfer now joins. A round names them lower number first; a chamfer names first the face its shorter distance runs along, the lower number first when its distances are equal.
sharp – Where the edge ran before it was worked: where the two faces, carried on past the round or the chamfer, meet.
Nonewhen that cannot be told, as where the faces run on tangent to each other.break_face_ids – The faces of the round or the chamfer that took this edge away.
- break_face_ids: frozenset[int]#
- face_ids: tuple[int, int]#
- volmdlr_tools.parametrics.anchor(record: HoleStack | BossParameters | PocketParameters | SlotParameters | GrooveParameters) Point3D#
Return the point a feature is placed by.
That is where a hole’s axis meets its entry, the origin of a pad’s frame, and the point of a groove’s axis.
- volmdlr_tools.parametrics.classify_edge_tuples(edges_2d: list[tuple[str, dict]], *, extent: float | None = None) ProfileShape | None#
Return the shape
edges_2ddraws, orNonewhen it is not one of the five.- Parameters:
edges_2d – Ordered
(edge_type, data)tuples, aswire_edge_tuples()produces."line"carriesstartandend;"arc"carriesstart,midandend, and carriesradiuswhen it projected as a circle rather than an ellipse. Any other edge type — a whole"circle", or an"unsupported"curve — means the outline is not one of these shapes.extent – The extent of the part the outline belongs to, when known: see
length_tolerance().
- Returns:
The recognised shape, or
None.
- volmdlr_tools.parametrics.compute_grid_coords(pts_2d: ndarray, origin: ndarray, u: ndarray, v: ndarray, tol_fraction: float = 0.01) list[tuple[int, int]] | None#
Check all points lie on integer grid coordinates.
- Parameters:
pts_2d – Nx2 array of 2D points.
origin – 2D origin point.
u – First basis vector.
v – Second basis vector.
tol_fraction – Relative tolerance for grid-snap check.
- Returns:
List of (i, j) integer coordinates, or None if any point is off-grid.
- volmdlr_tools.parametrics.find_fundamental_spacing(deltas: ndarray, angle_tol: float = 2.0) float | None#
Find the fundamental angular spacing from consecutive angle deltas.
All deltas must be positive integer multiples of the fundamental spacing.
The candidate fundamental is the mode of the deltas (the mean of the most-populated tolerance bin), not the min. The mode is robust against a single near-coincident pair producing a tiny outlier delta that would otherwise hijack a min-based pick and cause every real delta to fail the integer-ratio test.
- Parameters:
deltas – Array of consecutive angular differences (degrees).
angle_tol – Tolerance in degrees for angle comparisons.
- Returns:
Fundamental spacing in degrees, or None if no regular pattern.
- volmdlr_tools.parametrics.find_grid_basis(pts_2d: ndarray, collinear_tol: float = 0.01) tuple[ndarray, ndarray, int] | None#
Find two non-collinear basis vectors from shortest pairwise distances.
- Parameters:
pts_2d – Nx2 array of 2D points.
collinear_tol – Relative cross-product threshold for collinearity.
- Returns:
(u, v, origin_index) or None.
- volmdlr_tools.parametrics.fit_circle_kasa(xs: ndarray, ys: ndarray) tuple[float, float, float] | None#
Algebraic circle fit (Kasa method).
Near-collinear input makes the algebraic solver return a geometrically valid but practically useless huge-radius circle. The radius/bbox guard below rejects those fits before they reach a downstream consistency check (which would pass — the points really do lie on that huge circle).
- Parameters:
xs – X coordinates of points.
ys – Y coordinates of points.
- Returns:
(cx, cy, r) or None on failure / degenerate fit.
- volmdlr_tools.parametrics.hull_profile(edges_2d: list[tuple[str, dict]], *, extent: float | None = None) ProfileShape | None#
Return the convex hull of circles that
edges_2ddraws, orNonewhen it is not one.The outline is a hull of circles when it alternates arcs and straight sides, every side runs tangent to the arcs on either end of it, and all the arcs turn the same way. The circles are those the arcs belong to. This is not one of the kinds
classify_edge_tuples()returns: it is asked for by a caller that knows its outline is a plate drawn round a few circles, such as a flange round its hub and its bolt lobes.- Parameters:
edges_2d – Ordered
(edge_type, data)tuples, as forclassify_edge_tuples().extent – The extent of the part the outline belongs to, when known: see
length_tolerance().
- Returns:
A
hullshape whosepointsandradiiare the circles in order round the outline, orNone.
- volmdlr_tools.parametrics.length_tolerance(edges_2d: list[tuple[str, dict]], extent: float | None = None) float#
Return the length under which two lengths of this outline count as equal.
It is a fixed share of the outline’s extent, the diagonal of the box its edges’ end points and middle points fit in, so an outline gets the same verdict in any unit. Projection uses it as well, to drop an edge too short to be told from a point, so the two cannot disagree.
- Parameters:
edges_2d – Ordered
(edge_type, data)tuples, as forclassify_edge_tuples().extent – The extent of the part the outline belongs to, when known, such as the diagonal of its bounding box. The share is then taken of the larger of the two extents, so a small outline is judged as the part’s other lengths are rather than more tightly.
- Returns:
The tolerance, zero for an outline with no extent and no part extent given.
- volmdlr_tools.parametrics.reframe_profile_shape(shape: ProfileShape, from_frame: Frame3D, to_frame: Frame3D) ProfileShape#
Re-express a shape measured in one sketch frame in another frame.
centerandpointsare carried through 3D;rotation_degis carried by transporting the direction it names. Rectangle-family kinds keep rotation canonical by exchanging width and height, so a shape square to its frame stays square to the new one after a quarter-turn change of frame.The two frames must describe the same plane, or planes parallel to it: only the in-plane position and direction are mapped, while
width,height,radiusandcorner_radiusare carried across untouched. A frame whose third axis is not parallel to the original’s would need those re-measured, which this cannot do, so the caller is responsible for not asking.
- volmdlr_tools.parametrics.wire_edge_tuples(wire: object, frame: Frame3D, *, extent: float | None = None) list[tuple[str, dict]]#
Walk a wire in order and describe each edge on
frameas a sketch primitive.The projection every sketch is read through, so a wire is described the same way wherever it is read — whether it is about to be drawn or about to be classified by
classify_edge_tuples(). It lives besideproject_edge(), which does the per-edge work.An edge whose two ends coincide once projected is dropped: it draws nothing, and left in it would read as an extra vertex. The threshold is the classifier’s own
length_tolerance(), taken over the wire as projected, so an edge too short for the classifier to tell apart from a point never reaches it, in whatever unit the wire is measured.- Parameters:
wire – A volmdlr wire.
frame – Sketch-plane frame the edges are projected onto.
extent – The extent of the part the wire belongs to, when known, as for
length_tolerance(). Pass the same one to the classifier.
- Returns:
Ordered
(edge_type, data)tuples.