carrot1983 发表于 2009-11-26 16:05:00

[分享]绘制剖断线(C#)


using System;
using System.Text;
using Autodesk..ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace CsMgd1
{
    public class Class1
    {
      Database db = HostApplicationServices.WorkingDatabase;
      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
      
      public void Test()
      {
            ed.WriteMessage("\n绘制剖断线By carrot1983");
   PromptPointResult proPtRes1;
   PromptPointOptions proPtOpts1 = new PromptPointOptions("\n指定第一点: ");
   proPtRes1 = ed.GetPoint(proPtOpts1);
   Point3d pt1 = proPtRes1.Value;
   PromptPointResult proPtRes2;
   PromptPointOptions proPtOpts2 = new PromptPointOptions("\n指定第二点: ");
            proPtOpts2.UseDashedLine = true;
   proPtOpts2.UseBasePoint = true;
            proPtOpts2.BasePoint = pt1;
   proPtRes2 = ed.GetPoint(proPtOpts2);
   Point3d pt2 = proPtRes2.Value;
            Point2dCollection pts = GetPoDuanPoints(pt1, pt2);
            ObjectId pline = AddPline(pts, 0.0);
      }
      //取得两点间角度
      public static double Get2PointsAngle(Point3d pt1, Point3d pt2)
      {
            Vector3d v1 = pt1.GetVectorTo(pt2);
            return v1.GetAngleTo(Vector3d.XAxis);
      }
      //按方向和距离求取点
      public static Point3d PolarPoint(Point3d basePt, double angle, double distance)
      {
            double[] pt = new double;
            pt = basePt + distance * Math.Cos(angle);
            pt = basePt + distance * Math.Sin(angle);
            pt = basePt;
            Point3d point = new Point3d(pt, pt, pt);
            return point;
      }
      //计算剖断线的顶点表
      public static Point2dCollection GetPoDuanPoints(Point3d pt1, Point3d pt2)
      {
             double ang = Get2PointsAngle(pt1, pt2);
             Point3d leftPt = PolarPoint(pt1, ang+Math.PI, 56);
             Point3d rightPt = PolarPoint(pt2, ang, 56);
             Point3d middlePt = new Point3d((leftPt.X + rightPt.X) * 0.5, (leftPt.Y + rightPt.Y) * 0.5, (leftPt.Z + rightPt.Z) * 0.5);
             Point3d leftPt1 = PolarPoint(middlePt, ang + Math.PI, 26);
             Point3d leftPt2 = PolarPoint(PolarPoint(middlePt, ang + Math.PI, 12), ang + Math.PI * 0.5, 44);
             Point3d rightPt1 = PolarPoint(middlePt, ang, 26);
             Point3d rightPt2 = PolarPoint(PolarPoint(middlePt, ang, 12), ang + Math.PI * 1.5, 44);
             Point2dCollection pts = new Point2dCollection();
             pts.Add(new Point2d (leftPt.X,leftPt.Y));
             pts.Add(new Point2d(leftPt1.X, leftPt1.Y));
             pts.Add(new Point2d(leftPt2.X, leftPt2.Y));
             pts.Add(new Point2d(rightPt2.X, rightPt2.Y));
             pts.Add(new Point2d(rightPt1.X, rightPt1.Y));
             pts.Add(new Point2d(rightPt.X, rightPt.Y));
             return pts;
      }
      // 由二维点集合和线宽创建二维优化多段线的函数.
      public static ObjectId AddPline(Point2dCollection pts, double width)
      {
            try
            {
                int n = pts.Count;
                Polyline ent = new Polyline();
                for (int i = 0; i 将Lisp的运行结果图片贴上让看看,不知道啥叫剖断线

dukeyongwang 发表于 2009-11-26 17:42:00

你的这个剖断线跟剖面图是不是一个东西的

jsy198610 发表于 2009-12-9 15:49:00

不能设置比例,不太好

无惢 发表于 2013-6-23 21:32:00

路过并表示强烈支持!

sdaulj 发表于 2014-5-6 23:14:00

角度转换有问题

aprilsea 发表于 2014-5-27 16:49:00

萝卜兄转战.NET了?你的拉移随心已经成名已久啦!你的剖断线程序,我测试了是后面的角度转换有问题,改过后就行了。不知道你解决没有?复制代码
页: [1]
查看完整版本: [分享]绘制剖断线(C#)