yds_009 发表于 2010-11-1 22:05:00

截取两点间的部分

复制代码另外如
Point3d m_Pt1 = m_CurNew.GetPointAtParameter(m_Param);
Point3d m_Pt2 = m_TrimEdge.GetClosestPointTo(m_Pt1, false);
Vector3d m_Vect = m_TrimEdge.GetFirstDerivative(m_Pt2);
这三句分别表示什么意思?GetPointAtParameter,GetClosestPointTo,GetFirstDerivative是什么意思?
哪位帮帮忙解释下,我相信还有许多和我一样不清楚的人。

雪山飞狐_lzh 发表于 2010-11-1 22:11:00

GetPointAtParameter
This function determines the point on the curve that corresponds to value, and returns the point.
GetClosestPointTo
This function projects the curve onto the plane defined by givenPoint. Returns the point (in WCS coordinates) on the curve that is nearest to givenPoint.
GetFirstDerivative
Returns the first derivative of the vector.

雪山飞狐_lzh 发表于 2010-11-3 21:10:00


下面的代码可以适应任何曲线

      
      public void test()
      {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            using (doc.LockDocument())
            {
                PromptEntityOptions optEnt = new PromptEntityOptions("\n请选择曲线上的点:");
                optEnt.SetRejectMessage("你选择的不是曲线!");
                optEnt.AddAllowedClass(typeof(Curve), false);
                PromptEntityResult resEnt = ed.GetEntity(optEnt);
                if (resEnt.Status != PromptStatus.OK)
                  return;
                ObjectId id = resEnt.ObjectId;
                Point3d pt1 = resEnt.PickedPoint;
                SystemManager.OSModeType oldos = SystemManager.OSMode;
                SystemManager.OSMode = SystemManager.OSModeType.Nearest;
                PromptPointOptions optPt2 = new PromptPointOptions("\n请选取第二个点:");
                PromptPointResult resPt2 = ed.GetPoint(optPt2);
                SystemManager.OSMode = oldos;
                if (resPt2.Status != PromptStatus.OK)
                  return;
                Point3d pt2 = resPt2.Value;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                  BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false);
                  Curve oldCurve = tr.GetObject(id, OpenMode.ForWrite) as Curve;
                  if (pt2.DistanceTo(oldCurve.GetClosestPointTo(pt2, false)) > 5)
                  {
                        ed.WriteMessage("\n点不在曲线上!");
                        return;
                  }
                  pt1 = oldCurve.GetClosestPointTo(pt1, false);
                  pt2 = oldCurve.GetClosestPointTo(pt2, false);
                  double par1 = oldCurve.GetParameterAtPoint(pt1);
                  double par2 = oldCurve.GetParameterAtPoint(pt2);
                  if (par1 > par2)
                  {
                        double temp = par1;
                        par1 = par2;
                        par2 = temp;
                  }
                  DoubleCollection pars = new DoubleCollection { par1, par2 };
                  
                  var curves = oldCurve.GetSplitCurves(pars);
                  Curve newCurve = null;
                  foreach (Curve curve in curves)
                  {
                        if (curve.GetClosestPointTo(pt1, false) == pt1 && curve.GetClosestPointTo(pt2, false) == pt2)
                        {
                            newCurve = curve;
                            break;
                        }
                  }
                  if (newCurve != null)
                  {
                        oldCurve.Erase();
                        btr.AppendEntity(newCurve);
                        tr.AddNewlyCreatedDBObject(newCurve, true);
                  }
                  tr.Commit();
                }
            }
      }

雪山飞狐_lzh 发表于 2010-11-3 21:13:00

SystemManager类

