获取两个二维点表的所有交点(非vla-IntersectWith)
本帖最后由 lishucheng96 于 2018-1-31 16:57 编辑;;说明:得到两个二维点表的交点
;;用非vla-IntersectWith方法不生成对象写的点表交点函数,可选多种延长方向,两点表都可以选择是否双向延长还是各自单向延长
;;参数:lst1:点表1
;;参数:lst2:点表2
;;参数:typ:延长类型(不区别大小写):"0000"或其他—两个都不延长;"0001"—延长点表2右侧两个点; "0010"—延长点表2左侧两个点; "0011"—延长点表2两侧两个点; "1000"—延长点表1左侧两个点; "0100"—延长点表1右侧两个点;"1100"—延长点表1两侧两个点;"1111"—延长点表1和点表2两侧两个点;
;;返回:符合条件的包括所有交点的二维点表
;;示例
;(setq lst1 (list (list 1492.5310 356.4799) (list 1693.9629 457.0300) (list 2085.9058 466.7216) (list 2281.2705 367.3829)))
;(setq lst2 (list (list 1567.8204 362.9696) (list 1667.2671324.9823) (list 1980.3360 258.3527) (list 2205.2348 357.8477)))
;(setq typ "0011")
;(Intpt_2lsts lst1 lst2 typ)
;((1532.53 376.449) (2255.92 380.272))
(defun Intpt_2lsts(lst1 lst2 typ / ii jj pt1 pt2 pt3 pt4 azi intpt interpt)
(setq ii (length lst1))
(setq jj (length lst2))
;延长lst1左侧
(if (= (substr typ 1 1) "1")
(progn
(setq pt1 (nth 0 lst1))
(setq pt2 (nth 1 lst1))
(setq azi (angle pt1 pt2))
(setq azi (+ pi azi))
(setq lst1 (append (list (polar pt1 azi 10000) ) lst1 ))
)
)
;延长lst1右侧
(if (= (substr typ 2 1) "1")
(progn
(setq pt1 (nth (1- ii) lst1))
(setq pt2 (nth ii lst1))
(setq azi (angle pt1 pt2))
(setq lst1 (append lst1 (list (polar pt2 azi 10000) ) ))
)
)
;延长lst2左侧
(if (= (substr typ 3 1) "1")
(progn
(setq pt3 (nth 0 lst2))
(setq pt4 (nth 1 lst2))
(setq azi (angle pt3 pt4))
(setq azi (+ pi azi))
(setq lst2 (append (list (polar pt3 azi 10000) ) lst2 ))
)
)
;延长lst2右侧
(if (= (substr typ 4 1) "1")
(progn
(setq pt3 (nth (1- jj) lst2))
(setq pt4 (nth jj lst2))
(setq azi (angle pt3 pt4))
(setq lst2 (append lst2 (list (polar pt4 azi 10000) ) ))
)
)
;计算交点坐标
(setq ii (1- (length lst1)))
(setq jj (1- (length lst2)))
(setq intpt nil interpt nil i 0 )
(while (< i ii)
(setq pt1 (nth i lst1))
(setq pt2 (nth (1+ i) lst1))
(setq j 0)
(while (< j jj)
(setq pt3 (nth j lst2))
(setq pt4 (nth (1+ j) lst2))
(setq intpt (inters pt1 pt2 pt3 pt4 t) )
(if (/= intpt nil)
;将交点坐标存入点表
(setq interpt (append interpt (list intpt)))
)
(setq j (1+ j))
)
(setq i (1+ i))
)
interpt
)
支持一下楼主大作 谢谢大哥:lol 不错,谢谢楼主,正好需要用到:victory:
页:
[1]