- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have trouble to find the intersection point of two working axes which I created.
I would like to use the point in a sketch later.
I was expecting to find a method in the line object...but I could not. Maybe I oversaw it?
Here is my code so far, which is not working...and my math class days are quite a bit ago...(plus I would like with inventor methods where it is possible.)
Attached also my part becuase I maybe overcomplicating things(?)....the rule "CreateAssembly" is creating an ipt file. On the intersection of the volumes I need to have a cut out feature. After that I create with "CreateMultiBody" the assembly. My first attemp was to bottom up but with top down I expect to handle modifications in the ipt faster and once the configuration is done I produce the assembly parts.
Sub main()
' Get the active document
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
' Get the component definition (part)
Dim oCompDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition
' Get references to the two work axes by name
Dim oAxis1 As WorkAxis
Dim oAxis2 As WorkAxis
oAxis1 = oCompDef.WorkAxes.Item("Arbeitsachse1") ' Replace with the name of your first work axis
oAxis2 = oCompDef.WorkAxes.Item("Arbeitsachse2") ' Replace with the name of your second work axis
' Get the geometry of the work axes
Dim oLine1 As Line
Dim oLine2 As Line
oLine1 = oAxis1.Line
oLine2 = oAxis2.Line
' Call the function to find the intersection point
Dim intersectionPt As Point
intersectionPt = FindIntersectionPoint(oLine1, oLine2)
' Output the intersection point
If intersectionPt IsNot Nothing Then
MsgBox("Intersection Point: X=" & intersectionPt.X & ", Y=" & intersectionPt.Y & ", Z=" & intersectionPt.Z)
Else
MsgBox("No intersection point found.")
End If
End Sub
' Function to calculate the intersection point between two lines
Function FindIntersectionPoint(line1 As Line, line2 As Line) As Point
' Get the direction vectors of the lines
Dim dir1 As Vector
Dim dir2 As Vector
dir1 = line1.Direction.AsVector
dir2 = line2.Direction.AsVector
' Get the point on the first line (origin)
Dim pt1 As Point
pt1 = line1.RootPoint
' Get the point on the second line (origin)
Dim pt2 As Point
pt2 = line2.RootPoint
' Calculate the cross product of the direction vectors
Dim crossDir As Vector
crossDir = dir1.CrossProduct(dir2)
' If the cross product is nearly zero, the lines are parallel or coincident
If crossDir.Length < 0.000001 Then
MsgBox("The lines are parallel or coincident, no unique intersection point.")
Return Nothing
End If
' Calculate the intersection point using the parameter of the first line
Dim t As Double
t = (pt2 - pt1).DotProduct(crossDir) / dir1.DotProduct(crossDir)
' Calculate the intersection point
Dim intersectionPoint As Point
intersectionPoint = pt1 + dir1 * t
Return intersectionPoint
End
Solved! Go to Solution.