几何类使用相关
本帖最后由 作者 于 2010-6-12 6:53:40 编辑 <br /><br /> <p><font face="Verdana"> //使用Ge曲线的简单例子<br/> //对直线和圆求交点,并返回交点分隔的部分<br/> <br/> public static void Test9()<br/> {<br/> //Ge直线<br/> Line2d l2d = new Line2d(Point2d.Origin, Vector2d.XAxis);<br/> //Ge圆<br/> CircularArc2d ca2d = new CircularArc2d(new Point2d(5, 5), 15);</font></p><p><font face="Verdana"> //交点集合<br/> List<Point2d> pnts = new List<Point2d>();</font></p>
<p><font face="Verdana"> //交点处的参数集合<br/> List<double> pars1 = new List<double>();<br/> List<double> pars2 = new List<double>();</font></p>
<p><font face="Verdana"> //求交<br/> using (var cci2d = new CurveCurveIntersector2d(l2d, ca2d))<br/> {<br/> for (int i = 0; i < cci2d.NumberOfIntersectionPoints; i++)<br/> {<br/> pnts.Add(cci2d.GetIntersectionPoint(i));<br/> var k = cci2d.GetIntersectionParameters(i);<br/> pars1.Add(k);<br/> pars2.Add(k);<br/> }<br/> }</font></p>
<p><font face="Verdana"> var db = HostApplicationServices.WorkingDatabase;<br/> var doc = Application.DocumentManager.GetDocument(db);<br/> var ed = doc.Editor;<br/> <br/> int j = 0;<br/> pnts.ForEach(p => ed.WriteMessage("\n第{0}个交点为:{1}", ++j, p));</font></p>
<p><font face="Verdana"> //转换结果为Db曲线<br/> using (var tr = db.TransactionManager.StartTransaction())<br/> {</font></p>
<p><font face="Verdana"> var btr = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord;</font></p>
<p><font face="Verdana"> pars1.Sort();<br/> LineSegment2d ls2d = new LineSegment2d(l2d.EvaluatePoint(pars1), l2d.EvaluatePoint(pars1));<br/> var line = ls2d.ToCurve(Matrix3d.Identity);<br/> btr.AppendEntity(line);<br/> tr.AddNewlyCreatedDBObject(line, true);</font></p>
<p><font face="Verdana"> pars2.Sort();<br/> ca2d.SetInterval(new Interval(pars2, pars2, 0));<br/> var arc = ca2d.ToCurve(Matrix3d.Identity);<br/> btr.AppendEntity(arc);<br/> tr.AddNewlyCreatedDBObject(arc, true);</font></p>
<p><font face="Verdana"> tr.Commit();</font></p>
<p><font face="Verdana"> }<br/> }</font></p>
<p><font face="Verdana"></font> </p>
<p><font face="Verdana">代码效果:</p>
<p><br/></p></font> 大佬们有2个问题请教一下:Ge曲线和db曲线有什么不同,LineSegment2d这类和实际的line有啥区别 学习了,有个疑问,Ge对象是不是不能直接读取其属性值 顶起,完美的代码,赞一个 学习了。
<div><span style="FILTER: glow(color='#9898BA',strength='2'); WIDTH: 105px"><font face="Verdana" color="#da2549"><b>lzh741206</b></font>发的,我直接收藏.</div></span> 学习,顶!!!!! <p>点到直线的垂足</p>
<p> </p>
<p><font face="Verdana"> <br/> public static void Test11()<br/> {<br/> var db = HostApplicationServices.WorkingDatabase;<br/> var doc = Application.DocumentManager.GetDocument(db);<br/> var ed = doc.Editor;</font></p>
<p><font face="Verdana"> var resEnt = ed.GetEntity("\n请选择一条直线:");<br/> if (resEnt.Status != PromptStatus.OK)<br/> return;</font></p>
<p><font face="Verdana"> var resPnt = ed.GetPoint("\n请选择直线外的一点:");<br/> if (resPnt.Status != PromptStatus.OK)<br/> return;</font></p>
<p><font face="Verdana"> using (var tr = db.TransactionManager.StartTransaction())<br/> {<br/> Line line = resEnt.ObjectId.GetObject(OpenMode.ForRead) as Line;<br/> LineSegment3d ls3d = new LineSegment3d(line.StartPoint, line.EndPoint); ;<br/> Line3d l3d = new Line3d(line.StartPoint, line.EndPoint);</font></p>
<p><font face="Verdana"> Point3d pt1 = resPnt.Value;<br/> Point3d pt2 = l3d.GetClosestPointTo(pt1).Point;</font></p>
<p><font face="Verdana"> ed.WriteMessage<br/> (<br/> "\n点{0}\n到直线的垂足为{1};\n距离为{2};\n在直线{3}",<br/> pt1,<br/> pt2,<br/> (pt2 - pt1).Length,<br/> ls3d.IsOn(pt2) ? "内" : "外"<br/> );</font></p>
<p><font face="Verdana"> ed.DrawVector(pt1, pt2, 1, false);</font></p>
<p><font face="Verdana"> }</font></p>
<p><font face="Verdana"> }</font></p>
<p> </p>
<p>效果:</p>
<p></p>
<p> </p> <p>呵呵,看到了,谢谢飞弧哥</p> 大家排队顶起! <p>顶下</p> <p>回头再顶一次</p>
<p> </p> 学习,顶