注册 登录
明经CAD社区 返回首页

Gu_xl的个人空间 http://bbs.mjtd.com/?161460 [收藏] [复制] [分享] [RSS]

日志

按弦高限差值回返曲线拟合样本点

热度 19已有 5102 次阅读2014-3-12 10:04 |个人分类:Lisp公用函数|系统分类:开发| 拟合曲线, 样本点

Gxl-GetSamplet.LSP

Gxl-GetSamplet.LSP

本源代码由 Gu_xl 编写发布! 联系方式: Email: Gu_xl@sohu.com
;;(gxl-GetSamplet CURVE d) 按弦高返回曲线拟合样本点
;;参数 curve = 曲线图元名/对象名
;;     d = 弦高限差值
;;   By Gu_xl 明经通道,2015.04.01修正了SPLINE的一个Bug
(defun gxl-GetSamplet (CURVE D / PerDistToLine GETPOINTS NAME DXF PL I)
  (defun PerDistToLine (pt p1 p2 / norm)
    (setq norm (mapcar '- p2 p1)
	  p1   (trans p1 0 norm)
	  pt   (trans pt 0 norm)
    )
    (abs (- (car pt) (car p1)))
  )
  (defun getpoints (curve stPar enPar d / ps pe pm)
    (setq ps (vlax-curve-getPointAtParam curve stPar)
	  pe (vlax-curve-getPointAtParam curve enPar)
	  pm (vlax-curve-getPointAtParam curve (* 0.5 (+ stPar enPar)))
    )
   (if pm
(if (<= (PerDistToLine pm ps pe) d) (list pe) (append (getpoints curve stpar (* 0.5 (+ stPar enPar)) d) (getpoints curve (* 0.5 (+ stPar enPar)) enPar d) ) )
  (list pe)
  )
) (if (= 'vla-object (type curve)) (setq curve (vlax-vla-object->ename curve)) ) (cond ((= "LINE" (setq name (cdr (assoc 0 (setq dxf (entget curve))))) ) (list (vlax-curve-getStartPoint curve) (vlax-curve-getEndPoint curve) ) ) ((= "ARC" name) (cons (vlax-curve-getstartpoint curve) (getpoints curve (vlax-curve-getStartParam curve) (vlax-curve-getEndParam curve) d ) ) ) ((= "CIRCLE" name) (cons (vlax-curve-getstartpoint curve) (append (getpoints curve 0 pi d ) (getpoints curve pi 2pi d ) ) ) ) ((= "ELLIPSE" name) (if (vlax-curve-isClosed curve) (cons (vlax-curve-getstartpoint curve) (append (getpoints curve 0 pi d ) (getpoints curve pi 2pi d ) ) ) (cons (vlax-curve-getstartpoint curve) (getpoints curve (vlax-curve-getStartParam curve) (vlax-curve-getEndParam curve) d ) ) ) ) ((= "SPLINE" name) (setq pl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 11 (car x))) dxf) ) ) (if (not pl) (setq pl (mapcar '(lambda (x) (vlax-curve-getclosestpointto curve (cdr x))) (vl-remove-if-not '(lambda (x) (= 10 (car x))) dxf) ) ) ) (setq pl (mapcar '(lambda (x) (vlax-curve-getParamAtPoint curve x ) ) pl ) ) (if (equal (car pl) (last pl) 1e-6)
        (setq
	 pl (reverse
	      (cons (vlax-curve-getEndParam curve) (cdr (reverse pl)))
	    )
       )
     )
     (setq pl (mapcar 'list pl (cdr pl))
     )
     (setq pl
	    (apply 'append
		   (mapcar
		     '(lambda (x)
			(list
			  (list (car x) (* 0.5 (apply '+ x)))
			  (list (* 0.5 (apply '+ x)) (cadr x))
			)
		      )
		     pl
		   )
	    )
     )
     (cons
       (vlax-curve-getStartPoint curve)
       (apply
	 'append
	 (mapcar '(lambda (x)
		    (apply 'GETPOINTS (append (cons curve x) (list d)))
		  )
		 pl
	 )
       )
     )
    )
    ((WCMATCH name "*POLYLINE")
     (setq pl nil
	   i  -1
     )
     (while (< i (vlax-curve-getEndParam curve))
       (setq pl (cons (setq i (1+ i)) pl))
     )
     (setq pl (reverse pl)
	   pl (mapcar 'list pl (cdr pl))
     )
     (cons
       (vlax-curve-getStartPoint curve)
       (apply
	 'append
	 (mapcar '(lambda (x)
		    (apply 'GETPOINTS (append (cons curve x) (list d)))
		  )
		 pl
	 )
       )
     )
    )
  )
)

路过

雷人
11

握手
2

鲜花

鸡蛋

刚表态过的朋友 (13 人)

发表评论 评论 (7 个评论)

回复 cxjzxh 2014-4-6 15:52
版主思路甚好!
回复 yjr111 2014-12-13 21:17
G版,你这个函数中样条曲线转多段线有个致命漏洞,就是样条曲线是控制点绘制且控制点离相对应的拟合点元而离另一段曲线的拟合点近时,用vlax-curve-getclosestpointto函数就产生错误
回复 yjr111 2014-12-13 21:21
图片画不出,请移步到http://bbs.mjtd.com/forum.php?mod=viewthread&tid=109418附件查看
回复 yjr111 2014-12-13 21:55
G版,已经解决,对参数值进行排序(setq pl(vl-sort pl '(lambda(x y)(< x y))))
回复 903242237 2015-12-20 15:27
高手呀,谢谢楼主呀!
回复 lea丶丶 2016-11-28 16:31
G版,在圆那 2pi应该改成* 2 pi
回复 yjtdkj 2021-6-25 17:20
牛,我自己花几天时间才编出一点点,原来这里有大全呀,谢谢G版!!!!!

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

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

GMT+8, 2024-5-3 18:05 , Processed in 2.946209 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部