### Dump Topology Structure Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Illustrates how to use the `dumpTopology` function from OCCUtils.Topology to print the hierarchical structure of a shape. This is useful for debugging and understanding the topology of complex B-Rep models. The example creates a box using BRepPrimAPI_MakeBox and then calls `dumpTopology` on it. ```python from OCCUtils.Topology import dumpTopology from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox # Create a box box = BRepPrimAPI_MakeBox(10, 20, 30).Shape() # Print complete topology hierarchy print("Complete topology structure:") dumpTopology(box) # Output shows hierarchical structure: # Solid: 12345 # ..Shell: 23456 # ....Face: 34567 # ......Wire: 45678 # ........Edge: 56789 # ..........Vertex 1: # ..........Vertex 2: ``` -------------------------------- ### Offset Shapes using pythonocc-utils Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Provides examples of creating offset versions of geometric entities like wires, faces, and 3D shapes. Functions such as make_offset and make_offset_shape are used. The offset operation supports specifying distance, join types (e.g., GeomAbs_Arc), and can be applied to both wires and faces. ```python from OCCUtils.Construct import ( make_offset, make_offset_shape, make_polygon, make_face, gp_Pnt ) from OCC.Core.GeomAbs import GeomAbs_Arc from OCC.Core.BRepOffset import BRepOffset_Skin # Create a rectangular wire points = [ gp_Pnt(0, 0, 0), gp_Pnt(10, 0, 0), gp_Pnt(10, 10, 0), gp_Pnt(0, 10, 0) ] wire = make_polygon(points, closed=True) # Offset wire outward offset_wire = make_offset( wire, offsetDistance=2.0, altitude=0, joinType=GeomAbs_Arc ) print("Wire offset by 2 units with arc joins") # Create face and offset it face = make_face(wire) offset_face = make_offset(face, offsetDistance=-1.0) print("Face offset inward by 1 unit") ``` -------------------------------- ### High-Level Face Class Operations Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Showcases the Face wrapper class from pythonocc-utils for surface analysis, projection, and UV parameter methods. It includes creating a sphere face, querying properties like planarity and closure, obtaining the UV domain, finding mid-points, projecting a point onto the surface, computing normals, and calculating curvatures. Dependencies include OCC.Core.BRepPrimAPI, OCCUtils.face, and OCCUtils.Construct. ```python from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere from OCCUtils.face import Face from OCCUtils.Construct import gp_Pnt # Create sphere face sphere_face = BRepPrimAPI_MakeSphere(10.0).Face() face = Face(sphere_face) # Query face properties print(f"Is planar: {face.is_planar()}") print(f"Is trimmed: {face.is_trimmed()}") u_closed, v_closed = face.is_closed() print(f"U-closed: {u_closed}, V-closed: {v_closed}") # Get UV domain u_min, u_max, v_min, v_max = face.domain() print(f"U domain: {u_min} to {u_max}") print(f"V domain: {v_min} to {v_max}") # Get mid-point (u_mid, v_mid), mid_point = face.mid_point() print(f"Mid UV parameters: ({u_mid}, {v_mid})") print(f"Mid point: {mid_point.X()}, {mid_point.Y()}, {mid_point.Z()}") # Project point onto surface point = gp_Pnt(5, 5, 5) uv, projected_point = face.project_vertex(point) u, v = uv.Coord() print(f"Projected UV: ({u}, {v})") print(f"Projected point: {projected_point.X()}, {projected_point.Y()}, {projected_point.Z()}") # Compute normal at UV parameters normal = face.DiffGeom.normal(u_mid, v_mid) print(f"Normal at mid-point: {normal.X()}, {normal.Y()}, {normal.Z()}") # Compute curvatures gaussian = face.DiffGeom.gaussian_curvature(u_mid, v_mid) mean_curv = face.DiffGeom.mean_curvature(u_mid, v_mid) print(f"Gaussian curvature: {gaussian}") print(f"Mean curvature: {mean_curv}") # Get edges from face edges = face.edges() print(f"Face has {len(edges)} edges") ``` -------------------------------- ### Create Lofted Surface and Pipe using pythonocc-utils Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Demonstrates creating a lofted surface through multiple circular profiles and generating a pipe by sweeping a profile along a spine. It utilizes functions like make_circle, make_loft, make_edge, and make_pipe. The loft function supports ruled and continuity parameters, with an option for precise lofting with tolerance and compatibility checks. ```python from OCCUtils.Construct import make_circle, gp_Pnt, make_loft, make_edge, make_pipe from OCC.Core.GeomAbs import GeomAbs_C2 # Create circular profiles at different Z levels circle1 = make_circle(gp_Pnt(0, 0, 0), 5.0) circle2 = make_circle(gp_Pnt(0, 0, 10), 3.0) circle3 = make_circle(gp_Pnt(0, 0, 20), 1.0) # Create lofted surface through profiles profiles = [circle1, circle2, circle3] loft = make_loft(profiles, ruled=False, continuity=GeomAbs_C2) print(f"Lofted shape created through {len(profiles)} profiles") # Create pipe by sweeping profile along spine spine = make_edge(gp_Pnt(0, 0, 0), gp_Pnt(20, 20, 20)) profile = make_circle(gp_Pnt(0, 0, 0), 2.0) pipe = make_pipe(spine, profile) print(f"Pipe created along spine path") # Create loft with tolerance and compatibility checking loft_precise = make_loft( profiles, ruled=False, tolerance=1e-6, continuity=GeomAbs_C2, check_compatibility=True ) ``` -------------------------------- ### Apply Transformations to Shapes with pythonocc-utils Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Illustrates geometric transformations including translation, rotation, scaling, and mirroring using pythonocc-utils. Functions like translate_topods_from_vector, rotate, scale_uniformal, and mirror_pnt_dir are demonstrated. Transformations can be applied with or without copying the original shape. ```python from OCCUtils.Construct import ( translate_topods_from_vector, rotate, scale_uniformal, mirror_pnt_dir, make_box, gp_Vec, gp_Pnt, gp_Dir, gp_Ax1 ) # Create a box to transform box = make_box(10, 10, 10) # Translate without copying (modifies original) translated_box = translate_topods_from_vector( box, gp_Vec(20, 0, 0), copy=False ) print("Box translated 20 units in X direction") # Translate with copying (preserves original) box2 = make_box(5, 5, 5) translated_copy = translate_topods_from_vector( box2, gp_Vec(0, 15, 0), copy=True ) # Rotate around axis rotation_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) rotated_box = rotate(box, rotation_axis, 45, copy=True) print("Box rotated 45 degrees around Z axis") # Uniform scaling center = gp_Pnt(5, 5, 5) scaled_box = scale_uniformal(box, center, 2.0, copy=True) print("Box scaled 2x from center point") # Mirror reflection mirror_point = gp_Pnt(0, 0, 0) mirror_direction = gp_Dir(1, 0, 0) mirrored_box = mirror_pnt_dir(box, mirror_point, mirror_direction, copy=True) print("Box mirrored across YZ plane") ``` -------------------------------- ### Perform Point and Vector Operations (Python) Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Demonstrates the enhanced `gp_Pnt` and `gp_Vec` classes from `OCCUtils.Construct`, which support operator overloading for arithmetic operations and convenient conversion methods. This includes point addition, subtraction, scaling, division, conversion to vectors, adding vectors to points, and converting vectors to directions. It also shows point equality checks with tolerance. ```python from OCCUtils.Construct import gp_Pnt, gp_Vec, gp_Dir # Point arithmetic with operator overloading p1 = gp_Pnt(10, 20, 30) p2 = gp_Pnt(5, 10, 15) p_sum = p1 + p2 print(f"Sum: {p_sum.X()}, {p_sum.Y()}, {p_sum.Z()}") # (15, 30, 45) p_diff = p1 - p2 print(f"Difference: {p_diff.X()}, {p_diff.Y()}, {p_diff.Z()}") # (5, 10, 15) p_scaled = p1 * 2 print(f"Scaled: {p_scaled.X()}, {p_scaled.Y()}, {p_scaled.Z()}") # (20, 40, 60) p_div = p1 / 2 print(f"Divided: {p_div.X()}, {p_div.Y()}, {p_div.Z()}") # (5, 10, 15) # Convert between point and vector vec = p1.as_vec() print(f"As vector: {vec.X()}, {vec.Y()}, {vec.Z()}") # Add vector to point v = gp_Vec(5, 0, 0) p_translated = p1.add_vec(v) print(f"Point + vector: {p_translated.X()}, {p_translated.Y()}, {p_translated.Z()}") # Convert vector to direction direction = vec.as_dir() print(f"As direction (normalized): {direction.X()}, {direction.Y()}, {direction.Z()}") # Point equality with tolerance p3 = gp_Pnt(10.0000001, 20, 30) are_equal = (p1 == p3) print(f"Points equal within tolerance: {are_equal}") ``` -------------------------------- ### Analyze Edge Properties with High-Level Class (Python) Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Introduces the `Edge` wrapper class from `OCCUtils.edge`, which simplifies access to differential geometry, projection, and curve analysis methods for edges. It allows querying properties like type, length, closure status, degree, knot count, parameter domain, mid-point, and projecting points onto the edge. Dependencies include `OCCUtils.Topology` and `OCCUtils.Construct`. ```python from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCCUtils.Topology import Topo from OCCUtils.edge import Edge from OCCUtils.Construct import gp_Pnt # Create box and get edge box = BRepPrimAPI_MakeBox(10, 20, 30).Shape() topo = Topo(box) edge_topo = next(topo.edges()) edge = Edge(edge_topo) # Query edge properties print(f"Edge type: {edge.type}") print(f"Edge length: {edge.length()}") print(f"Is closed: {edge.is_closed()}") print(f"Degree: {edge.degree()}") print(f"Number of knots: {edge.nb_knots()}") domain = edge.domain() print(f"Parameter domain: {domain[0]} to {domain[1]}") # Get point at parameter mid_param, mid_point = edge.mid_point() print(f"Mid-point parameter: {mid_param}") print(f"Mid-point coordinates: {mid_point.X()}, {mid_point.Y()}, {mid_point.Z()}") # Project point onto edge point = gp_Pnt(5, 5, 5) param, nearest = edge.project_vertex(point) print(f"Projected parameter: {param}") print(f"Nearest point: {nearest.X()}, {nearest.Y()}, {nearest.Z()}") ``` -------------------------------- ### Sew Shapes into Shells Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Demonstrates using the `sew_shapes` function from OCCUtils.Construct to combine multiple faces or shells into a single connected shell. It shows how to pass a list of faces and nested lists of shapes, with an adjustable tolerance for sewing. Dependencies include OCCUtils.Construct and its helper functions like `make_face` and `make_polygon`. ```python from OCCUtils.Construct import sew_shapes, make_face, make_polygon, gp_Pnt # Create multiple faces points1 = [gp_Pnt(0, 0, 0), gp_Pnt(10, 0, 0), gp_Pnt(10, 10, 0), gp_Pnt(0, 10, 0)] face1 = make_face(make_polygon(points1, closed=True)) points2 = [gp_Pnt(10, 0, 0), gp_Pnt(20, 0, 0), gp_Pnt(20, 10, 0), gp_Pnt(10, 10, 0)] face2 = make_face(make_polygon(points2, closed=True)) points3 = [gp_Pnt(0, 10, 0), gp_Pnt(10, 10, 0), gp_Pnt(10, 20, 0), gp_Pnt(0, 20, 0)] face3 = make_face(make_polygon(points3, closed=True)) # Sew faces together faces = [face1, face2, face3] sewn_shape = sew_shapes(faces, tolerance=0.001) print("Faces sewn into connected shell") print(f"Number of degenerated shapes: (printed during sewing)") print(f"Number of deleted faces: (printed during sewing)") print(f"Number of free edges: (printed during sewing)") # Can also pass nested lists result = sew_shapes([[face1, face2], face3], tolerance=0.01) ``` -------------------------------- ### Create BSpline Curves from Points Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Provides Python functions for creating B-spline curves by interpolating or approximating through sequences of 3D points. Supports tangent constraints and creating closed curves. Key functions include `points_to_bspline`, `interpolate_points_to_spline`, and `interpolate_points_to_spline_no_tangency` from OCCUtils.Common. Dependencies include OCCUtils.Construct. ```python from OCCUtils.Common import ( points_to_bspline, interpolate_points_to_spline, interpolate_points_to_spline_no_tangency ) from OCCUtils.Construct import make_edge, gp_Pnt, gp_Vec # Create bspline approximation through points points = [ gp_Pnt(0, 0, 0), gp_Pnt(2, 1, 0.5), gp_Pnt(4, 3, 1), gp_Pnt(6, 2, 0.8), gp_Pnt(8, 0, 0) ] bspline_curve = points_to_bspline(points) edge = make_edge(bspline_curve) print(f"BSpline curve created through {len(points)} points") # Interpolate with specified end tangents start_tangent = gp_Vec(1, 0, 0) end_tangent = gp_Vec(1, 0, 0) interpolated_curve = interpolate_points_to_spline( points, start_tangent, end_tangent, filter_pts=True, tolerance=1e-6 ) print("Curve interpolated with tangent constraints") # Interpolate without tangent constraints simple_curve = interpolate_points_to_spline_no_tangency( points, filter_pts=True, closed=False, tolerance=1e-6 ) print("Curve interpolated freely through points") # Create closed curve closed_curve = interpolate_points_to_spline_no_tangency( points + [points[0]], # add first point to end closed=True ) print("Closed curve created") ``` -------------------------------- ### Create N-Sided Patches with pythonocc-utils Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Shows how to create N-sided surface patches bounded by curves and passing through optional interior points. It utilizes make_n_sided with different continuity constraints (GeomAbs_C0, GeomAbs_G1). Helper functions like make_edge and points_to_bspline are used to define boundary curves from lists of points. ```python from OCCUtils.Construct import make_n_sided, make_edge, gp_Pnt from OCCUtils.Common import points_to_bspline from OCC.Core.GeomAbs import GeomAbs_C0, GeomAbs_G1 # Define boundary curves pts_left = [gp_Pnt(0, i, 0.1*i) for i in range(5)] pts_right = [gp_Pnt(4, i, 0.2*i) for i in range(5)] pts_front = [gp_Pnt(i, 0, 0) for i in range(5)] pts_back = [gp_Pnt(i, 4, 0.15*i) for i in range(5)] # Create bspline edges from points edge1 = make_edge(points_to_bspline(pts_left)) edge2 = make_edge(points_to_bspline(pts_right)) edge3 = make_edge(points_to_bspline(pts_front)) edge4 = make_edge(points_to_bspline(pts_back)) # Create n-sided patch with C0 continuity constraining_edges = [edge1, edge2, edge3, edge4] constraining_points = [] # optional interior points patch = make_n_sided(constraining_edges, constraining_points, continuity=GeomAbs_C0) print(f"N-sided patch created with {len(constraining_edges)} boundaries") # Create with G1 continuity (tangent constraint) patch_g1 = make_n_sided(constraining_edges, [], continuity=GeomAbs_G1) ``` -------------------------------- ### Explore Wires with WireExplorer in Python Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt WireExplorer facilitates ordered iteration through edges and vertices of a wire, respecting connectivity. It depends on OCC.Core and pythonocc-utils. It returns ordered lists of edges and vertices. ```python from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCCUtils.Topology import Topo, WireExplorer # Create a box and get first wire box = BRepPrimAPI_MakeBox(10, 20, 30).Shape() topo = Topo(box) wire = next(topo.wires()) # Get ordered edges from wire wire_explorer = WireExplorer(wire) edges = list(wire_explorer.ordered_edges()) print(f"Wire has {len(edges)} edges in order") # Get ordered vertices vertices = list(WireExplorer(wire).ordered_vertices()) print(f"Wire has {len(vertices)} vertices in order") # Process each edge sequentially for i, edge in enumerate(wire_explorer.ordered_edges()): print(f"Processing edge {i}: {edge}") ``` -------------------------------- ### Compute Shape Properties: Length, Area, Volume (Python) Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Illustrates how to compute geometric properties of shapes, including length, area, volume, and bounding box. It uses `GpropsFromShape` for volume and surface area calculations, `curve_length` for edge lengths, and `get_boundingbox` for dimensions. The output includes mass (volume/area), center of mass, and bounding box coordinates. ```python from OCCUtils.Common import GpropsFromShape, curve_length, get_boundingbox from OCCUtils.Construct import make_box, make_edge, gp_Pnt from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox # Calculate volume of solid box = BRepPrimAPI_MakeBox(10, 20, 30).Shape() gprops = GpropsFromShape(box, tolerance=1e-5) volume_props = gprops.volume() print(f"Volume: {volume_props.Mass()}") center_of_mass = volume_props.CentreOfMass() print(f"Center of mass: {center_of_mass.X()}, " f"{center_of_mass.Y()}, {center_of_mass.Z()}") # Calculate surface area surface_props = gprops.surface() print(f"Surface area: {surface_props.Mass()}") # Calculate edge length edge = make_edge(gp_Pnt(0, 0, 0), gp_Pnt(10, 10, 10)) length = curve_length(edge) print(f"Edge length: {length}") # Get bounding box xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(box, tol=1e-6) print(f"Bounding box: ({xmin}, {ymin}, {zmin}) to ({xmax}, {ymax}, {zmax})") dimensions = (xmax - xmin, ymax - ymin, zmax - zmin) print(f"Dimensions: {dimensions}") ``` -------------------------------- ### Offset 3D Shape to Create Shell (Python) Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Demonstrates how to offset a 3D shape (specifically a box) to create a shell using the `make_offset_shape` function. This function is useful for creating thickened surfaces or shells around existing geometry. It requires the input shape, an offset distance, and optional parameters for tolerance and offset mode. ```python from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCCUtils.Solid import make_offset_shape from OCC.Core.BRepOffsetAPI import BRepOffset_Skin box = BRepPrimAPI_MakeBox(10, 10, 10).Shape() offset_shell = make_offset_shape( box, offsetDistance=1.0, tolerance=1e-6, offsetMode=BRepOffset_Skin, intersection=False ) print("3D shape offset creating shell") ``` -------------------------------- ### Create Advanced Shapes (Loft, Pipe) with OCC.Construct in Python Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt This snippet shows how to create advanced shapes like lofted surfaces and swept pipes using functions from OCCUtils.Construct. It requires OCCUtils.Construct, OpenCASCADE geometry primitives (gp_Pnt, gp_Vec, gp_Ax2, gp_Dir), and GeomAbs_C2. ```python from OCCUtils.Construct import ( make_loft, make_pipe, make_circle, make_edge, gp_Pnt, gp_Vec, gp_Ax2, gp_Dir ) from OCC.Core.GeomAbs import GeomAbs_C2 # Example usage for make_loft and make_pipe would go here # These functions typically take lists of edges or profiles and a guide curve. ``` -------------------------------- ### Perform Boolean Operations with pythonocc-utils Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Demonstrates constructive solid geometry (CSG) operations such as cut (subtraction) and fuse (union) using pythonocc-utils. Functions like boolean_cut and boolean_fuse are used to combine or subtract volumes of shapes. The operations automatically handle edge refinement and topology optimization. ```python from OCCUtils.Construct import boolean_cut, boolean_fuse, make_box, gp_Pnt # Create two overlapping boxes box1 = make_box(20, 20, 20) box2 = make_box(gp_Pnt(10, 10, 10), 20, 20, 20) # Boolean cut (subtraction) - box1 minus box2 result_cut = boolean_cut(box1, box2) print("Cut operation: removed box2 volume from box1") # Boolean fuse (union) - combine volumes box3 = make_box(15, 15, 15) box4 = make_box(gp_Pnt(10, 0, 0), 15, 15, 15) result_fuse = boolean_fuse(box3, box4) print("Fuse operation: combined two boxes into single solid") # Operations include edge refinement and fusion # Automatically cleans up redundant edges and optimizes topology ``` -------------------------------- ### Create Basic Shapes using OCC.Construct in Python Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt This snippet demonstrates creating primitive CAD shapes like boxes, vertices, edges, wires, and faces using functions from OCCUtils.Construct. It requires OCCUtils.Construct and OpenCASCADE geometry primitives (gp_Pnt, gp_Vec). ```python from OCCUtils.Construct import ( make_box, make_vertex, make_edge, make_wire, make_face, make_circle, gp_Pnt, gp_Vec ) # Create a box solid box = make_box(10, 20, 30) # width, height, depth print(f"Box created: {box}") # Create vertices at specific coordinates v1 = make_vertex(gp_Pnt(0, 0, 0)) v2 = make_vertex(gp_Pnt(10, 0, 0)) v3 = make_vertex(gp_Pnt(10, 10, 0)) # Create edge between two points edge = make_edge(gp_Pnt(0, 0, 0), gp_Pnt(10, 10, 10)) # Create a circle edge circle_edge = make_circle(gp_Pnt(0, 0, 0), 5.0) # Create wire from multiple edges edges = [ make_edge(gp_Pnt(0, 0, 0), gp_Pnt(10, 0, 0)), make_edge(gp_Pnt(10, 0, 0), gp_Pnt(10, 10, 0)), make_edge(gp_Pnt(10, 10, 0), gp_Pnt(0, 10, 0)), make_edge(gp_Pnt(0, 10, 0), gp_Pnt(0, 0, 0)) ] wire = make_wire(edges) # Create face from wire face = make_face(wire) print(f"Face area calculated from wire boundary") ``` -------------------------------- ### Create Polygons using OCC.Construct in Python Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt This function set from OCCUtils.Construct creates open and closed polygonal wires from sequences of points. It requires OCCUtils.Construct and gp_Pnt. The `closed` parameter determines if the last point connects to the first. ```python from OCCUtils.Construct import make_polygon, make_closed_polygon, gp_Pnt # Create open polygon points = [ gp_Pnt(0, 0, 0), gp_Pnt(10, 0, 0), gp_Pnt(10, 10, 0), gp_Pnt(5, 15, 5) ] open_polygon = make_polygon(points, closed=False) print(f"Open polygon with {len(points)} points") # Create closed polygon (automatically connects last to first) closed_polygon = make_closed_polygon( gp_Pnt(0, 0, 0), gp_Pnt(10, 0, 0), gp_Pnt(10, 10, 0), gp_Pnt(0, 10, 0) ) print(f"Closed rectangular polygon created") # Nested list of points also supported nested_points = [ [gp_Pnt(0, 0, 0), gp_Pnt(5, 0, 0)], [gp_Pnt(5, 5, 0), gp_Pnt(0, 5, 0)] ] polygon = make_polygon(nested_points, closed=True) ``` -------------------------------- ### Traverse Topology with Topo Class in Python Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt The Topo class allows traversal and querying of topological relationships (faces, edges, vertices, etc.) within a 3D shape. It requires OCC.Core and pythonocc-utils. It returns various topological entities and counts. ```python from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCCUtils.Topology import Topo # Create a box shape box = BRepPrimAPI_MakeBox(10, 20, 30).Shape() topo = Topo(box) # Iterate through all faces for face in topo.faces(): print(f"Face found: {face}") # Count topological elements print(f"Number of faces: {topo.number_of_faces()}") # 6 print(f"Number of edges: {topo.number_of_edges()}") # 12 print(f"Number of vertices: {topo.number_of_vertices()}") # 8 # Get edges connected to a specific face first_face = next(topo.faces()) edges_from_face = list(topo.edges_from_face(first_face)) print(f"Edges on first face: {len(edges_from_face)}") # Get faces connected to an edge first_edge = next(topo.edges()) faces_from_edge = list(topo.faces_from_edge(first_edge)) print(f"Faces sharing first edge: {len(faces_from_edge)}") ``` -------------------------------- ### Measure Distances and Project Points (Python) Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Provides functions for calculating the minimum distance between two shapes and for projecting a point onto a curve. It utilizes `minimum_distance` to find the closest points on given shapes and `project_point_on_curve` to determine the nearest point on a curve and its parameter. Dependencies include `OCCUtils.Common` and `OCCUtils.Construct`. ```python from OCCUtils.Common import minimum_distance, project_point_on_curve from OCCUtils.Construct import make_box, make_edge, gp_Pnt from OCC.Core.BRep import BRep_Tool # Create two shapes box1 = make_box(10, 10, 10) box2 = make_box(gp_Pnt(15, 0, 0), 10, 10, 10) # Calculate minimum distance min_dist, points_on_shp1, points_on_shp2 = minimum_distance(box1, box2) print(f"Minimum distance between boxes: {min_dist}") print(f"Closest point on box1: {points_on_shp1[0].X()}, " f"{points_on_shp1[0].Y()}, {points_on_shp1[0].Z()}") print(f"Closest point on box2: {points_on_shp2[0].X()}, " f"{points_on_shp2[0].Y()}, {points_on_shp2[0].Z()}") # Project point onto curve edge = make_edge(gp_Pnt(0, 0, 0), gp_Pnt(10, 10, 0)) curve = BRep_Tool().Curve(edge)[0] point_to_project = gp_Pnt(5, 0, 0) parameter, nearest_point = project_point_on_curve(curve, point_to_project) print(f"Projected point parameter: {parameter}") print(f"Nearest point on curve: {nearest_point.X()}, " f"{nearest_point.Y()}, {nearest_point.Z()}") ``` -------------------------------- ### Calculate Tangent and Divide Edge Source: https://context7.com/tpaviot/pythonocc-utils/llms.txt Demonstrates calculating the tangent direction at a specific parameter on an edge and dividing an edge into a specified number of points. Requires an 'edge' object with 'DiffGeom' and 'divide_by_number_of_points' methods. ```python # Calculate tangent at parameter tangent_dir = edge.DiffGeom.tangent(mid_param) print(f"Tangent direction: {tangent_dir.X()}, {tangent_dir.Y()}, {tangent_dir.Z()}") # Divide edge into points points = edge.divide_by_number_of_points(10) print(f"Divided edge into {len(points)} points") for param, pnt in points[:3]: # show first 3 print(f" Parameter {param}: ({pnt.X()}, {pnt.Y()}, {pnt.Z()}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.