How to check whether a shape is completely inside another on

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Anto
Posts: 2
Joined: Mon May 12, 2014 9:03 pm

How to check whether a shape is completely inside another on

Post by Anto »

I need to check whether a shape (mostly 2D shapes) is completely surrounded by a second one, i.e. with no intersections and being "inside".
I tried cut and common, but unsuccesfully, I even tried distToShape, hoping for some negative distance returned when completely inside. Also unsuccesfully. See attached script.
Thanks for suggestions.
Anto
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to check whether a shape is completely inside anothe

Post by NormandC »

Hello Anto,

Welcome here. I believe you forgot to attach your script...
Anto
Posts: 2
Joined: Mon May 12, 2014 9:03 pm

Re: How to check whether a shape is completely inside anothe

Post by Anto »

Oops, thanks.
I copy it here, instead of attacching:
from FreeCAD import Base
import Part

def rectOutline(W,H):
rol=Part.makePolygon([Base.Vector(0,0,0),Base.Vector(W,0,0),Base.Vector(W,0,0),Base.Vector(W,H,0),Base.Vector(0,H,0),Base.Vector(0,0,0)])
rol.translate(Base.Vector(-W/2,-H/2,0))
return rol

rec= rectOutline(2.2,2.2)
smallC= Part.makeCircle(1.0,Base.Vector(0.0,0.0,0.0))
largeC= Part.makeCircle(2.0,Base.Vector(4.0,0.0,0.0))
inLargeC= Part.makeCircle(1.0,Base.Vector(4.0,0.0,0.0))
Part.show(rec)
Part.show(smallC)
Part.show(largeC)
Part.show(inLargeC)
Gui.SendMsgToActiveView("ViewFit")
d1, pts, geom = smallC.distToShape(largeC)
d2, pts, geom = inLargeC.distToShape(largeC)
d3, pts, geom = rec.distToShape(largeC)
d4, pts, geom = rec.distToShape(smallC)
print 'd1= ',d1,' d2= ', d2, ' d3= ', d3,' d4= ', d4
Post Reply