I am overwhelmed with gratitude at the quick and helpful responses I received on this intersectWIth problem; thanks all.
The solution posted by Hallex for filleting lines I have just stored away for future use, when I need to build a fillet functionality for SELECTING lines from user input.
However, for now, the line objects I need to fillet are stored in memory as DBObjectCollection, and haven't quite been added to a database transaction yet.
I do this because I first construct the lines in memory, then I fillet them, and then I use their coordinates to generate a polyline, including the coordinates of the arc created during the filleting process.
I am able to accomplish all of this successfully, ecpect that the filletLines function I am using utilizes the IntersectWIth function which just breaks everything. I paste the code I am using below.
To solve this intersectWith problem, I am particularly interested in the PlatformUtils.vb class for the Autodesk.AutoCAD.DatabaseServices namespace by Tony Tanzillo (thanks to DiningPhilosopher for providing the link)
What is the best way to implement this vb class so that its IntersectWIth method is the one called when I use the IntersectWIth method on a line?
Do I just create the PlatformUtils.vb class in the same project as my other vb classes?
Many thanks...
NB: Here is my filletLines code:
' Fillet functionality for this class; the lines must intersect with each other
Public Shared Sub filletLines(ByVal rad As Double, ByVal line1 As Line, _
ByVal line2 As Line)
Try
Dim intpts As New Point3dCollection()
' Get the intersection between lines
line1.IntersectWith(line2, Intersect.OnBothOperands, intpts, 0, 0)
' The lines must intersect with each other
If intpts.Count <> 1 Then Return
Dim ip As Point3d = intpts(0)
Dim midp1, midp2 As Point3d
' Compare points for line1, set the midpoint
If Not (line1.StartPoint.Equals(ip)) Then
line1.EndPoint = line1.StartPoint
line1.StartPoint = ip
End If
midp1 = line1.GetPointAtDist(rad)
' Compare points for line2, set the midpoint
If Not (line2.StartPoint.Equals(ip)) Then
line2.EndPoint = line2.StartPoint
line2.StartPoint = ip
End If
midp2 = line2.GetPointAtDist(rad)
' Get point on bisector
Dim midp As New Point3d((midp1.X + midp2.X) / 2.0, _
(midp1.Y + midp2.Y) / 2.0, (midp1.Z + midp2.Z) / 2.0)
' Get angles along lines from intersection
Dim ang1 As Double = angleFromX(ip, midp1)
Dim ang2 As Double = angleFromX(ip, midp2)
' Get bisector angle and then calculate angle between lines
Dim ang As Double = angleFromX(ip, midp)
Dim angc As Double = Math.Abs(ang2 - ang1)
' Get a half of them and then calculate hypotenuse
Dim bis As Double = angc / 2.0
Dim hyp As Double = rad / Math.Sin(bis)
' Calculate the center point of filleting arc
Dim cPoint As Point3d = polarPoint(ip, ang, hyp)
' Calculate another leg of a triangle
Dim dblCat As Double = Math.Sqrt((Math.Pow(hyp, 2)) - (Math.Pow(rad, 2)))
' Calculate start point of arc, end point of arc and define arc
Dim pStart As Point3d = polarPoint(ip, ang1, dblCat)
Dim pEnd As Point3d = polarPoint(ip, ang2, dblCat)
Dim arc As New Arc()
' Define the direction of the arc
If isLeft(midp2, ip, midp1) Then
arc = New Arc(cPoint, rad, angleFromX(cPoint, pEnd), _
angleFromX(cPoint, pStart))
Else : arc = New Arc(cPoint, rad, angleFromX(cPoint, pStart), _
angleFromX(cPoint, pEnd))
End If
' Trim lines by arc
line1.StartPoint = pStart
line2.StartPoint = pEnd
' Update the lines and arc properties for this class
m_line1 = line1
m_line2 = line2
m_arc = arc
Catch ex As Autodesk.AutoCAD.Runtime.Exception
acApp.ShowAlertDialog("Sorry, unable to fillet lines! " & ex.Message)
End Try
End Sub