一种将Region转为Polyline的方法

在AutoCAD.NET二次开发中,如果要将面域转为Polyline主要有以下几种方式:

1、使用Explode将面域炸成Line和Arc,然后再串起来,此方法可用于AutoCAD2007开始的所有版本。

参考:http://through-the-interface.typepad.com/through_the_interface/2008/08/creating-a-seri.html

2、想办法获取Region内的一个点,使用CAD的BO命令重新创建边界,并监听命令结束事件,获取最后一个生成的实体。

3、使用C#和Lisp配合开发,在Lisp中使用bpoly创建边界。

4、使用AutoCAD.NET接口中的Editor.TracBoundary方法取得新边界,但此方法从AutoCAD2011开始有。

5、使用Brep和Edge来获取Region子实体,这几个接口从AutoCAD2009开始才添加进来的,

使用Brep来取得Region的每条边,然后再将这些边转为弧和线段对象,再进行串联,示例代码如下:

引用acdbmgdbrep.dll

PromptEntityResult per = ed.GetEntity("\n请选择");
            if (per.Status == PromptStatus.OK)
            {
                using (DocumentLock dlk = doc.LockDocument())
                {
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        Entity ent = (Entity)trans.GetObject(per.ObjectId, OpenMode.ForWrite);
                        if (!(ent is Region))
                            return;
                        Region reg = (Region)ent;
                        Brep brep = new Brep(reg);
                        BrepEdgeCollection bec = brep.Edges;
                        if (bec != null)
                        {
                            foreach (Edge edge in bec)
                            {
                                Curve3d cv3d = edge.Curve;
                                ExternalCurve3d ecv3d = (ExternalCurve3d)cv3d;
                                if (ecv3d.IsCircularArc)
                                {
                                    CircularArc3d ca3d = ecv3d.NativeCurve as CircularArc3d;
                                    ed.WriteMessage("\n弧");
                                }
                                else if (ecv3d.IsLine)
                                {
                                    ed.WriteMessage("\n线");
                                }
                                else if (ecv3d.IsLineSegment)
                                {
                                    LineSegment3d ls3d = ecv3d.NativeCurve as LineSegment3d;
                                    ed.WriteMessage("\n线段");
                                }
                                else if (ecv3d.IsNativeCurve)
                                {
                                    ed.WriteMessage("\n原始曲线");
                                }
                                else if (ecv3d.IsNurbCurve)
                                {
                                    ed.WriteMessage("\n样条曲线");
                                }
                                else
                                {
                                    ed.WriteMessage("\n" + ecv3d.ExternalCurveKind);
                                }
                                ed.WriteMessage("\n起点:" + cv3d.StartPoint.ToString() + "-终点:" + cv3d.EndPoint.ToString());
                            }
                        }
                    }
                }
            }

 

转载于:https://www.cnblogs.com/bomb12138/p/5985600.html

Cesium提供了一个名为IntersectionTests的工具类,可以用来检测一个polyline是否穿过了地球。具体步骤如下: 1. 将polyline转换为一组线段,可以通过`PolylinePipeline.generateArc`方法来实现。 2. 对于每条线段,使用`IntersectionTests.lineSegmentSphere`方法检测该线段是否与地球相交。 3. 如果有任何一条线段与地球相交,则该polyline穿过了地球。 下面是一个使用Cesium判断polyline是否穿过地球的示例代码: ```javascript var viewer = new Cesium.Viewer('cesiumContainer'); var polyline = new Cesium.PolylineCollection(); polyline.add({ positions : Cesium.Cartesian3.fromDegreesArrayHeights([ -75.59777, 40.03883, 0, -75.59777, 40.13883, 0, -75.69777, 40.13883, 0, -75.69777, 40.03883, 0 ]), width : 10.0, followSurface : false }); var cartographic = Cesium.Cartographic.fromCartesian(viewer.camera.position); var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0); var ray = new Cesium.Ray(viewer.camera.position, Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(surface, viewer.camera.position, new Cesium.Cartesian3()), new Cesium.Cartesian3())); var intersections = Cesium.IntersectionTests.lineSegmentSphere(polyline.get(0).positions[0], polyline.get(0).positions[1], Cesium.Ellipsoid.WGS84, ray); if (intersections != null) { console.log("Polyline intersects the earth!"); } else { console.log("Polyline does not intersect the earth."); } ``` 这段代码创建了一个包含四个点的polyline,并将其与地球进行了相交测试。如果该polyline穿过了地球,则输出"Polyline intersects the earth!",否则输出"Polyline does not intersect the earth."。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值