Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Algorithm - Does plane intersect solid?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
aelqabbany
610 Views, 6 Replies

Algorithm - Does plane intersect solid?

I am trying to write an algorithm (subroutine) to determine if a plane intersects a solid. I have prepared the code below which measures the minimum distance between each solid face to the plane, and it works, but it is very slow, especially as parts get larger and more complex.

 

Does anyone have an idea for a faster solution?

Thanks in advance

Sub Main()
	Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	Dim Solid1 As SurfaceBody = oCompDef.SurfaceBodies(1)
	Dim Plane As WorkPlane = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select Plane")
	MessageBox.Show(PlaneIntersectSolid(Solid1,Plane),"Does Plane intersect solid 1?")
	
End Sub

Function PlaneIntersectSolid(Solid1 As SurfaceBody, Plane As WorkPlane) As Boolean
	For Each oFace As Face In Solid1.Faces
		If ThisApplication.MeasureTools.GetMinimumDistance(Plane, oFace) = 0 Then
			PlaneIntersectSolid = True
			Exit Function
		End If
	Next
	PlaneIntersectSolid = False
End Function
6 REPLIES 6
Message 2 of 7
Michael.Navara
in reply to: aelqabbany

Can you provide some performance counters?

Faces count:

Vertices count:

Measured time:

Message 3 of 7

Hi @aelqabbany,

 

try this approach (this is the Ilogic version):

 

Sub Main()
	Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	Dim Solid1 As SurfaceBody = oCompDef.SurfaceBodies(1)
	Dim workPlane As WorkPlane = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select Plane")
	
	Dim context As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	context.Add(IntersectionFound,true)
	
    Dim contextValueForIntersection As Double
  	contextValueForIntersection = ThisApplication.MeasureTools.GetMinimumDistance(Solid1, workPlane.Plane, , , context)
	
	If (contextValueForIntersection = 0) Then
		MessageBox.Show("Intersection is found")
	Else 
		MessageBox.Show("No intersection")
	End If	
End Sub

 

Check out my Add-InsPlace Fasteners AddIn    Quick Section View AddIn 

😀

Message 4 of 7

Wow, just wow. 

 

I ran my script and yours in a part with 319 faces.

 

My script took 3.97 seconds and yours took less than 0.01 seconds.

 

Could you explain to me how you used the NameValueMap type to get the measurements so quickly? Did Inventor still have to take 319 distance measurements?

 

Thanks

 

Message 5 of 7

I think some more optimal algorithms are used for measurements in this case (maybe not even actual distance measurments to the faces)

 

Using the NameValueMap is simple. You create an object and pass as an argument to MeasureTools.GetMinimumDistance method.

 

Please check Inventor Api for this method:

https://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-240D2F92-2701-4D9D-BCE7-02759538E2FC

 

Here is a good article as well:

https://adndevblog.typepad.com/manufacturing/2014/01/vector-of-minimum-distance.html

 

 

Message 6 of 7

Thank you very much!
Message 7 of 7

I find it very interesting that this code is working without throwing any errors, because according to the online help page for that method, a SurfaceBody object is not listed as a valid type of input entity.  It certainly is nice that it is working here though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report