乐筑天下

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

[编程交流] 没时间了。GRVEC和Grread

[复制链接]

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 13:28:00 | 显示全部楼层
提供另一组眼睛:
 
  1. (DEFUN GETARCLASTPOINT (_pt1 _pt2 _msg`str / *error* *-ce _msg`str *-pt)
  2. (defun *error* (msg)
  3.    (and *-ce (setvar "cmdecho" *-ce)))
  4. (SETQ *-ce (GETVAR "cmdecho"))
  5. (SETVAR "cmdecho" 0)
  6. (or _msg`str (setq _msg`str "Specify point: "))
  7. (PROMPT (strcat "\n" _msg`str))
  8. (and (VL-CMDF (GETCNAME "_ARC") _pt1 _pt2 pause)
  9.       (SETQ *-pt (GETVAR "LASTPOINT"))
  10.       (ENTDEL (ENTLAST)))
  11. (*error* nil)
  12. *-pt)
回复

使用道具 举报

15

主题

687

帖子

169

银币

中流砥柱

Rank: 25

铜币
582
发表于 2022-7-6 13:33:21 | 显示全部楼层
你好
 
如果你真的想用grread画一个3点的弧,你可以启发以下例程。
但我同意李和艾伦的观点,司令部提供了更多的选择和全面的OSNAP。
 
  1. ;; Make3PointsArc (gile)
  2. ;; Entmakes an arc
  3. ;; Returns the arc ename
  4. ;;
  5. ;; Arguments
  6. ;; p1, p2, p3: points (UCS coordinates)
  7. (defun Make3PointsArc (p1 p2 p3 / m1 m2 a1 a2 pi/2 cen Xang norm cen rad)
  8. (setq m1   (midPoint p1 p2)
  9.        m2   (midPoint p2 p3)
  10.        a1   (angle p1 p2)
  11.        a2   (angle p2 p3)
  12.        pi/2 (/ pi 2)
  13.        norm (trans '(0. 0. 1.) 1 0 T)
  14.        Xang (angle '(0. 0. 0.) (trans (getvar 'ucsxdir) 0 norm))
  15.        cen  (inters m1 (polar m1 (+ a1 pi/2) 1.0) m2 (polar m2 (+ a2 pi/2) 1.0) nil)
  16.        rad  (distance cen p1)
  17. )
  18. (if (clockwise-p p1 p2 p3)
  19.    (setq start (angle cen p3)
  20.          end   (angle cen p1)
  21.    )
  22.    (setq start (angle cen p1)
  23.          end   (angle cen p3)
  24.    )
  25. )
  26. (entmakex
  27.    (list
  28.      '(0 . "ARC")
  29.      (cons 10 (trans cen 1 norm))
  30.      (cons 40 rad)
  31.      (cons 50 (+ Xang start))
  32.      (cons 51 (+ Xang end))
  33.      (cons 210 norm)
  34.    )
  35. )
  36. )
  37. ;; MidPoint (gile)
  38. ;; Returns the middle point between p1 and p2
  39. (defun MidPoint (p1 p2)
  40. (mapcar (function (lambda (x1 x2) (/ (+ x1 x2) 2.))) p1 p2)
  41. )
  42. ;; Clockwise-p (gile)
  43. ;; evaluates if p1, p2, p3 are clockwise
  44. (defun clockwise-p (p1 p2 p3)
  45. (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
  46. )
  47. ;; STR2PT (gile)
  48. ;; Converts a string into a point (grread input)
  49. ;;
  50. ;; Argument: a string
  51. ;; Return: a 3d point or nil (if incorrect string)
  52. (defun str2pt (str)
  53. (setq str (mapcar 'read (str2lst str ",")))
  54. (if (and (vl-every 'numberp str)
  55.           (< 1 (length str) 4)
  56.      )
  57.    (trans str 0 0)
  58. )
  59. )
  60. ;; STR2LST (gile)
  61. ;; Splits a string with separator into a list
  62. ;;
  63. ;; Arguments
  64. ;; str = string
  65. ;; sep = separator
  66. (defun str2lst (str sep / pos)
  67. (if (setq pos (vl-string-search sep str))
  68.    (cons (substr str 1 pos)
  69.          (str2lst (substr str (+ (strlen sep) pos 1)) sep)
  70.    )
  71.    (list str)
  72. )
  73. )
  74. ;; gr-3PointsArc (gile)
  75. ;; grread using to create an arc by 3 points
  76. ;;
  77. ;; Arguments
  78. ;; p1 p2: the 2 first points (UCS coordinates)
  79. (defun gr-3PointsArc (p1 p2 / *error* loop gr p3 arc str)
  80. (defun *error* (msg)
  81.    (or (= msg "Function cancelled")
  82.        (princ (strcat "Error: " msg))
  83.    )
  84.    (and arc (entdel arc) (setq arc nil))
  85.    (princ)
  86. )
  87. (setq loop T)
  88. (while (and (setq gr (grread T 12 0)) loop)
  89.    (and arc (entdel arc) (setq arc nil))
  90.    (cond
  91.      ((= 5 (car gr))
  92.       (setq p3 (cadr gr))
  93.       (setq arc (Make3PointsArc p1 p2 p3))
  94.      )
  95.      ((= 3 (car gr))
  96.       (setq arc  (Make3PointsArc p1 p2 p3)
  97.             loop nil
  98.       )
  99.      )
  100.      ((equal gr '(2 13))
  101.       (cond
  102.         ((and str (setq pt (str->pt str)))
  103.          (setq arc (Make3PointsArc p1 p2 p3))
  104.          (setq loop nil)
  105.          (grtext)
  106.         )
  107.         (T
  108.          (setq str nil)
  109.          (princ
  110.            "\nIncorrect point.\nSpecify the third point: "
  111.          )
  112.         )
  113.       )
  114.      )
  115.      (T
  116.       (if (= (cadr gr)  ;_ backspace
  117.         (or
  118.           (and str
  119.                (/= str "")
  120.                (setq str (substr str 1 (1- (strlen str))))
  121.                (princ (chr )
  122.                (princ (chr 32))
  123.           )
  124.           (setq str nil)
  125.         )
  126.         (or
  127.           (and str (setq str (strcat str (chr (cadr gr)))))
  128.           (setq str (chr (cadr gr)))
  129.         )
  130.       )
  131.       (and str (princ (chr (cadr gr))))
  132.      )
  133.    )
  134. )
  135. )
  136. (defun c:test (/ p1 p2)
  137. (if (and
  138.        (setq p1 (getpoint "\nSpecify the first point: "))
  139.        (setq p2 (getpoint p1 "\nSpecify the second point: "))
  140.        (not (equal p1 p2))
  141.        (princ "\nSpecify the third point: ")
  142.      )
  143.    (gr-3PointsArc p1 p2)
  144. )
  145. (princ)
  146. )
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-6 13:36:47 | 显示全部楼层
非常好的gile!
 
顺便说一句,李!暂停=“\\”
 
很好地理解了“and”,但我们都忘记了使用osnap覆盖:
  1. (DEFUN GETARCLASTPOINT (_pt1 _pt2 _msg`str / *error* *-ce _msg`str *-pt)
  2. (defun *error* (msg)
  3.    (and *-ce (setvar "cmdecho" *-ce)))
  4. (SETQ *-ce (GETVAR "cmdecho"))
  5. (SETVAR "cmdecho" 0)
  6. (or _msg`str (setq _msg`str "\nSpecify point: "))
  7. (PROMPT (strcat "\n" _msg`str))
  8. (and (VL-CMDF "_.ARC" "_non" _pt1 "_non" _pt2 pause)
  9.       (SETQ *-pt (GETVAR "LASTPOINT"))
  10.       (ENTDEL (ENTLAST)))
  11. (*error* nil)
  12. *-pt)

