本帖最后由 作者 于 2010-6-12 6:53:40 编辑
//使用Ge曲线的简单例子 //对直线和圆求交点,并返回交点分隔的部分 [CommandMethod("t9")] public static void Test9() { //Ge直线 Line2d l2d = new Line2d(Point2d.Origin, Vector2d.XAxis); //Ge圆 CircularArc2d ca2d = new CircularArc2d(new Point2d(5, 5), 15);
//交点集合 List<oint2d> pnts = new List<oint2d>();
//交点处的参数集合 List<double> pars1 = new List<double>(); List<double> pars2 = new List<double>();
//求交 using (var cci2d = new CurveCurveIntersector2d(l2d, ca2d)) { for (int i = 0; i < cci2d.NumberOfIntersectionPoints; i++) { pnts.Add(cci2d.GetIntersectionPoint(i)); var k = cci2d.GetIntersectionParameters(i); pars1.Add(k[0]); pars2.Add(k[1]); } }
var db = HostApplicationServices.WorkingDatabase; var doc = Application.DocumentManager.GetDocument(db); var ed = doc.Editor; int j = 0; pnts.ForEach(p => ed.WriteMessage("\n第{0}个交点为:{1}", ++j, p));
//转换结果为Db曲线 using (var tr = db.TransactionManager.StartTransaction()) {
var btr = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
pars1.Sort(); LineSegment2d ls2d = new LineSegment2d(l2d.EvaluatePoint(pars1[0]), l2d.EvaluatePoint(pars1[1])); var line = ls2d.ToCurve(Matrix3d.Identity); btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true);
pars2.Sort(); ca2d.SetInterval(new Interval(pars2[0], pars2[1], 0)); var arc = ca2d.ToCurve(Matrix3d.Identity); btr.AppendEntity(arc); tr.AddNewlyCreatedDBObject(arc, true);
tr.Commit();
} }
代码效果:
|