AutoCAD.net: 求空间两曲线交点

using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using AsApp = Autodesk.AutoCAD.ApplicationServices.Application;
using DsTM = Autodesk.AutoCAD.DatabaseServices.TransactionManager;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Interop;

namespace ObjectArxNet.Test
{
    
/// <summary>
    
/// 求空间两曲线交点
    
/// </summary>

    public class Intersection
    
{
        [CommandMethod(
IntersectionTest)]
        
public void IntersectionTest()
        
{
            Editor m_ed 
= Application.DocumentManager.MdiActiveDocument.Editor;
            Database m_db 
= HostApplicationServices.WorkingDatabase;
            PromptEntityOptions m_peo 
= new PromptEntityOptions(/n请选择第一条曲线:);
            PromptEntityResult m_per 
= m_ed.GetEntity(m_peo);
            
if (m_per.Status != PromptStatus.OK) return; }
            ObjectId m_objid1 
= m_per.ObjectId;

            m_peo 
= new PromptEntityOptions(/n请选择第二条曲线:);
            m_per 
= m_ed.GetEntity(m_peo);
            
if (m_per.Status != PromptStatus.OK) return; }
            ObjectId m_objid2 
= m_per.ObjectId;

            
using (Transaction m_tr = m_db.TransactionManager.StartTransaction())
            
{
                Curve m_cur1 
= (Curve)m_tr.GetObject(m_objid1, OpenMode.ForRead);
                Curve m_cur2 
= (Curve)m_tr.GetObject(m_objid2, OpenMode.ForRead);

                Point3dCollection m_ints 
= new Point3dCollection();
                m_cur1.IntersectWith(m_cur2, Intersect.OnBothOperands, 
new Plane(), m_ints, 00); //得出的所有交点在c1曲线上
                foreach (Point3d m_pt in m_ints)
                
{
                    m_ed.WriteMessage(
/n第一条曲线与第二条曲线交点:{0}, m_pt);
                }


                m_ed.WriteMessage(
/n===);
                m_ints.Clear();
                m_cur2.IntersectWith(m_cur1, Intersect.OnBothOperands, 
new Plane(), m_ints, 00); //得出的所有交点在c2曲线上
                foreach (Point3d m_pt in m_ints)
                
{
                    m_ed.WriteMessage(
/n第二条曲线与第条曲线一交点:{0}, m_pt);
                }

                m_tr.Commit();
            }

        }


    }

}

转载自:https://blog.csdn.net/sx811125/article/details/6326060

You may also like...