乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 122|回复: 9

截取两点间的部分

[复制链接]

1

主题

6

帖子

1

银币

初来乍到

Rank: 1

铜币
10
发表于 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是什么意思?
哪位帮帮忙解释下,我相信还有许多和我一样不清楚的人。
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 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.
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2010-11-3 21:10:00 | 显示全部楼层

下面的代码可以适应任何曲线
  1.         [CommandMethod("CTest")]
  2.         public void test()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Editor ed = doc.Editor;
  6.             Database db = doc.Database;
  7.             using (doc.LockDocument())
  8.             {
  9.                 PromptEntityOptions optEnt = new PromptEntityOptions("\n请选择曲线上的点:");
  10.                 optEnt.SetRejectMessage("你选择的不是曲线!");
  11.                 optEnt.AddAllowedClass(typeof(Curve), false);
  12.                 PromptEntityResult resEnt = ed.GetEntity(optEnt);
  13.                 if (resEnt.Status != PromptStatus.OK)
  14.                     return;
  15.                 ObjectId id = resEnt.ObjectId;
  16.                 Point3d pt1 = resEnt.PickedPoint;
  17.                 SystemManager.OSModeType oldos = SystemManager.OSMode;
  18.                 SystemManager.OSMode = SystemManager.OSModeType.Nearest;
  19.                 PromptPointOptions optPt2 = new PromptPointOptions("\n请选取第二个点:");
  20.                 PromptPointResult resPt2 = ed.GetPoint(optPt2);
  21.                 SystemManager.OSMode = oldos;
  22.                 if (resPt2.Status != PromptStatus.OK)
  23.                     return;
  24.                 Point3d pt2 = resPt2.Value;
  25.                 using (Transaction tr = db.TransactionManager.StartTransaction())
  26.                 {
  27.                     BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false);
  28.                     Curve oldCurve = tr.GetObject(id, OpenMode.ForWrite) as Curve;
  29.                     if (pt2.DistanceTo(oldCurve.GetClosestPointTo(pt2, false)) > 5)
  30.                     {
  31.                         ed.WriteMessage("\n点不在曲线上!");
  32.                         return;
  33.                     }
  34.                     pt1 = oldCurve.GetClosestPointTo(pt1, false);
  35.                     pt2 = oldCurve.GetClosestPointTo(pt2, false);
  36.                     double par1 = oldCurve.GetParameterAtPoint(pt1);
  37.                     double par2 = oldCurve.GetParameterAtPoint(pt2);
  38.                     if (par1 > par2)
  39.                     {
  40.                         double temp = par1;
  41.                         par1 = par2;
  42.                         par2 = temp;
  43.                     }
  44.                     DoubleCollection pars = new DoubleCollection { par1, par2 };
  45.                     
  46.                     var curves = oldCurve.GetSplitCurves(pars);
  47.                     Curve newCurve = null;
  48.                     foreach (Curve curve in curves)
  49.                     {
  50.                         if (curve.GetClosestPointTo(pt1, false) == pt1 && curve.GetClosestPointTo(pt2, false) == pt2)
  51.                         {
  52.                             newCurve = curve;
  53.                             break;
  54.                         }
  55.                     }
  56.                     if (newCurve != null)
  57.                     {
  58.                         oldCurve.Erase();
  59.                         btr.AppendEntity(newCurve);
  60.                         tr.AddNewlyCreatedDBObject(newCurve, true);
  61.                     }
  62.                     tr.Commit();
  63.                 }
  64.             }
  65.         }
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2010-11-3 21:13:00 | 显示全部楼层
SystemManager类
  1. using System;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.GraphicsSystem;
  6. namespace TlsCad.Runtime
  7. {
  8.     public static class SystemManager
  9.     {
  10.         #region Goal
  11.         public static Database CurrentDatabase
  12.         {
  13.             get
  14.             {
  15.                 return HostApplicationServices.WorkingDatabase;
  16.             }
  17.         }
  18.         public static Document ActiveDocument
  19.         {
  20.             get
  21.             {
  22.                 return Application.DocumentManager.MdiActiveDocument;
  23.             }
  24.         }
  25.         public static Editor Editor
  26.         {
  27.             get
  28.             {
  29.                 return ActiveDocument.Editor;
  30.             }
  31.         }
  32.         public static Manager GsManager
  33.         {
  34.             get
  35.             {
  36.                 return ActiveDocument.GraphicsManager;
  37.             }
  38.         }
  39.         #endregion
  40.         #region Preferences
  41.         public static object GetCurrentProfileProperty(string subSectionName, string propertyName)
  42.         {
  43.             UserConfigurationManager ucm = Application.UserConfigurationManager;
  44.             IConfigurationSection cpf = ucm.OpenCurrentProfile();
  45.             IConfigurationSection ss = cpf.OpenSubsection(subSectionName);
  46.             return ss.ReadProperty(propertyName, "");
  47.         }
  48.         public static IConfigurationSection GetDialogSection(object dialog, string propertyName)
  49.         {
  50.             UserConfigurationManager ucm = Application.UserConfigurationManager;
  51.             IConfigurationSection ds = ucm.OpenDialogSection(dialog);
  52.             return ds;
  53.         }
  54.         public static IConfigurationSection GetGlobalSection(string propertyName)
  55.         {
  56.             UserConfigurationManager ucm = Application.UserConfigurationManager;
  57.             IConfigurationSection gs = ucm.OpenGlobalSection();
  58.             IConfigurationSection ss = gs.OpenSubsection(propertyName);
  59.             return ss;
  60.         }
  61.         #endregion
  62.         #region Enum
  63.         private static T ToEnum(this string value)
  64.         {
  65.             return (T)Enum.Parse(typeof(T), value, true);
  66.         }
  67.         private static string GetName(this T value)
  68.         {
  69.             return Enum.GetName(typeof(T), value);
  70.         }
  71.         
  72.         #region Dimblk
  73.         public enum DimblkType
  74.         {
  75.             Defult,
  76.             Dot,
  77.             DotSmall,
  78.             DotBlank,
  79.             Origin,
  80.             Origin2,
  81.             Open,
  82.             Open90,
  83.             Open30,
  84.             Closed,
  85.             Small,
  86.             None,
  87.             Oblique,
  88.             BoxFilled,
  89.             BoxBlank,
  90.             ClosedBlank,
  91.             DatumFilled,
  92.             DatumBlank,
  93.             Integral,
  94.             ArchTick,
  95.         }
  96.         public static DimblkType Dimblk
  97.         {
  98.             get
  99.             {
  100.                 string s = (string)Application.GetSystemVariable("dimblk");
  101.                 if (s == "" || s == null)
  102.                 {
  103.                     return DimblkType.Defult;
  104.                 }
  105.                 else
  106.                 {
  107.                     return s.ToEnum();
  108.                 }
  109.             }
  110.             set
  111.             {
  112.                 string s =
  113.                     value == DimblkType.Defult ?
  114.                     "." : "_" + value.GetName();
  115.                 Application.SetSystemVariable("dimblk", s);
  116.             }
  117.         }
  118.         public static ObjectId GetDimblkId(DimblkType dimblkname)
  119.         {
  120.             DimblkType oldDimblk = Dimblk;
  121.             Dimblk = dimblkname;
  122.             ObjectId id = HostApplicationServices.WorkingDatabase.Dimblk;
  123.             Dimblk = oldDimblk;
  124.             return id;
  125.         }
  126.         #endregion
  127.         #region OsMode
  128.         public enum OSModeType
  129.         {
  130.             None = 0,
  131.             End = 1,
  132.             Middle = 2,
  133.             Center = 4,
  134.             Node = 8,
  135.             Quadrant = 16,
  136.             Intersection = 32,
  137.             Insert = 64,
  138.             Pedal = 128,
  139.             Tangent = 256,
  140.             Nearest = 512,
  141.             Quick = 1024,
  142.             Appearance = 2048,
  143.             Extension = 4096,
  144.             Parallel = 8192
  145.         }
  146.         public static OSModeType OSMode
  147.         {
  148.             get
  149.             {
  150.                 return (OSModeType)Convert.ToInt16(Application.GetSystemVariable("osmode"));
  151.             }
  152.             set
  153.             {
  154.                 Application.SetSystemVariable("osmode", (int)value);
  155.             }
  156.         }        public static void AppendOSMode(OSModeType osm)
  157.         {
  158.             OSMode |= osm;
  159.         }
  160.         public static bool CheckOSMode(OSModeType osm)
  161.         {
  162.             return (OSMode & osm) == osm;
  163.         }
  164.         public static void RemoveOSMode(OSModeType osm)
  165.         {
  166.             OSMode ^= osm;
  167.         }
  168.         #endregion
  169.         #endregion
  170.     }
  171. }
回复

使用道具 举报

1

主题

6

帖子

1

银币

初来乍到

Rank: 1

铜币
10
发表于 2010-11-3 22:45:00 | 显示全部楼层
谢谢,我研究下
回复

使用道具 举报

1

主题

6

帖子

1

银币

初来乍到

Rank: 1

铜币
10
发表于 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顺时针或逆时针方向的一段多义线。

回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2010-11-5 23:26:00 | 显示全部楼层
这个有点麻烦
提供算法先考虑下吧

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

使用道具 举报

84

主题

543

帖子

12

银币

中流砥柱

Rank: 25

铜币
886
发表于 2010-11-9 12:23:00 | 显示全部楼层
谢谢,现在还不懂,先收藏,以后我也研究下
回复

使用道具 举报

1

主题

6

帖子

1

银币

初来乍到

Rank: 1

铜币
10
发表于 2010-11-9 19:16:00 | 显示全部楼层
谢谢飞狐,在你的指导下以及查阅了相关资料,我实现了此功能复制代码
回复

使用道具 举报

1

主题

6

帖子

1

银币

初来乍到

Rank: 1

铜币
10
发表于 2010-11-11 22:19:00 | 显示全部楼层
复制代码
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-15 10:44 , Processed in 0.366197 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表