This is a question asked recently by an ADN developer: how can you determine if a point is located inside a watertight solid or outside?
There is no API that would directly return the information in Inventor. However here is a simple approach:
- Create a tiny spherical transient solid centered on the point, using specified tolerance as radius
- Check the volume of each solids, let’s call them vol1 and vol2
- Do a Boolean union between both solids, the sphere and the original solid
- Check volume of the union, if its volume is smaller than the sum of the two volumes, the solids intersect: volUnion < vol1 + vol2 –> point is contained by original solid.
Here is the VBA code that implements that solution:
Function PointContainment( _
point As point, _
body As SurfaceBody, _
tol As Double) As Boolean
PointContainment = False
Dim TxBrep As TransientBRep
Set TxBrep = ThisApplication.TransientBRep
Dim ptBody As SurfaceBody
Set ptBody = TxBrep.CreateSolidSphere(point, tol)
Dim vol1 As Double
vol1 = ptBody.volume(tol)
Dim vol2 As Double
vol2 = body.volume(tol)
Call TxBrep.DoBoolean(ptBody, body, kBooleanTypeUnion)
Dim volRes As Double
volRes = ptBody.volume(tol)
If (volRes < vol1 + vol2) Then
PointContainment = True
End If
End Function
Sub TestPointContainment()
Dim doc As PartDocument
Set doc = ThisApplication.ActiveDocument
Dim point As point
Set point = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)
Dim body As SurfaceBody
Set body = ThisApplication.CommandManager.Pick( _
kPartBodyFilter, "Pick a body: ")
Dim res As Boolean
res = PointContainment(point, body, 0.0001)
Debug.Print "Point containment: " & res
End Sub