I am writing a code that will find the intersection point of a circle with a line, both of which are in x-y plane.
Below is my code and to my dismay, the code could not give me the intersection point. Can someone point me out in the right direction on where the failure comes from. I am cluelss because there were no build errors and debug errors. A picture is also attached for greater clarity.
Imports System Imports System.Runtime.InteropServices Imports System.Drawing Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension Namespace sweeping Public Class intersecting <CommandMethod("ITSSPS")> Public Shared Sub SweepAlongPath() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Using tr As Transaction = db.TransactionManager.StartTransaction() 'getting point1 Dim ppo1 As PromptPointOptions = New PromptPointOptions(vbLf & "choose/click the centre of the first circle:") Dim ppr1 As PromptPointResult = doc.Editor.GetPoint(ppo1) Dim pt1 As Point3d = ppr1.Value If ppr1.Status = PromptStatus.Cancel Then Exit Sub Dim pdo11 As PromptDoubleOptions = New PromptDoubleOptions(vbLf & "The radius of the first cycle? Type 5 as 5.0") Dim pdr11 As PromptDoubleResult = doc.Editor.GetDouble(pdo11) Dim pd11 As Double = pdr11.Value If pdr11.Status = PromptStatus.Cancel Then Exit Sub 'getting point2 Dim ppo2 As PromptPointOptions = New PromptPointOptions(vbLf & "choose/click the centre of the second circle:") Dim ppr2 As PromptPointResult = doc.Editor.GetPoint(ppo2) Dim pt2 As Point3d = ppr2.Value If ppr2.Status = PromptStatus.Cancel Then Exit Sub Dim pdo21 As PromptDoubleOptions = New PromptDoubleOptions(vbLf & "The radius of the second cycle? Type 5 as 5.0") Dim pdr21 As PromptDoubleResult = doc.Editor.GetDouble(pdo21) Dim pd21 As Double = pdr21.Value If pdr21.Status = PromptStatus.Cancel Then Exit Sub Dim line12 As Line = New Line(pt1, pt2) Dim Cir1, Cir2 As Circle Cir1 = New Circle() : Cir1.Center = pt1 : Cir1.Normal = New Vector3d(0, 0, 1) : Cir1.Radius = pd11 Cir2 = New Circle() : Cir2.Center = pt2 : Cir2.Normal = New Vector3d(0, 0, 1) : Cir2.Radius = pd21 Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Dim Cir11 As Entity = DirectCast(Cir1, Entity) Dim line121 As Entity = DirectCast(line12, Entity) btr.AppendEntity(Cir11) tr.AddNewlyCreatedDBObject(Cir11, True) btr.AppendEntity(line121) tr.AddNewlyCreatedDBObject(line121, True) Dim its3dpts As Point3dCollection = New Point3dCollection() line121.IntersectWith(Cir11, Intersect.OnBothOperands, its3dpts, IntPtr.Zero, IntPtr.Zero) For Each pt3d As Point3d In its3dpts Dim ptt As Point3d = pt3d Dim Cir3 As Circle = New Circle() Cir3.Center = ptt : Cir3.Normal = New Vector3d(0, 0, 1) : Cir3.Radius = 450 ed.WriteMessage(pt3d.ToString) btr.AppendEntity(Cir3) tr.AddNewlyCreatedDBObject(Cir3, True) Next tr.Commit() End Using End Sub End Class End Namespace
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
private Point3dCollection GetIntersections1(Point3d pt1, double rad1, Point3d pt2, double rad2) { Point3dCollection result = new Point3dCollection(); LineSegment3d line = new LineSegment3d(pt1, pt2); CircularArc3d circ1 = new CircularArc3d(pt1, Vector3d.ZAxis, rad1); CircularArc3d circ2 = new CircularArc3d(pt2, Vector3d.ZAxis, rad2); Point3d[] inters1 = circ1.IntersectWith(line); if (inters1 != null) result.Add(inters1[0]); Point3d[] inters2 = circ2.IntersectWith(line); if (inters2 != null) result.Add(inters2[0]); return result; }
private Point3dCollection GetIntersections2(Point3d pt1, double rad1, Point3d pt2, double rad2) { Point3dCollection result = new Point3dCollection(); double dist = pt1.DistanceTo(pt2); if (dist >= rad1) result.Add(pt1 + (pt2 - pt1).GetNormal() * rad1); if (dist >= rad2) result.Add(pt2 + (pt1 - pt2).GetNormal() * rad2); return result; }
Can't find what you're looking for? Ask the community or share your knowledge.