我以前没有注意到,但我也将(GETCNAME“\u ARC”)替换为“\u.ARC”,因为这是您真正需要的。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 13:42:24 | 显示全部楼层
非常好的Gile!
 
谢谢Alan,是的,我也忘了快照。。。哦,好吧,看起来两只眼睛比一只好。。
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-6 13:44:30 | 显示全部楼层
大致情况。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 13:49:07 | 显示全部楼层
尽管我很好奇。。。只需要解剖一下你的方法Gile。。。
 
这是我的图表,让其他人受益
 
135010ox0bujujj7ekpz6p.png
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 13:50:59 | 显示全部楼层
稍微扭转一下:
 
  1. ;; Make3PointsArc (gile)
  2. ;; Entmakes an arc
  3. ;; Returns the arc ename
  4. ;;
  5. ;; Arguments
  6. ;; p1, p2, p3: points (UCS coordinates)
  7. (defun Make3PointsArc (p1 p2 p3 / m1 m2 a1 a2 pi/2 cen Xang norm cen rad)
  8. (setq m1   (midPoint p1 p2)
  9.        m2   (midPoint p2 p3)
  10.        a1   (angle p1 p2)
  11.        a2   (angle p2 p3)
  12.        pi/2 (/ pi 2)
  13.        norm (trans '(0. 0. 1.) 1 0 T)
  14.        Xang (angle '(0. 0. 0.) (trans (getvar 'ucsxdir) 0 norm))
  15.        cen  (inters m1 (polar m1 (+ a1 pi/2) 1.0) m2 (polar m2 (+ a2 pi/2) 1.0) nil)
  16.        rad  (distance cen p1)
  17. )
  18. (if (clockwise-p p1 p2 p3)
  19.    (setq start (angle cen p3)
  20.          end   (angle cen p1)
  21.    )
  22.    (setq start (angle cen p1)
  23.          end   (angle cen p3)
  24.    )
  25. )
  26. (entmakex
  27.    (list
  28.      '(0 . "ARC")
  29.      (cons 10 (trans cen 1 norm))
  30.      (cons 40 rad)
  31.      (cons 50 (+ Xang start))
  32.      (cons 51 (+ Xang end))
  33.      (cons 210 norm)
  34.    )
  35. )
  36. )
  37. ;; MidPoint (gile)
  38. ;; Returns the middle point between p1 and p2
  39. (defun MidPoint (p1 p2)
  40. (mapcar (function (lambda (x1 x2) (/ (+ x1 x2) 2.))) p1 p2)
  41. )
  42. ;; Clockwise-p (gile)
  43. ;; evaluates if p1, p2, p3 are clockwise
  44. (defun clockwise-p (p1 p2 p3)
  45. (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
  46. )
  47. ;; STR2PT (gile)
  48. ;; Converts a string into a point (grread input)
  49. ;;
  50. ;; Argument: a string
  51. ;; Return: a 3d point or nil (if incorrect string)
  52. (defun str2pt (str)
  53. (setq str (mapcar 'read (str2lst str ",")))
  54. (if (and (vl-every 'numberp str)
  55.           (< 1 (length str) 4)
  56.      )
  57.    (trans str 0 0)
  58. )
  59. )
  60. ;; STR2LST (gile)
  61. ;; Splits a string with separator into a list
  62. ;;
  63. ;; Arguments
  64. ;; str = string
  65. ;; sep = separator
  66. (defun str2lst (str sep / pos)
  67. (if (setq pos (vl-string-search sep str))
  68.    (cons (substr str 1 pos)
  69.          (str2lst (substr str (+ (strlen sep) pos 1)) sep)
  70.    )
  71.    (list str)
  72. )
  73. )
  74. ;; gr-3PointsArc (gile)
  75. ;; grread using to create an arc by 3 points
  76. ;;
  77. ;; Arguments
  78. ;; p1 p2: the 2 first points (UCS coordinates)
  79. (defun gr-3PointsArc (p1 p3 / *error* loop gr p3 arc str)
  80. (defun *error* (msg)
  81.    (or (= msg "Function cancelled")
  82.        (princ (strcat "Error: " msg))
  83.    )
  84.    (and arc (entdel arc) (setq arc nil))
  85.    (princ)
  86. )
  87. (setq loop T)
  88. (while (and (setq gr (grread T 12 0)) loop)
  89.    (and arc (entdel arc) (setq arc nil))
  90.    (cond
  91.      ((= 5 (car gr))
  92.       (setq p2 (cadr gr))
  93.       (setq arc (Make3PointsArc p1 p2 p3))
  94.      )
  95.      ((= 3 (car gr))
  96.       (setq arc  (Make3PointsArc p1 p2 p3)
  97.             loop nil
  98.       )
  99.      )
  100.      ((equal gr '(2 13))
  101.       (cond
  102.         ((and str (setq pt (str->pt str)))
  103.          (setq arc (Make3PointsArc p1 p2 p3))
  104.          (setq loop nil)
  105.          (grtext)
  106.         )
  107.         (T
  108.          (setq str nil)
  109.          (princ
  110.            "\nIncorrect point.\nSpecify the third point: "
  111.          )
  112.         )
  113.       )
  114.      )
  115.      (T
  116.       (if (= (cadr gr)  ;_ backspace
  117.         (or
  118.           (and str
  119.                (/= str "")
  120.                (setq str (substr str 1 (1- (strlen str))))
  121.                (princ (chr )
  122.                (princ (chr 32))
  123.           )
  124.           (setq str nil)
  125.         )
  126.         (or
  127.           (and str (setq str (strcat str (chr (cadr gr)))))
  128.           (setq str (chr (cadr gr)))
  129.         )
  130.       )
  131.       (and str (princ (chr (cadr gr))))
  132.      )
  133.    )
  134. )
  135. )
  136. (defun c:test (/ p1 p3)
  137. (if (and
  138.        (setq p1 (getpoint "\nSpecify the first point: "))
  139.        (setq p3 (getpoint p1 "\nSpecify the second point: "))
  140.        (not (equal p1 p3))
  141.        (princ "\nSpecify the third point: ")
  142.      )
  143.    (gr-3PointsArc p1 p3)
  144. )
  145. (princ)
  146. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 03:19 , Processed in 0.440162 second(s), 66 queries .

© 2020-2025 乐筑天下

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