Code: Select all
face = App.ActiveDocument.getObject('Face')
pts = [v.Point for v in face.Shape.OuterWire.Vertexes]
ptsclosed = pts + [pts[0]]
bs = Part.BSplineCurve()
bs.approximate(ptsclosed)
Part.show(bs.toShape(), "bsapprox")
Code: Select all
face = App.ActiveDocument.getObject('Face')
pts = [v.Point for v in face.Shape.OuterWire.Vertexes]
ptsclosed = pts + [pts[0]]
bs = Part.BSplineCurve()
bs.approximate(ptsclosed)
Part.show(bs.toShape(), "bsapprox")
Code: Select all
import Draft
doc = App.ActiveDocument
convert = 25.4
select = FreeCADGui.Selection.getSelection()[0]
wire = select.Shape.Wires[0]
KOUNT = 0
for pts in wire.Vertexes:
KOUNT = KOUNT + 1
X = pts.Point.x
Y = pts.Point.y
Z = pts.Point.z
if KOUNT == 1:
multlist = [[X, Y, Z]]
if KOUNT > 1:
multlist.append([X, Y, Z])
# print(pts.Point.x * .039370078)
print(pts.Point)
print(multlist)
K = KOUNT
ptss = []
for i in range(0, KOUNT):
K = K - 1
print('k', K)
print(multlist[K][0], multlist[K][1], multlist[K][2])
ptss.append(App.Vector(multlist[K][0], multlist[K][1], multlist[K][2]))
spline_from_wire = Draft.make_bspline(ptss)
doc.recompute()
Code: Select all
pts=new_wire.discretize(Number=nb)
Code: Select all
bspline=Part.BSplineCurve()
bspline.interpolate(bspline_pts)
bspline_shape=Part.Edge(bspline)
new_wire=Part.Wire([bspline_shape])
The points actually came from a discretization in the first place. This was a simplified example.jbi wrote: ↑Sat Mar 18, 2023 8:11 am Maybe trying to discretize the wireand run the approximation afterwards.Code: Select all
pts=new_wire.discretize(Number=nb)
I’ve been exploring interpolation. It may be the way to go. Thanks.Maybe you can try alsoCode: Select all
bspline=Part.BSplineCurve() bspline.interpolate(bspline_pts) bspline_shape=Part.Edge(bspline) new_wire=Part.Wire([bspline_shape])
Code: Select all
w=face.Shape.OuterWire
new_wire=Part.Wire(w)
tesselation=2
nb=int(new_wire.Length//tesselation)+1
pts=new_wire.discretize(Number=nb)
nw=Part.makePolygon(pts)
bspline_pts=pts #+[pts[0]]
bspline=Part.BSplineCurve()
bspline.interpolate(bspline_pts) #,PeriodicFlag=True)
bspline_shape=Part.Edge(bspline)
Part.show(bspline_shape)
Code: Select all
import FreeCAD
import Part
v3d = FreeCAD.Vector
def show_pts(pts):
"""Show points."""
for p_idx, pt in enumerate(pts):
pt_do = Part.show(Part.Vertex(pt), f'pts_{p_idx}')
pt_do.ViewObject.PointSize = 3
pt_do.ViewObject.PointColor = (1.0, 0.0, 0.0)
face = FreeCAD.ActiveDocument.getObject('Face')
out_wire_v = face.Shape.OuterWire.Vertexes
pts = [v.Point for v in out_wire_v]
# show_pts(pts)
ptsclosed = pts + [pts[0]]
bs = Part.BSplineCurve()
bs.approximate(ptsclosed, DegMin=2, DegMax=2)
Part.show(bs.toShape(), "bsapprox")
'''
LengthWeight = float, CurvatureWeight = float, TorsionWeight = float
If one of these arguments is not null, the functions approximates the
points using variational smoothing algorithm, which tries to minimize
additional criterium:
LengthWeight*CurveLength + CurvatureWeight*Curvature + TorsionWeight*Torsion
Continuity must be C0, C1(with DegMax >= 3) or C2(with DegMax >= 5).
'''
poly = Part.makePolygon(ptsclosed)
Part.show(poly, "polygon")
bs1 = Part.BSplineCurve()
bs1.approximate(ptsclosed, DegMin=2, DegMax=2, Continuity='C0', LengthWeight=1.0)
Part.show(bs1.toShape(), "bs1_tuned")
You have to think as a BSpline.
Code: Select all
help(Part.BSplineCurve)