Nice, very small differences on the curved (cylindrical) face
Nice, very small differences on the curved (cylindrical) face
This one should work on cones too :microelly2 wrote: ↑Mon Apr 13, 2020 1:49 pmNice to have this already.
If we adopt this to conic surfaces the most common developable surfaces can be flattend.
Code: Select all
import FreeCAD
import FreeCADGui
import Part
def nurbs_flat_cylinder(face):
l1 = face.Surface.uIso(face.ParameterRange[0])
e1 = l1.toShape(*face.ParameterRange[2:])
c1 = face.Surface.vIso(face.ParameterRange[2])
t1 = c1.tangent(c1.FirstParameter)[0]
l = c1.length()
e2 = e1.copy()
e2.translate(t1*l)
rs = Part.makeRuledSurface(e1,e2)
bs = rs.Surface
bs.exchangeUV()
bs.setUKnots(face.ParameterRange[0:2])
return bs
def nurbs_flat_cone(face):
c1 = face.Surface.vIso(face.ParameterRange[2])
c2 = face.Surface.vIso(face.ParameterRange[3])
h = c1.value(c1.FirstParameter).distanceToPoint(c2.value(c2.FirstParameter))
c1.Center = FreeCAD.Vector(0,0,0)
c2.Center = FreeCAD.Vector(0,0,0)
c2.Radius = c1.Radius + h
e1 = c1.toShape()
e2 = c2.toShape()
rs = Part.makeRuledSurface(e1,e2)
bs = rs.Surface
bs.setVKnots(face.ParameterRange[2:])
return bs
def flatten_face(face):
if isinstance(face.Surface, Part.Cylinder):
flat_face = nurbs_flat_cylinder(face)
elif isinstance(face.Surface, Part.Cone):
flat_face = nurbs_flat_cone(face)
else:
return None
cos = [face.curveOnSurface(e) for e in face.Edges]
edges = [c[0].toShape(flat_face, c[1], c[2]) for c in cos]
wires = [Part.Wire(el) for el in Part.sortEdges(edges)]
f = Part.Face(wires)
f.validate()
if f.isValid():
return f
else:
return Part.Compound(wires)
sel = FreeCADGui.Selection.getSelectionEx()
face = sel[0].SubObjects[0]
flat_face = flatten_face(face)
if flat_face:
Part.show(flat_face)
There is still an error in your script ?!
Code: Select all
sel = FreeCADGui.Selection.getSelectionEx()
face = sel[0].SubObjects[0]
f=face.toNurbs().Face1
sf=f.Surface
startA=f.valueAt(0,0)
apex=face.Surface.Apex
r0=(startA-apex).Length
r=face.Surface.Radius
import math
def uv2p(u,v):
devp=FreeCAD.Vector((r0+v)*math.cos(r/r0*u),(r0+v)*math.sin(r/r0*u))
return devp
col=[]
for e in face.Edges:
print (e)
pts=e.discretize(100)
ptsn=[]
for p in pts:
try:
[u,v]=sf.parameter(p)
#print(u,v,p)
ptsn += [uv2p(u,v)]
#ptsn += [FreeCAD.Vector(u,v)]
except:
print ("error",p)
try:
pol=Part.makePolygon(ptsn)
Part.show(pol)
print (pol.Length)
col += [pol]
except:
col += [e]
#Part.show(Part.Compound(col))
Oops, you're right. I need to rework it.
Very nice! This one seems to work very well for me in a couple tests I made, one with a cone cut from a cylinder, the other with a sphere cut from a cone. Any way to include support for a face made by cutting something from a sphere?
You cannot develope a sphere. Only faces with gaussian curvature zero can be developed. For such faces you only can split them into small segmets and make some deformation: example - the shell of an orangeTheMarkster wrote: ↑Mon Apr 13, 2020 5:38 pmAny way to include support for a face made by cutting something from a sphere?