curveOnSurface

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
edwilliams16
Veteran
Posts: 3112
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

curveOnSurface

Post by edwilliams16 »

I understand it in this context;

Start with a face of some (possibly curvy) object

Code: Select all

edge = face.Edges[0]  #pick an edge
curv, fp, lp = face.curveOnSurface(edge) #curv is 2D curve trimmed by (fp, lp) its FirstParameter and LastParameter
reconstructed_edge = curv.toShape(face, fp,lp)
so face.curveOnSurface(edge) maps the edge on the surface on which face lies onto flat parametric (u, v) space. The inverse mapping is curv.toShape(face, fp, lp) which takes the 2D curve, limited by (fp, lp), onto the surface on which face lies.

However, I don't know just what

Code: Select all

indx = 0
curv, obj, placement, fp, lp = edge.curveOnSurface(indx)
is doing - particularly what is indx indexing?
@Chris_G is an expert here.
User avatar
Chris_G
Veteran
Posts: 2580
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: curveOnSurface

Post by Chris_G »

edwilliams16 wrote: Fri Aug 05, 2022 4:35 am so face.curveOnSurface(edge) maps the edge on the surface on which face lies
More precisely, or maybe because english is not my native language, I would say that face.curveOnSurface(edge) returns the 2D representation of edge on face, if it already exist, otherwise, one has to project edge on face and use the projected edge instead.
edwilliams16 wrote: Fri Aug 05, 2022 4:35 am However, I don't know just what

indx = 0
curv, obj, placement, fp, lp = edge.curveOnSurface(indx)

is doing - particularly what is indx indexing?
An edge can contain several 2D pcurves (on various surfaces), and possibly also a 3D curve (but in FC, this 3D curve is always automatically computed)
edge.curveOnSurface(indx) simply returns the pcurve stored at index indx.
So you have access to all the pcurves stored in the edge, without having to specify a face.

Example code, where an edge gets loaded with several pcurves :

Code: Select all

import Part
vec = FreeCAD.Vector

poles1 = [vec(0, 0, 0), vec(5, 5, 0), vec(10, 0, 0)]
poles2 = [vec(-5, 0, 5), vec(5, 10, 5), vec(15, 0, 3)]
poles3 = [vec(-3, 0, 8), vec(5, 12, 8), vec(20, 0, 10)]

e1 = Part.BSplineCurve(poles1).toShape()
e2 = Part.BSplineCurve(poles2).toShape()
e3 = Part.BSplineCurve(poles3).toShape()

rs1 = Part.makeRuledSurface(e1, e2)
ext = e1.extrude(vec(0,0,10))
rs2 = Part.makeRuledSurface(e1, e3)

e1.curveOnSurface(0)
e1.curveOnSurface(1)
e1.curveOnSurface(2)
e1.curveOnSurface(3)

edwilliams16
Veteran
Posts: 3112
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: curveOnSurface

Post by edwilliams16 »

Thanks again @Chris_G

I even understand now why there are four pcurves for the three faces. The extrusion face ext has two pcurves associated with it - the original e1 and the extruded copy.
I'm not sure I fully understand the role of the Placement pl in

Code: Select all

curv, surf, placement, fp, lp = edge.curveOnSurface(2)
Empirically, I find

Code: Select all

edge = curv.toShape(surf, fp, lp)
edge.Placement = pl

brings the extruded edge back to original location of e1
User avatar
Chris_G
Veteran
Posts: 2580
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: curveOnSurface

Post by Chris_G »

I don't know much about placement either, but I reached the same conclusion as yours.
Post Reply