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

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

日志

两线间拟合多段线

热度 4已有 1518 次阅读2012-11-15 11:37 |个人分类:回答问题|系统分类:开发| 两线间拟合多段线

问题来源:http://bbs.mjtd.com/thread-99157-1-1.html

两线间拟合多段线.LSP

本源代码由 Gu_xl 编写! 联系方式: Email: Gu_xl@sohu.com
(defun c:tt  (/	E1 E2 N	L1 L2 D1 D2 DD1	DD2 PTS1 PTS2 P1 P2 W1 MP1 P3 P4
	      W2 MP2 CP cmdecho osmode *error*)
  (defun *error* (s)
    (setvar 'osmode osmode)
    (setvar 'cmdecho cmdecho)
    (princ s) (princ)
    )
  (setq cmdecho (getvar 'cmdecho)
	osmode (getvar 'osmode)
	)
  (setvar 'osmode 0)
  (setvar 'cmdecho 0)
  (if (and (setq e1 (ssget ":S" '((0 . "*line,arc"))))
	   (setq e2 (ssget ":S" '((0 . "*line,arc"))))
	   )
    (progn
      (setq e1 (ssname e1 0)
	    e2 (ssname e2 0)
	    )
      (initget 6)
      (setq n (getint "\n拟合精度<1000>:"))
      (if (null n)
	(setq n 1000))
      (setq l1	 (vlax-curve-getDistAtParam
		   e1
		   (vlax-curve-getEndParam e1))
	    l2	 (vlax-curve-getDistAtParam
		   e2
		   (vlax-curve-getEndParam e2))
	    d1	 (/ l1 n)
	    d2	 (/ l2 n)
	    dd1	 0
	    dd2	 0
	    pts1 (list (vlax-curve-getStartPoint e1))
	    pts2 (list (vlax-curve-getStartPoint e2))
	    )
      (repeat (1- n)
	(setq pts1 (cons (vlax-curve-getpointatdist
			   e1
			   (setq dd1 (+ dd1 d1)))
			 pts1)
	      pts2 (cons (vlax-curve-getpointatdist
			   e2
			   (setq dd2 (+ dd2 d2)))
			 pts2)
	      )
	)
      (setq pts1 (reverse (cons (vlax-curve-getendpoint e1) pts1))
	    pts2 (reverse (cons (vlax-curve-getendpoint e2) pts2))
	    )
      (if (inters (car pts1) (car pts2) (last pts1) (last pts2))
	(setq pts2 (reverse pts2))
	)
      (setq p1	 (car pts1)
	    p2	 (car pts2)
	    pts1 (cdr pts1)
	    pts2 (cdr pts2)
	    w1	 (distance p1 p2)
	    mp1	 (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5))
	    )
      (command "_pline" mp1)
      (repeat n
	(setq p3   (car pts1)
	      p4   (car pts2)
	      pts1 (cdr pts1)
	      pts2 (cdr pts2)
	      w2   (distance p3 p4)
	      mp2  (mapcar '* (mapcar '+ p3 p4) '(0.5 0.5 0.5))
	      cp   (inters p1 p4 p2 p3)
	      )
	(command "w" w1 w2 mp2 )
	(setq p1  p3
	      p2  p4
	      w1  w2
	      mp1 mp2)

	)
      (command "")
      )
    )
  (setvar 'osmode osmode)
    (setvar 'cmdecho cmdecho)  
  )

路过

雷人
4

握手

鲜花

鸡蛋

刚表态过的朋友 (4 人)

评论 (0 个评论)

facelist doodle 涂鸦板

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

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

GMT+8, 2024-5-6 15:11 , Processed in 0.391677 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部