找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1693|回复: 5

[教学] XDGE几何库应用(21)--Lisp函数

[复制链接]

已领礼包: 1268个

财富等级: 财源广进

发表于 2014-9-30 14:06:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 st788796 于 2014-11-1 07:54 编辑

几何库很强大,但 Lisp 中使用绕来绕去的也麻烦,集中起来写写Lisp库就方便些
  1. (defun XDGL::Curve:GetParamAtPoint (ge pt)
  2.   (xdge::getpropertyvalue
  3.     ge
  4.     "paramOf"
  5.     (xdge::getpropertyvalue ge "closestPointTo" pt)
  6.   )
  7. )

本帖被以下淘专辑推荐:

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 1268个

财富等级: 财源广进

 楼主| 发表于 2014-10-1 07:40:56 | 显示全部楼层
本帖最后由 st788796 于 2014-10-1 09:05 编辑

  1. (defun XDGL::Curve:GetFirstDeriv (ge pnt / lst)
  2.   (if (and (setq lst (xdge::getpropertyvalue
  3.                        ge
  4.                        "evalPoint"
  5.                        (XDGL::Curve:GetParamAtPoint ge pnt)
  6.                        2
  7.                      )
  8.            )
  9.            (= (length lst) 2)
  10.            (eq (type (cadr lst)) 'LIST)
  11.       )
  12.     (xdrx_vector_normalize (caadr lst))
  13.   )
  14. )

;;Ge 曲线 EndParam
  1. (defun XDGL::Curve:GetEndParam (ge / ep)
  2.   (if (setq ep (xdge::getpropertyvalue ge "hasEndPoint"))
  3.     (xdge::getpropertyvalue ge "paramOf" ep)
  4.   )
  5. )

;;Ge 曲线模拟点
;;等分点用 (xdge::getpropertyvalue ge "getSamplePoints" from to int)
  1. (defun XDGL::Curve:GetSamplePoints (ge from to chord-height / params)
  2.   (if (xdge::getpropertyvalue ge "isLinear")
  3.     (mapcar 'list (xdge::getpropertyvalue ge "hasStartPoint" "hasEndPoint")
  4.                        '(0.0 1.0)
  5.     )
  6.     (if        (and (> chord-height 0.0)
  7.              (setq epam (XDGL::Curve:GetEndParam ge))
  8.              (<= 0.0 from epam)
  9.              (<= to epam)
  10.              (< from to)
  11.         )
  12.       (progn
  13.         (setq params (xdge::getpropertyvalue
  14.                        ge "getSamplePoints" from to chord-height)
  15.         )
  16.         (list (mapcar '(lambda (x)
  17.                          (list (xdge::getpropertyvalue ge "evalPoint" x) x)
  18.                        )
  19.                       params
  20.               )
  21.               params
  22.         )
  23.       )
  24.     )
  25.   )
  26. )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1268个

财富等级: 财源广进

 楼主| 发表于 2014-10-1 11:31:16 | 显示全部楼层
本帖最后由 st788796 于 2014-10-1 11:37 编辑

