.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

intersection of three spheres (get a solid3d)

1 REPLY 1
Reply
Message 1 of 2
Anonymous
1008 Views, 1 Reply

intersection of three spheres (get a solid3d)

3 spheres.jpg3 spheres top.jpg3 spheres intersected.jpg

 

 

The  first and second figure shows three spheres. What I wanted to customize is to get the common intersection region among the three spheres(seen in third figure). Below is my code.

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
{code here} Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Dim its_points As Point3dCollection = New Point3dCollection() its_points = Getcriticalpoints(pt1, pd11, pd12, pt2, pd21, pd22, pt3, pd31, pd32) Dim n_of_itspts As Integer = its_points.Count Dim i As Integer = 0 For Each pt3d As Point3d In its_points Dim ptt As Point3d = pt3d Dim sph As Solid3d = New Solid3d() sph.CreateSphere(rad) sph.TransformBy(Matrix3d.Displacement(ptt - Point3d.Origin)) btr.AppendEntity(sph) tr.AddNewlyCreatedDBObject(sph, True) sphere_ID(i) = sph.ObjectId i = i + 1 Next Dim intersection_points1 As Point3dCollection = New Point3dCollection() Dim intersection_points2 As Point3dCollection = New Point3dCollection() Dim sph1 As Solid3d = tr.GetObject(sphere_ID(0), OpenMode.ForRead) Dim sph2 As Solid3d = tr.GetObject(sphere_ID(1), OpenMode.ForRead) Dim sph3 As Solid3d = tr.GetObject(sphere_ID(2), OpenMode.ForRead) sph1.IntersectWith(sph2, Intersect.OnBothOperands, intersection_points1, IntPtr.Zero, IntPtr.Zero) sph1.IntersectWith(sph3, Intersect.OnBothOperands, intersection_points2, IntPtr.Zero, IntPtr.Zero) btr.AppendEntity(sph1) tr.AddNewlyCreatedDBObject(sph1, True) tr.Commit() end using end sub Private Shared Function Getcriticalpoints(ByVal center1 As Point3d, ByVal rad1 As Double, ByVal height1 As Double, ByVal center2 As Point3d, ByVal rad2 As Double, ByVal height2 As Double, ByVal center3 As Point3d, ByVal rad3 As Double, ByVal height3 As Double) As Point3dCollection Dim result As Point3dCollection = New Point3dCollection Dim line12 As LineSegment3d = New LineSegment3d(center1, center2) Dim line13 As LineSegment3d = New LineSegment3d(center1, center3) Dim line12_dis As Double = line12.Length : Dim line13_dis As Double = line13.Length Dim circ1 As CircularArc3d = New CircularArc3d(center1, Vector3d.ZAxis, rad1) Dim circ2 As CircularArc3d = New CircularArc3d(center2, Vector3d.ZAxis, rad2) Dim circ3 As CircularArc3d = New CircularArc3d(center3, Vector3d.ZAxis, rad3) Dim its212() As Point3d = circ2.IntersectWith(line12) If (Not (its212) Is Nothing) Then Dim point1 As Point3d = New Point3d(its212(0).X, its212(0).Y, its212(0).Z + height2) result.Add(point1) End If Dim its313() As Point3d = circ3.IntersectWith(line13) If (Not (its313) Is Nothing) Then Dim point2 As Point3d = New Point3d(its313(0).X, its313(0).Y, its313(0).Z + height3) result.Add(point2) End If If line12_dis >= line13_dis Then Dim its112() As Point3d = circ1.IntersectWith(line12) If (Not (its112) Is Nothing) Then Dim point3 As Point3d = New Point3d(its112(0).X, its112(0).Y, its112(0).Z + height1) result.Add(point3) End If Else Dim its113() As Point3d = circ1.IntersectWith(line13) If (Not (its113) Is Nothing) Then Dim point4 As Point3d = New Point3d(its113(0).X, its113(0).Y, its113(0).Z + height1) result.Add(point4) End If End If Return result End Function end class end namespace

the debug process will be broken at 

ph1.IntersectWith(sph2, Intersect.OnBothOperands, intersection_points1, IntPtr.Zero, IntPtr.Zero)

with the message

 

An exception of type 'Autodesk.AutoCAD.Runtime.Exception' occurred in AcdbMgd.dll but was not handled in user code

Additional information: eNotImplementedYet

If there is a handler for this exception, the program may be safely continued.

 

Can some autocad customization experts help me with this?

 

 

 

 

1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

Solved.

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report