Apply 2D or 3D fillet to a wire :param radius: the radius of the fillet, must be > zero :param vertices: the vertices to delete (where the fillet will be applied). By default all vertices are deleted except ends of open wires. :return: A wire with fillete
(self, radius: float, vertices: Iterable[Vertex] | None = None)
| 3162 | return f.chamfer2D(d, vertices).outerWire() |
| 3163 | |
| 3164 | def fillet(self, radius: float, vertices: Iterable[Vertex] | None = None) -> Wire: |
| 3165 | """ |
| 3166 | Apply 2D or 3D fillet to a wire |
| 3167 | |
| 3168 | :param radius: the radius of the fillet, must be > zero |
| 3169 | :param vertices: the vertices to delete (where the fillet will be applied). By default |
| 3170 | all vertices are deleted except ends of open wires. |
| 3171 | :return: A wire with filleted corners |
| 3172 | """ |
| 3173 | |
| 3174 | edges = list(self) |
| 3175 | all_vertices = self.Vertices() |
| 3176 | n_edges = len(edges) |
| 3177 | n_vertices = len(all_vertices) |
| 3178 | |
| 3179 | newEdges = [] |
| 3180 | currentEdge = edges[0] |
| 3181 | |
| 3182 | verticesSet = set(vertices) if vertices else set() |
| 3183 | |
| 3184 | for i in range(n_edges): |
| 3185 | if i == n_edges - 1 and not self.IsClosed(): |
| 3186 | break |
| 3187 | nextEdge = edges[(i + 1) % n_edges] |
| 3188 | |
| 3189 | # Create a plane that is spanned by currentEdge and nextEdge |
| 3190 | currentDir = currentEdge.tangentAt(1) |
| 3191 | nextDir = nextEdge.tangentAt(0) |
| 3192 | normalDir = currentDir.cross(nextDir) |
| 3193 | |
| 3194 | # Check conditions for skipping fillet: |
| 3195 | # 1. The edges are parallel |
| 3196 | # 2. The vertex is not in the vertices white list |
| 3197 | if normalDir.Length == 0 or ( |
| 3198 | all_vertices[(i + 1) % n_vertices] not in verticesSet |
| 3199 | and bool(verticesSet) |
| 3200 | ): |
| 3201 | newEdges.append(currentEdge) |
| 3202 | currentEdge = nextEdge |
| 3203 | continue |
| 3204 | |
| 3205 | # Prepare for using ChFi2d_FilletAPI |
| 3206 | pointInPlane = currentEdge.Center().toPnt() |
| 3207 | cornerPlane = gp_Pln(pointInPlane, normalDir.toDir()) |
| 3208 | |
| 3209 | filletMaker = ChFi2d_FilletAPI( |
| 3210 | currentEdge.wrapped, nextEdge.wrapped, cornerPlane |
| 3211 | ) |
| 3212 | |
| 3213 | ok = filletMaker.Perform(radius) |
| 3214 | if not ok: |
| 3215 | raise ValueError(f"Failed fillet at vertex {i+1}!") |
| 3216 | |
| 3217 | # Get the result of the fillet operation |
| 3218 | thePoint = next(iter(nextEdge)).Center().toPnt() |
| 3219 | res_arc = filletMaker.Result( |
| 3220 | thePoint, currentEdge.wrapped, nextEdge.wrapped |
| 3221 | ) |