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: 

Interference of solids and line segment

2 REPLIES 2
Reply
Message 1 of 3
Arias79
347 Views, 2 Replies

Interference of solids and line segment

Hello.

I'm trying to figure a "fast" algorithm to obtain the amount of material (in linear distance) between 2 points within an assembly i.e. if I draw a line between any two points P1 & P2 in an assembly, what is the length of this segment that goes trogh material and what is the length that goes trough empty space?

For now I'm creating a thin cyilinder as a new part, place it with one end at P1 and the other end at P2, calculate the inerference volume of this body with the rest of the assembly and divide this number by the total volume of the cylinder. This method gives me the rigth answer, but has some problmes:

1. It is VERY slow, and I want to call this function lots of times.
3. Is not accurate due to the finite diameter of the cylinder.
2. If the assembly has some interferences, the result is wrong (acounting same volume more than once)

Any idea to improve this calculation will be much appreciated.
Tanks in advance

Pablo

Tags (1)
2 REPLIES 2
Message 2 of 3
adam.nagy
in reply to: Arias79

Hi Pablo,

 

It probably depends on the model, but in my tests the following code I wrote seemed to work fast enough:

Sub CheckIntersection()
    Dim doc As AssemblyDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim wp1 As WorkPoint
    Dim wp2 As WorkPoint
    
    Set wp1 = doc.SelectSet(1)
    Set wp2 = doc.SelectSet(2)
    
    Dim sp As Point
    Set sp = wp1.Point
    
    Dim ep As Point
    Set ep = wp2.Point
    
    Dim dir As Vector
    Set dir = sp.VectorTo(ep)
    
    Dim dist As Double
    dist = sp.DistanceTo(ep)
    
    Dim filter(1 To 1) As SelectionFilterEnum
    filter(1) = kPartFaceFilter
    
    Dim pts As Variant
    Dim oe As ObjectsEnumerator
    Set oe = doc.ComponentDefinition.FindUsingVector( _
        sp, dir.AsUnitVector, filter, , , , pts)
        
    Dim i As Integer
    For i = 1 To oe.Count
        Dim pt As Point
        Set pt = pts(i)
            
        ' If we are going beyond the end point then
        ' let's stop
        If sp.DistanceTo(pt) > dist Then
            Exit For
        End If
            
        Dim f As Face
        Set f = oe(i)
        
        Dim se As SurfaceEvaluator
        Set se = f.Evaluator
        
        Dim ptData() As Double
        pt.GetPointData ptData
        
        Dim normals() As Double
        se.GetNormalAtPoint ptData, normals
        
        Dim n As Vector
        Set n = ThisApplication.TransientGeometry.CreateVector()
        Call n.PutVectorData(normals)
        
        ' Check if the section up till the intersection point
        ' was inside a solid or outside
        ' If the face's normal is the same direction
        ' as we are going, then we are leaving the solid through
        ' this face
        Dim isInside As Boolean
        isInside = n.DotProduct(dir) > 0#
        
        Dim length As Double
        
        Select Case i
            Case 1:
                length = sp.DistanceTo(pt)
            Case oe.Count:
                length = ep.DistanceTo(pt)
            Case Else:
                length = pt.DistanceTo(pts(i - 1))
        End Select
        
        Debug.Print str(length) + " section inside solid = " + str(isInside)
    Next
End Sub

I hope this helps.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 3
Arias79
in reply to: adam.nagy

Thanks very much Adam.
This is a much more "elegant" solution.

Pablo

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

Post to forums  

Autodesk Design & Make Report