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();
            }

        }


    }

}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值