Development of a Curved Surface

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
saso
Posts: 1495
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Development of a Curved Surface

Postby saso » Mon Apr 13, 2020 8:35 am

Chris_G wrote:
Mon Apr 13, 2020 8:21 am
Here is another solution
Nice, very small differences on the curved (cylindrical) face :)

SharedScreenshot.png
SharedScreenshot.png (113.06 KiB) Viewed 158 times
Attachments
Flat_faces.FCStd
(67.09 KiB) Downloaded 4 times
User avatar
Chris_G
Posts: 1342
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Development of a Curved Surface

Postby Chris_G » Mon Apr 13, 2020 9:01 am

Thanks for the comparison.
I wanted to check against the mesh method, but my self-compiled FC doesn't have this functionality.
gsandy
Posts: 155
Joined: Sun Jan 27, 2019 7:07 pm
Location: Auckland New Zealand

Re: Development of a Curved Surface

Postby gsandy » Mon Apr 13, 2020 9:18 am

Thanks Guys, will look at them tomorrow.
User avatar
microelly2
Posts: 4690
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Development of a Curved Surface

Postby microelly2 » Mon Apr 13, 2020 1:49 pm

Chris_G wrote:
Mon Apr 13, 2020 8:21 am
Here is another solution
Nice to have this already.
If we adopt this to conic surfaces the most common developable surfaces can be flattend. :D
freedman
Posts: 1451
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Development of a Curved Surface

Postby freedman » Mon Apr 13, 2020 2:19 pm

I know some pipe welders that love to make paper templets for cutting fitment.
Thanks all.
User avatar
Chris_G
Posts: 1342
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Development of a Curved Surface

Postby Chris_G » Mon Apr 13, 2020 3:16 pm

microelly2 wrote:
Mon Apr 13, 2020 1:49 pm
Nice to have this already.
If we adopt this to conic surfaces the most common developable surfaces can be flattend. :D
This one should work on cones too :

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)

User avatar
microelly2
Posts: 4690
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Development of a Curved Surface

Postby microelly2 » Mon Apr 13, 2020 3:46 pm

Chris_G wrote:
Mon Apr 13, 2020 3:16 pm
This one should work on cones too :
There is still an error in your script ?!
here is my one

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))


dp_04_13_002.png
dp_04_13_002.png (64.27 KiB) Viewed 110 times
User avatar
Chris_G
Posts: 1342
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Development of a Curved Surface

Postby Chris_G » Mon Apr 13, 2020 4:37 pm

microelly2 wrote:
Mon Apr 13, 2020 3:46 pm
There is still an error in your script ?!
Oops, you're right. I need to rework it.
TheMarkster
Posts: 1566
Joined: Thu Apr 05, 2018 1:53 am

Re: Development of a Curved Surface

Postby TheMarkster » Mon Apr 13, 2020 5:38 pm

Chris_G wrote:
Mon Apr 13, 2020 3:16 pm

This one should work on cones too :
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?
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
User avatar
microelly2
Posts: 4690
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Development of a Curved Surface

Postby microelly2 » Mon Apr 13, 2020 6:25 pm

TheMarkster wrote:
Mon Apr 13, 2020 5:38 pm
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 orange