Intersection of two Surfaces

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Intersection of two Surfaces

Post by microelly2 »

I want ot compute the intersection curve of two bspline surfaces.
Is there a method to do this the direct way?

at the moment i work around and calculate the intersection of two generated 3d parts and extract the curve. :roll:
or another question:
can i force to interpolate a bspline curve to lie on a given face?
my workaround is to make a projection of the bspline to the face.
User avatar
Chris_G
Veteran
Posts: 2578
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Intersection of two Surfaces

Post by Chris_G »

Hi,
I want ot compute the intersection curve of two bspline surfaces.
Is there a method to do this the direct way?
This should be what you're after :

Code: Select all

list_of_intersection_curves = surface1.intersectSS(surface2)
can i force to interpolate a bspline curve to lie on a given face?
my workaround is to make a projection of the bspline to the face.
If you can get the points you want to interpolate in the parametric space of the surface ( with distToShape, for example ), then you can build a 2D BsplineCurve that interpolates these points, and then apply this 2D curve on the Surface :

Code: Select all

from FreeCAD import Base
# the points to interpolate
p0 = Base.Vector2d(0.1,0.1)
p1 = Base.Vector2d(0.4,0.9)
p2 = Base.Vector2d(0.8,0.2)
pts2d = [p0,p1,p2]

bs2d = Part.Geom2d.BSplineCurve2d()
bs2d.interpolate(pts2d)

bs2d.Degree
# Degree = 2
bs2d.getPoles()
# [Vector2 (0.1, 0.1), Vector2 (0.32959173700183053, 1.648359991248584), Vector2 (0.8, 0.2)]

# apply the 2D BScurve on the surface
e1 = bs2d.toShape(the_surface)
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Intersection of two Surfaces

Post by microelly2 »

thank you for this intro,
I never used this kind of methods before.
User avatar
Chris_G
Veteran
Posts: 2578
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Intersection of two Surfaces

Post by Chris_G »

Werner ported the Geom2d package a couple of months ago ( many thanks for that ).
A brand new toolbox to play with ... :D
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Intersection of two Surfaces

Post by microelly2 »

Chris_G wrote:Werner ported the Geom2d package a couple of months ago ( many thanks for that ).
A brand new toolbox to play with ... :D
very interesting, so I can rethink a lot of ideas.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Intersection of two Surfaces

Post by microelly2 »

Now we can draw on our models :D :D
bp_430.png
bp_430.png (158.45 KiB) Viewed 3533 times

Code: Select all


def drawcurve():

	w=App.ActiveDocument.Drawing_on_MyShoe__Face2.Shape
	t=App.ActiveDocument.MyShoe.Shape.Face2

	pts=[p.Point for p in w.Vertexes]
	sf=t.Surface

	pts2da=[sf.parameter(p) for p in pts[1:]]
	pts2d=[Base.Vector2d(p[0],p[1]) for p in pts2da]

	bs2d = Part.Geom2d.BSplineCurve2d()
	bs2d.interpolate(pts2d)

	e1 = bs2d.toShape(t)
	Part.show(e1)

see: https://forum.freecadweb.org/viewtopic. ... 80#p166688
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Intersection of two Surfaces

Post by DeepSOIC »

Interesting. I have a pen on my laptop, would be interesting to super-quickly draw out mockup models with assistance of this tool...
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Intersection of two Surfaces

Post by microelly2 »

https://github.com/microelly2/freecad-nurbs

1. menu nurbs -> create shoe
2. select a face of the MyShoe
3. menu curves-> draw on face

4.move the mouse over the face
5. press "Enter" to register a point
repeat 4,5 - a red polygon is drawn

dialog -> Apply
a black curve is generated

I use the enter key, what is a good key for the pen?
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Intersection of two Surfaces

Post by DeepSOIC »

microelly2 wrote:4.move the mouse over the face5. press "Enter" to register a pointrepeat 4,5 - a red polygon is drawn
Doesn't work. When I move pen (equivalent to hovering mouse), I see lots of coordinates printed to report view. When I hit Enter, this is printed:
File "C:\Users\User\AppData\Roaming\FreeCAD\Mod\freecad-nurbs\nurbswb\facedraw.py", line 113, in eventFilter
self.update()
--> File "C:\Users\User\AppData\Roaming\FreeCAD\Mod\freecad-nurbs\nurbswb\facedraw.py", line 249, in update
self.dialog.commit_noclose()
--> AttributeError: 'MyWidget' object has no attribute 'commit_noclose'
, and then coordinates keep on coming...

No red curve on screen, no activity at all apart from preselection highlighting.

When I click Apply, I get this:
File "C:\Users\User\AppData\Roaming\FreeCAD\Mod\freecad-nurbs\nurbswb\facedraw.py", line 288, in apply
drawcurve(self.ef.wire,self.ef.subobj)
--> File "C:\Users\User\AppData\Roaming\FreeCAD\Mod\freecad-nurbs\nurbswb\facedraw.py", line 271, in drawcurve
bs2d.interpolate(pts2d)
--> OCCError: NCollection_Array1::Create
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Intersection of two Surfaces

Post by microelly2 »

DeepSOIC wrote: --> File "C:\Users\User\AppData\Roaming\FreeCAD\Mod\freecad-nurbs\nurbswb\facedraw.py", line 249, in update
self.dialog.commit_noclose()
there is a enter key and a return key,
you pressed the return key ( e.key()== QtCore.Qt.Key_Return
do you have a enter key (e.key()== QtCore.Qt.Key_Enter

--> OCCError: NCollection_Array1::Create
because there is no point stored
Post Reply