找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1334|回复: 1

[[coior=red]文档类] (XD::Doc:Getdist)获取距离向量(2016.5.24更新)

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2014-10-29 23:57:51 | 显示全部楼层 |阅读模式
函数发布
函数名称: XD::Doc:Getdist
调用格式: (XD::Doc:Getdist basePnt info col)
参数说明: basePnt --- 基点 or nil
info --- 提示字串 or nil
col --- 线颜色 or nil (红色) , 负数实线
xdir --- 自定义X轴向量
orthomode - T 强制垂直, 其它值 随系统或 随 xdir
返回值: 向量
函数简介: 获取向量
函数来源: 原创
函数作者: eachy
适用版本: XDRX API 
最后更新时间: 2016-05-24
备注: 支持垂直
演示图片: -

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

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

×
  1. ;|
  2. basePnt --- 基点 or nil
  3. info    --- 提示字串 or nil
  4. col     --- 线颜色 or nil (红色) , 负数实线
  5. xdir    --- 自定义X轴向量
  6. orthomode - T 强制垂直, 其它值 随系统或 随 xdir
  7. |;
  8. (defun XD::Doc:GetDist (basePnt      info   col        xdir     orthomode  /       _pnt:projectOnAxis
  9.    _pnt:GetdistOnAxis   p1        v     myerr  callback     olderr
  10.    con
  11.          )
  12.   (defun _pnt:GetdistOnAxis (bp p ucsxdir / baseAng vp tf1 tf2 lst dis sdis tf)
  13.     (setq lst  (trans (mapcar '- p bp) 0 ucsxdir)
  14.    dis  (distance bp p)
  15.    sdis (rtos dis 2 3)
  16.    tf   (equal dis (atof sdis) 0.0001)
  17.     )
  18.     (if (or orthomode
  19.      (= (getvar "orthomode") 1)
  20. )
  21.       (if (equal ucsxdir '(1.0 0.0 0.0))
  22. (progn
  23.    (setq tf1 (< (* pi 0.25) (angle bp p) (* 0.75 pi))
  24.   tf2 (< (* pi 1.25) (angle bp p) (* 1.75 pi))
  25.    )
  26.    (if tf ;_input
  27.      (if (or tf1 tf2)
  28.        (polar bp
  29.        (if tf1
  30.          (/ pi 2)
  31.          (* pi 1.5)
  32.        )
  33.        dis
  34.        )
  35.        (polar bp
  36.        (if (or (< (angle bp p) (/ pi 2)) (> (angle bp p) (* 1.5 pi)))
  37.          0.0
  38.          pi
  39.        )
  40.        dis
  41.        )
  42.      )
  43.      (if (or tf1 tf2)
  44.        (list (car bp) (cadr p) 0.)
  45.        (list (car p) (cadr bp) 0.)
  46.      )
  47.    )
  48. )
  49. (progn
  50.    (setq baseAng (angle '(0. 0. 0.) ucsxdir))
  51.    (setq vp (trans (mapcar '- p bp) 0 ucsxdir))
  52.    (if
  53.      (or (<= (* 0.25 pi) (- (angle bp p) baseAng) (* 0.75 pi))
  54.   (<= (* 1.25 pi) (- (angle bp p) baseAng) (* 1.75 pi))
  55.      )
  56.       (polar bp
  57.       (+ (* pi 0.5) baseAng)
  58.       (if tf
  59.         dis
  60.         (car vp)
  61.       )
  62.       )
  63.       (polar bp
  64.       baseAng
  65.       (if tf
  66.         dis
  67.         (last vp)
  68.       )
  69.       )
  70.    )
  71. )
  72.       )
  73.       p
  74.     )
  75.   )
  76.   (defun _pnt:projectOnAxis (bp p ucsxdir / baseAng vp)
  77.     (if (or orthomode
  78.      (= (getvar "orthomode") 1)
  79. )
  80.       (if (equal ucsxdir '(1.0 0.0 0.0))
  81. (if (or (< (* pi 0.25) (angle bp p) (* 0.75 pi))
  82.   (< (* pi 1.25) (angle bp p) (* 1.75 pi))
  83.      )
  84.    (list (car bp) (cadr p) 0.)
  85.    (list (car p) (cadr bp) 0.)
  86. )
  87. (progn
  88.    (setq baseAng (angle '(0. 0. 0.) ucsxdir))
  89.    (setq vp (trans (mapcar '- p bp) 0 ucsxdir))
  90.    (if
  91.      (or (<= (* 0.25 pi) (- (angle bp p) baseAng) (* 0.75 pi))
  92.   (<= (* 1.25 pi) (- (angle bp p) baseAng) (* 1.75 pi))
  93.      )
  94.       (polar bp (+ (* pi 0.5) baseAng) (car vp))
  95.       (polar bp baseAng (last vp))
  96.    )
  97. )
  98.       )
  99.       p
  100.     )
  101.   )
  102.   (defun myerr (msg)
  103.     (princ "\n*cancel*")
  104.     (xdrx_pointmonitor)
  105.     (xdrx_sysvar_pop)
  106.     (redraw)
  107.     (princ)
  108.   )
  109.   (defun callback (dynpt /)
  110.     (redraw)
  111.     (if (not (equal xdir '(1.0 0.0 0.) 1e-3))
  112.       (XD::Doc:DrawXAxis basePnt xdir 1)
  113.     )
  114.     (xdrx_grdraw
  115.       col
  116.       con
  117.       (trans basePnt 1 0)
  118.       (trans (_pnt:projectOnAxis basePnt (trans dynpt 0 1) xdir)
  119.       1
  120.       0
  121.       )
  122.     )
  123.   )
  124.   (setq olderr *error*
  125. *error* myerr
  126.   )
  127.   (if (not col)
  128.     (setq col 1)
  129.   )
  130.   (if (minusp col)
  131.     (setq con 0
  132.    col (abs col)
  133.     )
  134.     (setq con 1)
  135.   )
  136.   (if xdir
  137.     (setq xdir (xdrx_vector_normalize xdir))
  138.     (setq xdir '(1.0 0.0 0.0))
  139.   )
  140.   (if (not basePnt)
  141.     (setq basePnt (getpoint "\n基点: "))
  142.     (setvar "lastpoint" basePnt)
  143.   )
  144.   (if basePnt
  145.     (progn
  146.       (setvar "lastpoint" basePnt)
  147.       (xdrx_pointmonitor "callback")
  148.       (xdrx_sysvar_push '("apbox" 1))
  149.       (setq p1 (getpoint (if info
  150.       info
  151.       "\n距离: "
  152.     )
  153.         )
  154.       )
  155.       (setq
  156. v (mapcar '-
  157.     (_pnt:GetdistOnAxis basePnt p1 xdir)
  158.     basePnt
  159.    )
  160.       )
  161.     )
  162.     (and (setq p1 (getpoint (if info
  163.          info
  164.          "\n距离: "
  165.        )
  166.     )
  167.   )
  168.   (setq
  169.     v (mapcar '-
  170.        (_pnt:GetdistOnAxis basePnt p1 xdir)
  171.        basePnt
  172.       )
  173.   )
  174.     )
  175.   )
  176.   (setq *error* olderr)
  177.   (xdrx_pointmonitor)
  178.   (xdrx_sysvar_pop)
  179.   (redraw)
  180.   v
  181. )






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

已领礼包: 593个

财富等级: 财运亨通

 楼主| 发表于 2014-11-5 09:51:29 | 显示全部楼层
更新,增加自定义 XAxis 及强制垂直模式
在自定义 Xdir  时用到的一个箭头提示
  1. (defun XD::Doc:DrawXAxis (p v col / an an1 h h1        d1 d2 p1 p2 p3 p4 p5 p6
  2.                           p7)
  3.   (setq        an  (angle '(0. 0. 0.) v)
  4.         an1 (+ an (/ pi 2))
  5.         h   (getvar "viewsize")
  6.         h1  (/ h 80.)
  7.         d1  (* 0.25 (getvar "viewsize"))
  8.         d2  (* d1 0.7)
  9.         p1  (polar p an1 h1)
  10.         p2  (polar p1 an d2)
  11.         p3  (polar p2 an1 h1)
  12.         p4  (polar p an d1)
  13.         p5  (polar p (+ an1 pi) h1)
  14.         p6  (polar p5 an d2)
  15.         p7  (polar p6 (+ an1 pi) h1)
  16.   )
  17.   (grvecs (list        col p5 p1 col p1 p2 col        p2 p3 col p3 p4        col p4 p7 col p7
  18.                 p6 col p6 p5)
  19.   )
  20.   t
  21. )


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-24 12:10 , Processed in 0.356888 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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