--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/1bbd1ee2-7ed7-472c-95ff-0439e34a1a1en%40googlegroups.com.
Hello,
I found this a nice challenge. Below is my implementation of Joe’s original question.
Adam, what kind of API would you for this? Just a method to the Wire class?
Regards,
#!/usr/bin/python
######################################################################
# An implementation of Joe Schroeder's question on the cadquery list
# of how to fillet an open wire.
#
# This code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# 2024-03-16 Sat
# Dov Grobgeld <dov.gr...@gmail.com>
######################################################################
import cadquery as cq
from cadquery import exporters
from OCP.gp import gp_Pln
from OCP.ChFi2d import ChFi2d_FilletAPI
def filletWire(wire: cq.Wire, radius: float) -> cq.Wire:
"""Fillets a wire in 2d or 3d
:param wire: The input wire to fillet. Currently only open wires are supported
:param radius: the radius of the fillet, must be > zero
:return: A wire with filleted corners
"""
edges = list(wire)
newEdges = []
currentEdge = edges[0]
for i in range(len(edges) - 1):
nextEdge = edges[i + 1]
# Create a plane that is spanned by currentEdge and nextEdge
currentDir = currentEdge.tangentAt(1)
nextDir = nextEdge.tangentAt(0)
normalDir = currentDir.cross(nextDir)
# Check if they are parallell and if so, skip adding a fillet
if normalDir.Length == 0:
newEdges.append(currentEdge)
currentEdge = nextEdge
continue
# Prepare for using ChFi2d_FilletAPI
pointInPlane = currentEdge.Center().toPnt()
cornerPlane = gp_Pln(pointInPlane, normalDir.toDir())
filletMaker = ChFi2d_FilletAPI(
currentEdge.wrapped, nextEdge.wrapped, cornerPlane
)
ok = filletMaker.Perform(radius)
if not ok:
raise RuntimeError(f"Failed fillet at vertex {i+1}!")
# Get the result of the fillet operation
thePoint = next(iter(nextEdge)).Center().toPnt()
res_arc = filletMaker.Result(thePoint, currentEdge.wrapped, nextEdge.wrapped)
newEdges.append(currentEdge)
newEdges.append(cq.Edge(res_arc))
currentEdge = nextEdge
# Add the last edge
newEdges.append(currentEdge)
return cq.Wire.assembleEdges(newEdges)
if __name__ == "__main__":
# Here is Joe Schroeder original question.
# Create a tube (actually a solid wire)
# using intersection points
# dimensions are inches
rotated_points = [
[0.000, 0.000, 0.000],
[-0.287, 1.183, -0.592],
[-1.404, 4.113, -2.787],
[-1.332, 1.522, 0.553],
[7.062, 0.433, -0.097
],
[8.539, -0.000, -0.000],
]
diameter = 0.25
fillet_radius = 0.560
pts_tuple = rotated_points
# Turn the polyline into a wire
wire = cq.Wire.makePolygon(rotated_points, close=False)
# Fillet the wire
wire = filletWire(wire, fillet_radius)
# The initial direction of the wire
normal_plane = cq.Plane(rotated_points[0], normal=wire.tangentAt(0))
result = cq.Workplane(normal_plane).circle(radius=diameter / 2).sweep(wire)
exporters.export(result, "filling-a-polyline-path.stl")
print("ok")
Thank you so much for this! It is the key to my app!But I'm not getting pyinstaller to work - I keep getting:File "cadquery\occ_impl\geom.py", line 5, in <module>
ModuleNotFoundError: No module named 'OCP'I've tried adding search paths to my .spec file, but no success...Any ideas?Thanks,Joe
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/baff811c-f23d-4b01-9bfc-d0e6aef649ebn%40googlegroups.com.