明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3352|回复: 11

[已解答] 求如何计算以下圆弧entmake的组码

[复制链接]
发表于 2013-7-13 19:28:10 | 显示全部楼层 |阅读模式
    自己写了个lisp程序,其中需要根据已知条件绘制大量圆弧。现在使用command命令,但运算时间太长,想用entmake绘制以减少绘图时间,求相应的组码

1.已知构成圆弧的3点坐标,用entmake画出圆弧,图元类型为ARC或LWPOLYLINE
(command "arc" P1 P2 P3)

2.已知构成圆弧1的3点坐标(或直线1的2点坐标)、圆弧2的端点及圆弧3的端点,圆弧2分别和圆弧1(或直线1)圆弧3相连,并在相连处相切,求使用entmake画出圆弧2、圆弧3或包含圆弧2、圆弧3的多线段
(command "arc" P1  P2 P3)或(command "line" P1 P3 "")   ;圆弧1或直线1
(command "arc" "" p4)                                                    ;圆弧2
(command "arc" "" p5)                                                    ;圆弧3      



该贴已经同步到 victo_ept的微博

本帖子中包含更多资源

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

x
发表于 2013-7-13 20:20:07 | 显示全部楼层
本帖最后由 wowan1314 于 2013-7-13 20:21 编辑