using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.GraphicsSystem;
namespace TlsCad.Runtime
{
    public static class SystemManager
    {
      #region Goal
      public static Database CurrentDatabase
      {
            get
            {
                return HostApplicationServices.WorkingDatabase;
            }
      }
      public static Document ActiveDocument
      {
            get
            {
                return Application.DocumentManager.MdiActiveDocument;
            }
      }
      public static Editor Editor
      {
            get
            {
                return ActiveDocument.Editor;
            }
      }
      public static Manager GsManager
      {
            get
            {
                return ActiveDocument.GraphicsManager;
            }
      }
      #endregion
      #region Preferences
      public static object GetCurrentProfileProperty(string subSectionName, string propertyName)
      {
            UserConfigurationManager ucm = Application.UserConfigurationManager;
            IConfigurationSection cpf = ucm.OpenCurrentProfile();
            IConfigurationSection ss = cpf.OpenSubsection(subSectionName);
            return ss.ReadProperty(propertyName, "");
      }
      public static IConfigurationSection GetDialogSection(object dialog, string propertyName)
      {
            UserConfigurationManager ucm = Application.UserConfigurationManager;
            IConfigurationSection ds = ucm.OpenDialogSection(dialog);
            return ds;
      }
      public static IConfigurationSection GetGlobalSection(string propertyName)
      {
            UserConfigurationManager ucm = Application.UserConfigurationManager;
            IConfigurationSection gs = ucm.OpenGlobalSection();
            IConfigurationSection ss = gs.OpenSubsection(propertyName);
            return ss;
      }
      #endregion
      #region Enum
      private static T ToEnum(this string value)
      {
            return (T)Enum.Parse(typeof(T), value, true);
      }
      private static string GetName(this T value)
      {
            return Enum.GetName(typeof(T), value);
      }
      
      #region Dimblk
      public enum DimblkType
      {
            Defult,
            Dot,
            DotSmall,
            DotBlank,
            Origin,
            Origin2,
            Open,
            Open90,
            Open30,
            Closed,
            Small,
            None,
            Oblique,
            BoxFilled,
            BoxBlank,
            ClosedBlank,
            DatumFilled,
            DatumBlank,
            Integral,
            ArchTick,
      }
      public static DimblkType Dimblk
      {
            get
            {
                string s = (string)Application.GetSystemVariable("dimblk");
                if (s == "" || s == null)
                {
                  return DimblkType.Defult;
                }
                else
                {
                  return s.ToEnum();
                }
            }
            set
            {
                string s =
                  value == DimblkType.Defult ?
                  "." : "_" + value.GetName();
                Application.SetSystemVariable("dimblk", s);
            }
      }
      public static ObjectId GetDimblkId(DimblkType dimblkname)
      {
            DimblkType oldDimblk = Dimblk;
            Dimblk = dimblkname;
            ObjectId id = HostApplicationServices.WorkingDatabase.Dimblk;
            Dimblk = oldDimblk;
            return id;
      }
      #endregion
      #region OsMode
      public enum OSModeType
      {
            None = 0,
            End = 1,
            Middle = 2,
            Center = 4,
            Node = 8,
            Quadrant = 16,
            Intersection = 32,
            Insert = 64,
            Pedal = 128,
            Tangent = 256,
            Nearest = 512,
            Quick = 1024,
            Appearance = 2048,
            Extension = 4096,
            Parallel = 8192
      }
      public static OSModeType OSMode
      {
            get
            {
                return (OSModeType)Convert.ToInt16(Application.GetSystemVariable("osmode"));
            }
            set
            {
                Application.SetSystemVariable("osmode", (int)value);
            }
      }      public static void AppendOSMode(OSModeType osm)
      {
            OSMode |= osm;
      }
      public static bool CheckOSMode(OSModeType osm)
      {
            return (OSMode & osm) == osm;
      }
      public static void RemoveOSMode(OSModeType osm)
      {
            OSMode ^= osm;
      }
      #endregion
      #endregion
    }
}

yds_009 发表于 2010-11-3 22:45:00

谢谢,我研究下

yds_009 发表于 2010-11-5 21:09:00

谢谢你抽出时间给我回复。
主要是我的问题没有被我描述清楚、
我的意思是定义一个函数
public static Curve GetPolyLineBetweenTwoPoint(Curve cav, Point3d P1, Point3d P2,bool StoE )
1,首先我知道截取的两点在一个封闭的多义线cav上。(封闭的多义线cav---我也是事先就知道的)
2,假如起始点设为P1,终点设为P2,p1到p2是顺时针方向还是逆时针方向是由StoE决定。假如事先规定StoE为true时表示顺时针方向。
3,返回沿P1到P2顺时针或逆时针方向的一段多义线。

雪山飞狐_lzh 发表于 2010-11-5 23:26:00

这个有点麻烦
提供算法先考虑下吧

1、首先判断多段线的顺逆
2、按stoe和p1,p2的参数数值判断取舍
3、如果取起点所在的两段,还要把两段连接为一条

chpmould 发表于 2010-11-9 12:23:00

谢谢,现在还不懂,先收藏,以后我也研究下

yds_009 发表于 2010-11-9 19:16:00

谢谢飞狐,在你的指导下以及查阅了相关资料,我实现了此功能复制代码

yds_009 发表于 2010-11-11 22:19:00

复制代码
页: [1]
查看完整版本: 截取两点间的部分