用 Ge 获取整条线的定距分割点或定数等分点
cv ---- AcGeCurve 或 AcDbCurve
n ---- 实数是为定距分割,整数时为定数等分
  1. (defun XDGL::Curve:NumDiv (cv n / ge pts len nn in)
  2.   (setq ge (xdge::constructor cv))
  3.   (if (= (type n) 'REAL)
  4.     (progn
  5.       (setq len        (xdge::getpropertyvalue ge "length")
  6.             nn        (fix (/ len n))
  7.             in        (xdge::constructor "AcGeInterval" 0.0 (* nn n))
  8.       )
  9.       (xdge::setpropertyvalue ge "setInterval" in)
  10.       (setq n nn)
  11.     )
  12.   )
  13.   (setq pts (xdge::getpropertyvalue ge "getSamplePoints" (fix n)))
  14.   (xdge::free ge)
  15.   pts
  16. )

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1268个

财富等级: 财源广进

 楼主| 发表于 2014-10-1 12:09:59 | 显示全部楼层
st788796 发表于 2014-10-1 11:31
用 Ge 获取整条线的定距分割点或定数等分点
cv ---- AcGeCurve 或 AcDbCurve
n ---- 实数是为定距分割, ...

再改进一次 Cv  可以为 DbCurve  GeCurve Points
  1. (defun XDGL::Curve:NumDiv (cv n / ge pts len nn in)
  2.   (if (eq (type cv) 'LIST)
  3.     (setq ge (xdge::constructor
  4.                "kCompositeCrv3d"
  5.                (mapcar '(lambda        (x y)
  6.                           (xdge::constructor "kLineSeg3d" x y)
  7.                         )
  8.                        cv
  9.                        (cdr cv)
  10.                )
  11.              )
  12.     )
  13.     (setq ge (xdge::constructor cv))
  14.   )
  15.   (if (= (type n) 'REAL)
  16.     (progn
  17.       (setq len        (xdge::getpropertyvalue ge "length")
  18.             nn        (fix (/ len n))
  19.             in        (xdge::constructor "AcGeInterval" 0.0 (* nn n))
  20.       )
  21.       (xdge::setpropertyvalue ge "setInterval" in)
  22.       (setq n nn)
  23.     )
  24.   )
  25.   (setq pts (xdge::getpropertyvalue ge "getSamplePoints" (fix n)))
  26.   (xdge::free ge)
  27.   pts
  28. )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1268个

财富等级: 财源广进

 楼主| 发表于 2014-10-4 19:17:14 | 显示全部楼层
  1. (defun XDGL::Curve:GetSubCurve
  2.        (ge from to / prec in atStart atEnd clone nin)
  3.   (setq        prec        (car (xdrx_document_getprec))
  4.         in        (car (xdge::getpropertyvalue ge "getInterval"))
  5.         atStart        (equal (xdge::getpropertyvalue in "lowerBound")
  6.                        to
  7.                        prec
  8.                 )
  9.         atEnd        (equal (xdge::getpropertyvalue in "upperBound")
  10.                        from
  11.                        prec
  12.                 )
  13.   )
  14.   (cond
  15.     ((and atStart atEnd) ge)
  16.     ((= (xdge::type ge) "kNurbCurve3d")
  17.      (setq clone (xdge::copy ge))
  18.      (if (< from to)
  19.        (if (or atStart atEnd)
  20.          (progn
  21.            (xdge::setpropertyvalue clone "hardTrimByParams" from to)
  22.            clone
  23.          )
  24.          (progn
  25.            (xdge::setpropertyvalue
  26.              clone
  27.              "hardTrimByParams"
  28.              (xdge::getpropertyvalue in "lowerBound")
  29.              to
  30.            )
  31.            (xdge::setpropertyvalue clone "hardTrimByParams" from to)
  32.            clone
  33.          )
  34.        )
  35.        (progn
  36.          (setq clone1 (xdge::copy ge)
  37.                clone2 (xdge::copy ge)
  38.          )
  39.          (xdge::setpropertyvalue
  40.            clone1
  41.            "hardTrimByParams"
  42.            from
  43.            (xdge::getpropertyvalue in "upperBound")
  44.          )
  45.          (xdge::setpropertyvalue
  46.            clone2
  47.            "hardTrimByParams"
  48.            (xdge::getpropertyvalue in "lowerBound")
  49.            to
  50.          )
  51.          (xdge::setpropertyvalue clone1 "joinWith" clone2)
  52.          clone1
  53.        )
  54.      )
  55.     )
  56.     (t
  57.      (setq clone (xdge::copy ge)
  58.            nin         (xdge::constructor "AcGeInterval" from to)
  59.      )
  60.      (xdge::setpropertyvalue clone "setInterval" nin)
  61.      clone
  62.     )
  63.   )
  64. )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1268个

财富等级: 财源广进

 楼主| 发表于 2014-10-15 09:06:56 | 显示全部楼层
继续,AcGeCompositeCrv3d 的 GetSplitCurves ,改编自 lzh 的 Net 版函数,尚未测试
  1. (defun XDGL::Curve:GetSplitCurves (c3d           pars           /           prec
  2.                                    inter   c3ds           lowerBound
  3.                                    upperBound           tf           in1
  4.                                    in2           j           cp1           cp2
  5.                                    seg1           seg2           cs1           cs
  6.                                    curves
  7.                                   )
  8.   (defun _remvoedups (lst / nlst)
  9.     (setq lst  (vl-sort lst '>)
  10.           nlst (list (car lst))
  11.           lst  (cdr lst)
  12.     )
  13.     (while lst
  14.       (if (not (equal (car lst) (car nlst) prec))
  15.         (setq nlst (cons (car lst) nlst))
  16.       )
  17.       (setq lst (cdr lst))
  18.     )
  19.     nlst
  20.   )
  21.   (setq        prec  (car (xdrx_document_getprec))
  22.         inter (car (xdge::getpropertyvalue c3d "getIntervarl"))
  23.         c3ds  (xdge::getpropertyvalue c3d "getCurveList")
  24.         pars  (_remvoedups lst)
  25.         tf    t
  26.   )
  27.   (mapcar 'set
  28.           '(lowerBound upperBound)
  29.           (xdge::getpropertyvalue inter "lowerBound" "upperBound")
  30.   )
  31.   (if (= (length pars) 0)
  32.     (setq tf nil)
  33.     (progn
  34.       (if (and (= (length c3ds) 1)
  35.                (xdge::getpropertyvalue (car c3ds) "isClosed")
  36.           )
  37.         (if (> (length pars) 1)
  38.           (progn
  39.             (if        (equal (car pars) lowerBound prec)
  40.               (progn
  41.                 (setq pars (cons lowerBound (cdr pars)))
  42.                 (if (equal (last pars) upperBound prec)
  43.                   (progn
  44.                     (setq pars (reverse (cdr (reverse pars))))
  45.                     (if        (= (length pars) 1)
  46.                       (setq tf nil)
  47.                     )
  48.                   )
  49.                 )
  50.               )
  51.               (if (equal (last pars) upperBound prec)
  52.                 (setq pars
  53.                        (reverse (cons upperBound (cdr (reverse pars))))
  54.                 )
  55.               )
  56.             )
  57.             (setq pars (reverse (cons upperBound (cdr pars))))
  58.           )
  59.           (setq tf nil)
  60.         )
  61.         (progn
  62.           (if (equal (car pars) lowerBound prec)
  63.             (setq pars (cons lowerBound (cdr pars)))
  64.             (setq pars (cons lowerBound pars))
  65.           )
  66.           (if (equal (last pars) upperBound prec)
  67.             (setq pars (reverse (cons upperBound (cdr (reverse pars)))))
  68.             (setq pars (reverse (cons upperBound (reverse pars))))
  69.           )
  70.         )
  71.       )
  72.     )
  73.   )
  74.   (if tf
  75.     (progn
  76.       (setq i 0)
  77.       (repeat (length pars)
  78.         (mapcar        'set
  79.                 '(cp1 seg1)
  80.                 (xdge::getpropertyvalue c3d "globalToLocalParameter")
  81.         )
  82.         (mapcar        'set
  83.                 '(cp2 seg2)
  84.                 (xdge::getpropertyvalue c3d "globalToLocalParameter")
  85.         )
  86.         (if (= seg1 seg2)
  87.           (setq        cc3ds
  88.                  (cons (xdgl::curve:getsubcurve (nth seg1 c3ds) cp1 cp2)
  89.                  )
  90.           )
  91.           (progn
  92.             (setq in1 (car (xdge::getpropertyvalue
  93.                              (nth seg1 c3ds)
  94.                              "getInterval"
  95.                            )
  96.                       )
  97.             )
  98.             (setq
  99.               cc3ds (cons (xdgl::curve:getsubcurve
  100.                             (nth seg1 c3ds)
  101.                             cp1
  102.                             (xdge::getpropertyvalue in1 "upperBound")
  103.                           )
  104.                     )
  105.             )
  106.             (setq j (1+ seg1))
  107.             (while (< j seg2)
  108.               (setq cc3ds (cons (xdge::copy (nth j c3ds)) cc3ds)
  109.                     (setq j (1+ j))
  110.               )
  111.             )
  112.             (setq in2 (car (xdge::getpropertyvalue
  113.                              (nth seg2 c3ds)
  114.                              "getInterval"
  115.                            )
  116.                       )
  117.             )
  118.             (setq cc3ds
  119.                    (cons (xdgl::curve:getsubcurve
  120.                            (nth seg2 c3ds)
  121.                            (xdge::getpropertyvalue in2 "lowerBound")
  122.                            cp2
  123.                          )
  124.                    )
  125.             )
  126.           )
  127.         )
  128.         (setq curves (cons (xdge::constructro
  129.                              "kCompositeCrv3d"
  130.                              (reverse cc3ds)
  131.                            )
  132.                            curves
  133.                      )
  134.         )
  135.       )
  136.     )
  137.   )
  138.   (if (and
  139.         (xdge::getpropertyvalue c3d "isClosed")
  140.         (> (xdge::getpropertyvalue c3ds "length") 1)
  141.       )
  142.     (progn
  143.       (setq curves (reverse curves)
  144.             cs           (xdge::getpropertyvalue (last curves) "getCurveList")
  145.             cs1           (xdge::getpropertyvalue (car curves) "getCurveList")
  146.             cs           (append cs cs1)
  147.             curves (reverse (cons (xdge::constructro "kCompositeCrv3d" cs)
  148.                                   (cdr (reverse curves))
  149.                             )
  150.                    )
  151.             curves (cdr curves)
  152.       )
  153.     )
  154.   )
  155.   curves
  156. )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-8 08:18 , Processed in 0.411992 second(s), 40 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表