Detect Point Collision

Detect Point Collision

Anonymous
Not applicable
2,144 Views
1 Reply
Message 1 of 2

Detect Point Collision

Anonymous
Not applicable

Hello everyone,

 

I want to check if a point collides with any body in a multibody assembly.

 

I would like to make a random point in an(y) assembly:

dim ivApp as Inventor.Application
set ivApp = ThisApplication

dim ivDoc as AssemblyDocument
set ivDoc = ivApp.ActiveDocument

dim ivComp as ComponentDefinition
set ivComp = ivDoc.ComponentDefinition

Randomize

dim randomX as Double
randomX = rnd() * (ivComp.RangeBox.MaxPoint.X - ivComp.RangeBox.MinPoint.X)

dim randomY as Double
randomY = rnd() * (ivComp.RangeBox.MaxPoint.Y - ivComp.RangeBox.MinPoint.Y)

dim randomZ as Double
randomZ = rnd() * (ivComp.RangeBox.MaxPoint.Z - ivComp.RangeBox.MinPoint.Z)

dim ivTrans as TransientGeometry
set ivTrans = ivApp.TransientGeometry

dim randomPoint as Inventor.Point
set randomPoint = ivTrans.createPoint(randomX, randomY, randomZ)

Then I want to check if these coordinates collide with any body in the active assembly:

 

dim boolCollision as boolean
boolCollision = DoesPointCollide(randomPoint)

Function DoesPointCollide(ivPoint as Inventor.Point) as Boolean

'--> Insert code here <--

End Function

Can anyone help me with that? I don't know if Inventor provides a function that can return a true or a false with a point, or something comparable. Or where I can find a collection with a description of the body where I can deduct if there is a collision or not.

 

I do know that Inventor provides a collision detection in the animation, but I'm not sure if that would be something that I can use.

 

 

Kind regards

0 Likes
Accepted solutions (1)
2,145 Views
1 Reply
Reply (1)
Message 2 of 2

LukeDavenport
Collaborator
Collaborator
Accepted solution

You're in luck Gilian. Once you've got the SurfaceBody object and the Point object you want to test, you can simply use SurfaceBody.IsPointInside.

Try the example below - just adjust the X Y Z values of 111, 222, 333 as you need in your code.

Hope this helps,

Luke

 

Dim oDoc As PartDocument = ThisApplication.ActiveEditDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oSurfaceBods As SurfaceBodies = oDef.SurfaceBodies
Dim oTestPoint As Inventor.Point = ThisApplication.TransientGeometry.CreatePoint(111,222,333)

' Debug - create a workpoint
Dim oWP As WorkPoint = oDef.WorkPoints.AddFixed(oTestPoint, False)

For Each oSurf As SurfaceBody In oSurfaceBods
Select Case oSurf.IsPointInside(New Double(2) {oTestPoint.X, oTestPoint.Y, oTestPoint.Z }) 
Case ContainmentEnum.kInsideContainment 
	MsgBox("Point is inside surface body: " & oSurf.Name)
Case ContainmentEnum.kOnContainment
	MsgBox("Point is ON surface body: " & oSurf.Name)
Case ContainmentEnum.kOutsideContainment
	MsgBox("Point is outside surface body: " & oSurf.Name)
End Select
Next

 

0 Likes