明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 748|回复: 4

[经验] 无聊ing,trans函数的小应用(点在ucs上的位置)

  [复制链接]
发表于 2022-9-17 19:20 | 显示全部楼层 |阅读模式
本帖最后由 x_s_s_1 于 2022-9-17 20:04 编辑

无聊ing,trans函数的小应用(点在ucs上的位置),有时候有点用,抛砖引玉,看大家有什么更好的方法


  1. ;;;=============================================
  2. ;;;      通用函数  点在ucs上的位置
  3. ;;;参数: pt------测试点
  4. ;;;       p0------ucs原点
  5. ;;;       px------ucsx向点
  6. ;;;       fuzz----容差
  7. ;;;返回值:点位特征值
  8. (defun xty-G-PtAtUcs (pt p0 px fuzz / o v x x+ x- y y+ y- z z+ z-)
  9.   (setq  v  (mapcar '- px p0)
  10.   v  (trans (mapcar '- pt p0) 0 v)
  11.   x  (last v)
  12.   y  (car v)
  13.   z  (cadr v)
  14.   o  0
  15.   x+ 1
  16.   x- 2
  17.   y+ 4
  18.   y- 8
  19.   z+ 16
  20.   z- 32
  21.   )
  22.   (cond  ((equal pt p0 fuzz) o) ;_位于原点
  23.   ((and (equal y 0. fuzz) (equal z 0. fuzz) (> x fuzz)) x+) ;_位于正x轴
  24.   ((and (equal y 0. fuzz) (equal z 0. fuzz) (< x (- fuzz)))
  25.    x-
  26.   ) ;_位于负x轴
  27.   ((and (equal x 0. fuzz) (equal z 0. fuzz) (> y fuzz)) y+) ;_位于正y轴
  28.   ((and (equal x 0. fuzz) (equal z 0. fuzz) (< y (- fuzz)))
  29.    y-
  30.   ) ;_位于负y轴
  31.   ((and (equal x 0. fuzz) (equal y 0. fuzz) (> z fuzz)) z+) ;_位于正z轴
  32.   ((and (equal x 0. fuzz) (equal y 0. fuzz) (< z (- fuzz)))
  33.    z-
  34.   ) ;_位于负z轴
  35.   ((and (equal z 0. fuzz) (> x fuzz) (> y fuzz)) (+ x+ y+)) ;_位于xy平面第一象限
  36.   ((and (equal z 0. fuzz) (< x (- fuzz)) (> y fuzz))
  37.    (+ y+ x-)
  38.   ) ;_位于xy平面第二象限
  39.   ((and (equal z 0. fuzz) (< x (- fuzz)) (< y (- fuzz)))
  40.    (+ x- y-)
  41.   ) ;_位于xy平面第三象限
  42.   ((and (equal z 0. fuzz) (> x fuzz) (< y (- fuzz)))
  43.    (+ y- x+)
  44.   ) ;_位于xy平面第四象限
  45.   ((and (equal y 0. fuzz) (> x fuzz) (> z fuzz)) (+ x+ z+)) ;_位于xz平面第一象限
  46.   ((and (equal y 0. fuzz) (< x (- fuzz)) (> z fuzz))
  47.    (+ z+ x-)
  48.   ) ;_位于xz平面第二象限
  49.   ((and (equal y 0. fuzz) (< x (- fuzz)) (< z (- fuzz)))
  50.    (+ x- z-)
  51.   ) ;_位于xz平面第三象限
  52.   ((and (equal y 0. fuzz) (> x fuzz) (< z (- fuzz)))
  53.    (+ z- x+)
  54.   ) ;_位于xz平面第四象限
  55.   ((and (equal x 0. fuzz) (> y fuzz) (> z fuzz)) (+ y+ z+)) ;_位于yz平面第一象限
  56.   ((and (equal x 0. fuzz) (< y (- fuzz)) (> z fuzz))
  57.    (+ z+ y-)
  58.   ) ;_位于yz平面第二象限
  59.   ((and (equal x 0. fuzz) (< y (- fuzz)) (< z (- fuzz)))
  60.    (+ y- z-)
  61.   ) ;_位于yz平面第三象限
  62.   ((and (equal x 0. fuzz) (> y fuzz) (< z (- fuzz)))
  63.    (+ z- y+)
  64.   ) ;_位于yz平面第四象限
  65.   ((and (> x fuzz) (> y fuzz) (> z fuzz)) (+ x+ y+ z+)) ;_位于第Ⅰ象限
  66.   ((and (< x (- fuzz)) (> y fuzz) (> z fuzz)) (+ x- y+ z+)) ;_位于第Ⅱ象限
  67.   ((and (< x (- fuzz)) (< y (- fuzz)) (> z fuzz))
  68.    (+ x- y- z+)
  69.   ) ;_位于第Ⅲ象限
  70.   ((and (> x fuzz) (< y (- fuzz)) (> z fuzz)) (+ x+ y- z+)) ;_位于第Ⅳ象限
  71.   ((and (> x fuzz) (> y fuzz) (< z (- fuzz))) (+ x+ y+ z-)) ;_位于第Ⅴ象限
  72.   ((and (< x (- fuzz)) (> y fuzz)(< z (- fuzz))) (+ x- y+ z-)) ;_位于第Ⅵ象限
  73.   ((and (< x (- fuzz)) (< y (- fuzz))(< z (- fuzz)))
  74.    (+ x- y- z-)
  75.   ) ;_位于第Ⅶ象限
  76.   ((and (> x fuzz) (< y (- fuzz)) (< z (- fuzz))) (+ x+ y- z-)) ;_位于第Ⅷ象限
  77.   )
  78. )

  1. (setq
  2.   lst (mapcar '(lambda (x) (xty-G-PtAtUcs x '(0 0 0) '(1 0 0) 1e-6))
  3.         (list '(0 0 0)   '(1 0 0)     '(-1 0 0)     '(0 1 0)
  4.         '(0 -1 0)   '(0 0 1)     '(0 0 -1)     '(1 1 0)
  5.         '(-1 1 0)   '(-1 -1 0)   '(1 -1 0)     '(1 0 1)
  6.         '(-1 0 1)   '(-1 0 -1)   '(1 0 -1)     '(0 1 1)
  7.         '(0 -1 1)   '(0 -1 -1)   '(0 1 -1)     '(1 1 1)
  8.         '(-1 1 1)   '(-1 -1 1)   '(1 -1 1)     '(1 1 -1)
  9.         '(-1 1 -1)   '(-1 -1 -1)  '(1 -1 -1)
  10.        )
  11.       )
  12. )
  13. =>(0 1 2 4 8 16 32 5 6 10 9 17 18 34 33 20 24 40 36 21 22 26 25 37 38 42 41)


测试代码
  1. (defun c:tt (/ en ent gr loop obj pt pt1 pt2)
  2.   (setq  en   (car (entsel "\n拾取一条直线:"))
  3.   ent  (entget en)
  4.   pt1  (cdr (assoc 10 ent))
  5.   pt2  (cdr (assoc 11 ent))
  6.   obj  nil
  7.   loop t
  8.   )
  9.   (while loop
  10.     (setq gr (grread t 15 0)
  11.     pt (cadr gr)
  12.     gr (car gr)
  13.     )
  14.     (cond ((= 5 gr)
  15.      (if obj
  16.        (vla-delete obj)
  17.      )
  18.      (command "sphere" pt 100)
  19.      (setq obj(vlax-ename->vla-object (entlast)))
  20.      (vla-put-color obj(xty-G-PtAtUcs pt pt1 pt2 1e-8))
  21.     )
  22.     ((= 3 gr) (setq loop nil))
  23.     )
  24.   )
  25. )


本帖子中包含更多资源

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

x

评分

参与人数 2明经币 +1 金钱 +5 收起 理由
xj6019 + 1 赞一个!
tigcat + 5 很给力!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2022-9-17 21:17 | 显示全部楼层
再举个栗子:D,判断象限有时候还是有用的


  1. (defun c:tt ()
  2.   (setq  pt0 (getpoint "\n拾取原点:")
  3.   pt1 (getpoint "\n拾取x方向点:")
  4.   )
  5.   (while (setq pt2 (getpoint "\n拾取点:"))
  6.     (setq mode (xty-G-PtAtUcs pt2 pt0 pt1 1e-8))
  7.     (setq en (entmakex (list '(0 . "text")
  8.            '(100 . "AcDbEntity")
  9.            '(100 . "AcDbText")
  10.            (cons 10 pt2)
  11.            (cons 1 (itoa mode))
  12.            (cons 40 100)
  13.            (cons 41 0.8)
  14.            (cons 7 "standard")
  15.            (cons 72 0)
  16.            (cons 11 pt2)
  17.            (cons 50 0)
  18.            (cons 73 0)
  19.            (cons 62 mode)
  20.            )
  21.        )
  22.     )
  23.   )
  24. )


本帖子中包含更多资源

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

x

评分

参与人数 1明经币 +1 收起 理由
tigcat + 1 很给力!

查看全部评分

发表于 2022-9-17 20:33 | 显示全部楼层
支持下,希望多发代码给我们学习。
发表于 2022-9-18 08:09 | 显示全部楼层
向优秀者致敬和学习!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-17 19:28 , Processed in 0.174004 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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