(entmake (list '(0 . "ARC") (cons 10 pt) (cons 40 R)(cons 50 ANG1)(cons 51 ANG2)))
这entmake圆弧的代码。

从中可以看出你要根据圆弧上的三点先找出圆心。找到圆心其他就简单了.

找圆心:  好像是三点连线的中垂线的交点。
 楼主| 发表于 2013-7-14 00:40:55 | 显示全部楼层
本帖最后由 victo_ept 于 2013-7-14 00:46 编辑

第一个问题找到个C语言的,修改成Lisp如下
  1. (defun ARCmake (P1 P2 P3)
  2.   (setq  x1 (car P1)
  3.           y1 (cadr P1)
  4.           x2 (car P2)
  5.           y2 (cadr P2)
  6.           x3 (car P3)
  7.           y3 (cadr P3)
  8.   )

  9.   (setq   a (* 2 (- x2 x1))
  10.            b (* 2 (- y2 y1))
  11.            c (- (+ (* x2 x2) (* y2 y2)) (+ (* x1 x1) (* y1 y1)))
  12.            d (* 2 (- x3 x2))
  13.            e (* 2 (- y3 y2))
  14.            f (- (+ (* x3 x3) (* y3 y3)) (+ (* x2 x2) (* y2 y2)))
  15.   )
  16.   (setq  m (- (* b f) (* e c))
  17.           n (- (* d c) (* a f))
  18.           s (- (* b d) (* e a))
  19.   )

  20.   (if (= s 0)
  21.     (princ "\n三点在同一条直线上")
  22.     (progn (setq Pt (list (/ m s) (/ n s)))
  23.            (setq ra (distance Pt P1))
  24.            (setq  ang1        (angle Pt P1)
  25.                    ang2        (angle Pt P2)
  26.                    ang3        (angle Pt P3)
  27.                    angMax    (max ang1 ang3)
  28.                    angMin     (min ang1 ang3)

  29.            )
  30.            (if (and (> ang2 angMin) (< ang2 angMin))
  31.              (setq ang50 angMin
  32.                     ang51 angMax
  33.              )
  34.              (setq ang50 angMax
  35.                     ang51 angMin
  36.              )
  37.            )

  38.            (entmake (list '(0 . "ARC")
  39.                           (cons 10 Pt)
  40.                           (cons 40 Ra)
  41.                           (cons 50 ang50)
  42.                           (cons 51 ang51)
  43.                     )
  44.            )
  45.     )
  46.   )
  47.   (princ)
  48. )

点评

明白了! 这个数学算法吧! 咱有现成的函数可用哈  发表于 2013-7-16 20:03
只能绘制优弧,不能绘制劣弧?  发表于 2013-7-16 18:44
发表于 2013-7-16 18:15:08 | 显示全部楼层
本帖最后由 wowan1314 于 2013-7-16 18:30 编辑
victo_ept 发表于 2013-7-14 00:40
第一个问题找到个C语言的,修改成Lisp如下

我刚也写了个。思路就是简单的思路求中垂交点。

楼主给讲解下哈你的思路是什么啊?。 我表示完全没看懂啊!好像是 向量的算法。都不晓得是什么了!

下面是简单思路求圆心。其中YY-NP1P2就是前两天发表的   定数等分点函数。
  1. (defun YY-3arc (p1 p2 p3 / z1 z2 yxin)
  2.   (setq z1 (car (YY-np1p2 p1 p2 2))
  3.         z2 (car (YY-np1p2 p1 p3 2))
  4.   )
  5.   (if
  6.     (setq yxin (inters
  7.             z1 (polar z1 (+ (angle p1 p2)(* pi 0.5)) 0.1)
  8.             z2 (polar z2 (+ (angle p1 p3)(* pi 0.5)) 0.1)
  9.             nil
  10.          )
  11.     )
  12.     (list yxin (distance yxin p1))
  13.   )
  14. )

点评

你的思路简洁多了,我的纯粹是数学运算解方程  发表于 2013-7-18 19:09
发表于 2013-7-16 19:21:44 | 显示全部楼层
要解决这个问题估计还是得会求凸度,先发个网上搜来的代码

  1. ; AutoLISP function to convert from Polyline "Bulge" representation
  2. ; of an arc to AutoCAD's normal "center, radius, start/end angles"
  3. ; form of arc.  This function applies the bulge between two adjacent
  4. ; vertices.  It assumes that global symbols "sp", "ep", and "bulge"
  5. ; contain the current vertex (start point), next vertex (end point),
  6. ; and bulge, respectively.  It sets the appropriate values in global
  7. ; symbols "cen", "rad", "sa", and "ea".

  8. ; by Duff Kurland - Autodesk, Inc.
  9. ; July 7, 1986

  10. (defun cvtbulge (/ cotbce x1 x2 y1 y2 temp)
  11.   (setq x1 (car  sp) x2 (car  ep))
  12.   (setq y1 (cadr sp) y2 (cadr ep))
  13.   (setq cotbce (/ (- (/ 1.0 bulge) bulge) 2.0))

  14.   ; Compute center point and radius

  15.   (setq cen (list (/ (+ x1 x2 (- (* (- y2 y1) cotbce))) 2.0)
  16.                   (/ (+ y1 y2    (* (- x2 x1) cotbce) ) 2.0))
  17.   )
  18.   (setq rad (distance cen sp))

  19.   ; Compute start and end angles

  20.   (setq sa  (atan (- y1 (cadr cen)) (- x1 (car cen))))
  21.   (setq ea  (atan (- y2 (cadr cen)) (- x2 (car cen))))
  22.   (if (< sa 0.0)                      ; Eliminate negative angles
  23.      (setq sa (+ sa (* 2.0 pi)))
  24.   )
  25.   (if (< ea 0.0)
  26.      (setq ea (+ ea (* 2.0 pi)))
  27.   )
  28.   (if (< bulge 0.0)                   ; Swap angles if clockwise
  29.      (progn
  30.         (setq temp sa)
  31.         (setq sa ea)
  32.         (setq ea temp)
  33.      )
  34.   )
  35. )
 楼主| 发表于 2013-7-18 19:19:28 | 显示全部楼层
提出这个问题最初是因为要使用相切圆弧去逼近Spline曲线,最后发现占用时间最多的不是画弧,而是求圆弧与Spline曲线的最大距离
 楼主| 发表于 2013-7-18 19:49:15 | 显示全部楼层
victo_ept 发表于 2013-7-14 00:40
第一个问题找到个C语言的,修改成Lisp如下

优弧劣弧都可以求,上面的ang50、ang51就是为了判断P、P2点的角度哪个是50的,哪个是51的组吗值
后来查找了一下更通用的做法可以用矢量的叉积来判断是逆时针,还是顺时针
;;;设矢量P = ( x1, y1 ),Q = ( x2, y2 ),
;;;矢量叉积P × Q = x1*y2 - x2*y1
;;;若 P × Q > 0 , 则P在Q的顺时针方向。
;;;若 P × Q < 0 , 则P在Q的逆时针方向。
;;;若 P × Q = 0 , 则P与Q共线,但可能同向也可能反
发表于 2013-7-22 08:20:41 | 显示全部楼层
发表于 2013-7-27 11:20:53 | 显示全部楼层
发表于 2013-7-28 13:25:57 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-29 11:38 , Processed in 0.188288 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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