找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 4324|回复: 3

[公告] 曲线和平面求交点

[复制链接]

已领礼包: 13个

财富等级: 恭喜发财

发表于 2013-9-1 16:31:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Intersection between plane and a curve
Here are the steps to find the intersection of a curve and a Plane (based on the explanation provided by my colleague, Krishnamurthy Kalvai). I have provided a sample code that implements these steps to find an intersection between an ellipse and a plane.
1. Determine if the curve lies on the plane. You may query this using Curve::GetPlane( ). Check if the plane returned is the same as / parallel to the intersection plane using Plane::IntersectWith( ).
If the planes are parallel, there can be infinite intersection points or no points of intersection at all. In either case, you may stop here and not go to step 2.
2. Project the curve onto the plane using Curve::GetProjectedCurve( ).
3. Find the intersection between the projected curve and original curve using IntersectWith( ). The intersection points will be the same as points of intersection of the curve with the Intersection plane.
4. As a final check, check to see if the intersection points lie on the plane using AcGeSurface::isOn( )
[CommandMethod("PlaneCurveIntersection")]
public static void PlaneCurveIntersection()
{
    Document activeDoc
        = Application.DocumentManager.MdiActiveDocument;
    Database db = activeDoc.Database;
    Editor ed = activeDoc.Editor;

    // Create the planar region and the ellipse
    ObjectId regionId = ObjectId.Null;
    ObjectId ellipseId = ObjectId.Null;
    using (Transaction tr
                = db.TransactionManager.StartTransaction())
    {
        BlockTable bt = tr.GetObject(
                                        db.BlockTableId,
                                        OpenMode.ForRead
                                    ) as BlockTable;

        BlockTableRecord modelSpace = tr.GetObject
                        (
                            bt[BlockTableRecord.ModelSpace],
                            OpenMode.ForWrite
                        ) as BlockTableRecord;

        Autodesk.AutoCAD.DatabaseServices.Polyline polyline
            = new Autodesk.AutoCAD.DatabaseServices.Polyline();

        polyline.Closed = true;
        polyline.AddVertexAt
                    (
                        0,
                        new Point2d(10.0, -10.0),
                        0.0,
                        0.0,
                        0.0
                    );
        polyline.AddVertexAt
                    (    1,
                        new Point2d(10.0, 10.0),
                        0.0,
                        0.0,
                        0.0
                    );
        polyline.AddVertexAt
                    (    2,
                        new Point2d(-10.0, 10.0),
                        0.0,
                        0.0,
                        0.0
                    );
        polyline.AddVertexAt
                    (
                        3,
                        new Point2d(-10.0, -10.0),
                        0.0,
                        0.0,
                        0.0
                    );
        DBObjectCollection coll = new DBObjectCollection();
        coll.Add(polyline);
        DBObjectCollection rgnColl
                                = Region.CreateFromCurves(coll);
        if (rgnColl.Count > 0)
        {
            Region rgn = rgnColl[0] as Region;
            regionId = modelSpace.AppendEntity(rgn);
            tr.AddNewlyCreatedDBObject(rgn, true);
        }
        Vector3d ellipseNormal
            = Vector3d.ZAxis.RotateBy(
                                        45.0 * Math.PI / 180.0,
                                        Vector3d.XAxis
                                     );
        Vector3d ellipseMajorAxis = new Vector3d(0, 5, 0);
        ellipseMajorAxis
            = ellipseMajorAxis.RotateBy
                                    (
                                        45.0 * Math.PI / 180.0,
                                        Vector3d.XAxis
                                    );
        Ellipse ellipse = new Ellipse
                                    (
                                        Point3d.Origin,
                                        ellipseNormal,
                                        ellipseMajorAxis,
                                        0.5,
                                        0,
                                        0
                                    );
        ellipseId = modelSpace.AppendEntity(ellipse);
        tr.AddNewlyCreatedDBObject(ellipse, true);
        tr.Commit();
    }

    // Find the intersection of the curve and the plane
    using (Transaction tr
            = db.TransactionManager.StartTransaction())
    {
        Region rgn = tr.GetObject
                                (
                                    regionId,
                                    OpenMode.ForRead
                                ) as Region;
        DBObjectCollection exploded = new DBObjectCollection();
        rgn.Explode(exploded);
        Entity firstEntity = exploded[0] as Entity;
        Plane intersectionPlane = firstEntity.GetPlane();
        Curve curve = tr.GetObject
                                (
                                    ellipseId,
                                    OpenMode.ForRead
                                ) as Curve;
        Plane curvePlane = curve.GetPlane();
        if (curvePlane.IsCoplanarTo(intersectionPlane))
        {
            ed.WriteMessage("\nInfinite intersections !");
        }
        else if (curvePlane.IsParallelTo(intersectionPlane))
        {
            ed.WriteMessage("\nNo intersections !");
        }
        else
        {
            Curve projectedCurve
                = curve.GetProjectedCurve
                                    (
                                        intersectionPlane,
                                        intersectionPlane.Normal
                                    );
            Point3dCollection intPts = new Point3dCollection();
            projectedCurve.IntersectWith
                                    (
                                        curve,
                                        Intersect.ExtendBoth,
                                        intPts,
                                        IntPtr.Zero,
                                        IntPtr.Zero
                                    );
            foreach (Point3d pt in intPts)
            {
                if (curvePlane.IsOn(pt))
                {
                    ed.WriteMessage
                                (
                        string.Format(
                                        "{0}{1}",
                                        Environment.NewLine,
                                        pt.ToString()
                                     )
                                );
                }
            }
        }
        tr.Commit();
    }
}




论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 1268个

财富等级: 财源广进

发表于 2013-9-1 20:41:58 来自手机 | 显示全部楼层
这个不像ARX,发错版块了吧

点评

这个是C#  详情 回复 发表于 2013-10-4 21:59
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1632个

财富等级: 堆金积玉

发表于 2013-10-4 21:59:12 | 显示全部楼层
st788796 发表于 2013-9-1 20:41
这个不像ARX,发错版块了吧

这个是C#
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 859个

财富等级: 财运亨通

发表于 2014-5-5 21:22:20 来自手机 | 显示全部楼层
mark
1 entity.GetPlane
2 curve.GetProjectedCurve
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-24 12:23 , Processed in 0.200953 second(s), 42 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表