[求助]任意两条线的交点坐标
任意两条线的交点坐标,包括PL线与PL线,pl线与LINE,PL线与圆弧,pl线与圆等等,包括它们之间的任意组合方式,得到交点坐标表。请大侠帮助。谢谢 yoyoho 发表于 2010-1-6 22:19(defun m_IntersectWith (m_ent1 m_ent2 / m_obj1 m_obj2 m_objcopy1 m_objcopy2 m_jdtab m_jdtab1 i)  ...
yoyoho大侠好!我一条线与N条等高线外观交点粘贴cass高程属性块20240519圆和闭合多段线不能实现,自己修改过的文件上传到这里了!感觉大侠还能继续优化→能否实现框选cass舒心高程块→输出剖面线并粘贴高程值http://bbs.mjtd.com/forum.php?mod=viewthread&tid=173261&page=6#pid980652 李龙山 发表于 2010-1-5 22:24
测试通过了。(defun c:get_int0( / ent1 ent2 ps) (setq ent1 (car (entsel "选择第一实体:")))  ...
谢谢 才开始学习 也在找这个 任意空间的线如果Z坐标不一致的,还是求不到交点啊,好难啊 你去看一看置顶帖,里面就有。 <p>网内搜一下 vla-IntersectWith</p> <p>(defun m_IntersectWith(m_ent1 m_ent2 / m_obj1 m_obj2 m_objcopy1 m_objcopy2 m_jdtab m_jdtab1 i)<br/> ;;适用对象: Line、Polyline、LWPolyline、Circle、Arc、Ellipse、3dPolyline、Spline<br/> ;;支持求空间虚交点,但Z坐标始终为0.0,要求Z坐标,请用(vlax-curve-getClosestPointToProjection)函数<br/> (setq m_obj1 (vlax-ename->vla-object m_ent1))<br/> (setq m_obj2 (vlax-ename->vla-object m_ent2))<br/> <br/> (setq m_objcopy1 (vla-copy m_obj1));;复制第一条曲线实体<br/> (setq m_objcopy2 (vla-copy m_obj2));;复制第二条曲线实体<br/> <br/> (setq m_objcopy1 (m_ShadowToXY m_objcopy1));;得到投影实体<br/> (setq m_objcopy2 (m_ShadowToXY m_objcopy2));;得到投影实体</p><p> <br/> (setq m_jdtab1 (vla-intersectwith m_objcopy1 m_objcopy2 acExtendnone));;得到交点集<br/> <br/> (if (> (vlax-safearray-get-u-bound (vlax-variant-value m_jdtab1) 1) 1);;判断有无交点<br/> (progn<br/>(setq m_jdtab1 (vlax-safearray->list (vlax-variant-value m_jdtab1)));;safearray数组转换为list表<br/>(setq i 0)<br/>(repeat (/ (length m_jdtab1) 3)<br/> (setq m_jd (list (nth i m_jdtab1) (nth (+ 1 i) m_jdtab1) (nth (+ 2 i) m_jdtab1)));;取得一个交点<br/> (setq m_jdtab (cons m_jd m_jdtab));;构造交点表((第一个交点) (第二个交点)。。。)<br/> (setq i (+ 3 i))<br/>)<br/> )<br/> (princ"\n两曲线无交点!")<br/> )<br/> <br/> (vla-delete m_objcopy1);;删除复制的第一条曲线实体<br/> (vla-delete m_objcopy2);;删除复制的第二条曲线实体<br/> <br/> (setq m_jdtab m_jdtab);;返回交点表,无交点返回nil<br/>)</p><p>(defun m_ShadowToXY(m_obj / m_objname m_pts m_pts1 i)<br/> ;;对曲线实体m_obj创建一个投影至xy平面的曲线实体,即对曲线实体上每个控制点的z坐标值置为0.0<br/> ;;输入曲线实体(vla对象)<br/> ;;返回投影实体(vla对象)<br/> (setq m_objname (vla-get-objectname m_obj));;取得实体的类型名称<br/> (m_princ "\nObjectName:" m_objname)<br/> (cond<br/> ((= "AcDbSpline" m_objname);;样条曲线(Spline)<br/> (setq i 0)<br/> (setq m_pts (vlax-variant-value (vla-get-fitpoints m_obj)));;取得样条曲线的拟合点<br/> (setq m_pts1 (vlax-variant-value (vla-get-controlpoints m_obj)));;取得样条曲线的控制点<br/> (repeat (vla-get-numberoffitpoints m_obj);;循环<br/> (vlax-safearray-put-element m_pts (+ i 2) 0.0);;改变每个拟合点的z值为0.0<br/> (setq i (+ i 3))<br/> )<br/> (vla-put-fitpoints m_obj m_pts);;更改曲线拟合点属性</p><p> (setq i 0)<br/> <br/> (repeat (vla-get-numberofcontrolpoints m_obj);;循环<br/> (vlax-safearray-put-element m_pts1 (+ i 2) 0.0);;改变每个控制点的z值为0.0<br/> (setq i (+ i 3))<br/> )<br/> (vla-put-controlpoints m_obj m_pts1);;更改曲线控制点属性<br/> )<br/> <br/> ((= "AcDb3dPolyline" m_objname);;三维多段线(3dpolyline)<br/> (setq i 0)<br/> (setq m_pts (vlax-variant-value (vla-get-coordinates m_obj)));;取得3维多段线的控制点<br/> (repeat (/ (length (vlax-safearray->list m_pts)) 3)<br/> (vlax-safearray-put-element m_pts (+ i 2) 0.0)<br/> (setq i (+ i 3))<br/> )<br/> (vla-put-coordinates m_obj m_pts)<br/> )<br/> <br/> ((= "AcDbLine" m_objname);;直线(line)<br/> (setq i 0)<br/> (setq m_pts (vlax-variant-value (vla-get-startpoint m_obj)));;取得直线的起点座标<br/> (setq m_pts1 (vlax-variant-value (vla-get-endpoint m_obj)));;取得直线的端点座标<br/> (vlax-safearray-put-element m_pts 2 0.0);;改变起点座标z值为0.0<br/> (vlax-safearray-put-element m_pts1 2 0.0)<br/> (vla-put-startpoint m_obj m_pts)<br/> (vla-put-endpoint m_obj m_pts1)<br/> )</p><p> ((or (= "AcDbCircle" m_objname);;园(circle)<br/> (= "AcDbArc" m_objname);;圆弧(arc)<br/> (= "AcDbEllipse" m_objname);;椭圆及椭圆弧(ellipse)<br/> )<br/> (setq m_pts (vlax-variant-value (vla-get-center m_obj)));;取得中心点座标<br/> (vlax-safearray-put-element m_pts 2 0.0);;改变中心点座标z值为0.0<br/> (vla-put-center m_obj m_pts)<br/> )<br/> <br/> ((or (= "AcDbPolyline" m_objname);;多段线(polyline、lwpolyline)<br/> (= "AcDb2dPolyline" m_objname);;拟合的2维多段线(polyline、lwpolyline)<br/> )<br/> (vla-put-elevation m_obj 0.0);;改变标高值为0.0<br/> )<br/> )<br/> (setq m_obj m_obj)<br/>)</p><p><br/>(defun C:test(/ m_ent1 m_ent2 m_jdtab)<br/> (vl-load-com)<br/> <br/> (setq m_ent1 (car (entsel "\n请选择第一条曲线: ")))<br/> (setq m_ent2 (car (entsel "\n请选择第二条曲线: ")))<br/> (setq ZL-GETINTERS ( m_ent1 m_ent2))<br/> (princ"\n交点表: ")(princ ZL-GETINTERS)<br/> (princ)<br/>)</p><p><strong><font face="Verdana" color="#61b713">Andyhon大侠</font></strong></p><p><strong><font face="Verdana" color="#61b713">帮我看看,测试后也不返回交点列表呀,也不知道哪里出错</font></strong></p> <p>测试通过了。</p><p>(defun c:get_int0( / ent1 ent2 ps)<br/> (setq ent1 (car (entsel "选择第一实体:")))<br/> (setq ent2 (car (entsel "选择第二实体:")))<br/> (print)<br/> (setq ps (obj_int ent1 ent2))<br/>)<br/>;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br/>;功能:返回两个对象的所有交点<br/>;参数: ent1、ent2 均为ename对象<br/>(defun obj_int (ent1 ent2 / ax_ent_1 ax_ent_2 intpoints points i)<br/> (setq ax_ent_1 (vlax-ename->vla-object ent1)<br/> ax_ent_2 (vlax-ename->vla-object ent2)<br/> )<br/> (setq intpoints (vla-intersectwith ax_ent_1 ax_ent_2 acextendnone))<br/> (setq intpoints (vlax-variant-value intpoints))<br/> (setq i 0)<br/> (if (> (vlax-safearray-get-u-bound intpoints 1) 0)<br/> (repeat (/ (+ 1<br/> (- (vlax-safearray-get-u-bound intpoints 1)<br/> (vlax-safearray-get-l-bound intpoints 1)<br/> )<br/> )<br/> 3<br/> )<br/> (setq points (append points (list (list<br/> (vlax-safearray-get-element intpoints i)<br/> (vlax-safearray-get-element intpoints (+ i 1))<br/> (vlax-safearray-get-element intpoints (+ i 2))<br/> )))<br/> )<br/> (setq i (+ 3 i))<br/> )<br/> )<br/> points<br/>)</p> 提供另一种调用做比较<br/><a href="http://www.menziengineering.ch/Downloads/Download.htm">http://www.menziengineering.ch/Downloads/Download.htm</a><br/>VxGetInters - Returns all intersection points between two objects 谢谢<strong><font face="Verdana" color="#61b713">Andyhon</font></strong> <p>(defun m_IntersectWith (m_ent1 m_ent2 / m_obj1 m_obj2 m_objcopy1 m_objcopy2 m_jdtab m_jdtab1 i)<br/> ;;适用对像: Line、Polyline、LWPolyline、Circle、Arc、Ellipse、3dPolyline、Spline<br/> ;;支持求空间虚交点,但Z坐标始终为0.0,要求Z坐标,请用(vlax-curve-getClosestPointToProjection)函数<br/> (setq m_obj1 (vlax-ename->vla-object m_ent1))<br/> (setq m_obj2 (vlax-ename->vla-object m_ent2))</p><p> (setq m_objcopy1 (vla-copy m_obj1));;复制第一条曲线实体<br/> (setq m_objcopy2 (vla-copy m_obj2));;复制第二条曲线实体</p><p> (setq m_objcopy1 (m_ShadowToXY m_objcopy1));;得到投影实体<br/> (setq m_objcopy2 (m_ShadowToXY m_objcopy2));;得到投影实体</p><p><br/> (setq m_jdtab1 (vla-intersectwith m_objcopy1 m_objcopy2 acExtendnone));;得到交点集</p><p> (if (> (vlax-safearray-get-u-bound (vlax-variant-value m_jdtab1) 1) 1);;判断有无交点<br/> (progn<br/>(setq m_jdtab1 (vlax-safearray->list (vlax-variant-value m_jdtab1)));;safearray数组转换为list表<br/>(setq i 0)<br/>(repeat (/ (length m_jdtab1) 3)<br/> (setq m_jd (list (nth i m_jdtab1) (nth (+ 1 i) m_jdtab1) (nth (+ 2 i) m_jdtab1)));;取得一个交点<br/> (setq m_jdtab (cons m_jd m_jdtab));;构造交点表((第一个交点) (第二个交点)。。。)<br/> (setq i (+ 3 i))<br/>)<br/> )<br/> (princ"\n两曲线无交点!")<br/> )</p><p> (vla-delete m_objcopy1);;删除复制的第一条曲线实体<br/> (vla-delete m_objcopy2);;删除复制的第二条曲线实体</p><p> (setq m_jdtab m_jdtab);;返回交点表,无交点返回nil<br/>)</p><p>(defun m_ShadowToXY(m_obj / m_objname m_pts m_pts1 i)<br/> ;;对曲线实体m_obj创建一个投影至xy平面的曲线实体,即对曲线实体上每个控制点的z坐标值置为0.0<br/> ;;输入曲线实体(vla对像)<br/> ;;返回投影实体(vla对像)<br/> (setq m_objname (vla-get-objectname m_obj));;取得实体的类型名称<br/><font color="#ff0033">; (m_princ "\nObjectName:" m_objname)</font></p><p> (cond<br/> ((= "AcDbSpline" m_objname);;样条曲线(Spline)<br/> (setq i 0)<br/> (setq m_pts (vlax-variant-value (vla-get-fitpoints m_obj)));;取得样条曲线的拟合点<br/> (setq m_pts1 (vlax-variant-value (vla-get-controlpoints m_obj)));;取得样条曲线的控制点<br/> (repeat (vla-get-numberoffitpoints m_obj);;循环<br/> (vlax-safearray-put-element m_pts (+ i 2) 0.0);;改变每个拟合点的z值为0.0<br/> (setq i (+ i 3))<br/> )<br/> (vla-put-fitpoints m_obj m_pts);;更改曲线拟合点属性</p><p> (setq i 0)</p><p> (repeat (vla-get-numberofcontrolpoints m_obj);;循环<br/> (vlax-safearray-put-element m_pts1 (+ i 2) 0.0);;改变每个控制点的z值为0.0<br/> (setq i (+ i 3))<br/> )<br/> (vla-put-controlpoints m_obj m_pts1);;更改曲线控制点属性<br/> )</p><p> ((= "AcDb3dPolyline" m_objname);;三维多段线(3dpolyline)<br/> (setq i 0)<br/> (setq m_pts (vlax-variant-value (vla-get-coordinates m_obj)));;取得3维多段线的控制点<br/> (repeat (/ (length (vlax-safearray->list m_pts)) 3)<br/> (vlax-safearray-put-element m_pts (+ i 2) 0.0)<br/> (setq i (+ i 3))<br/> )<br/> (vla-put-coordinates m_obj m_pts)<br/> )</p><p> ((= "AcDbLine" m_objname);;直线(line)<br/> (setq i 0)<br/> (setq m_pts (vlax-variant-value (vla-get-startpoint m_obj)));;取得直线的起点座标<br/> (setq m_pts1 (vlax-variant-value (vla-get-endpoint m_obj)));;取得直线的端点座标<br/> (vlax-safearray-put-element m_pts 2 0.0);;改变起点座标z值为0.0<br/> (vlax-safearray-put-element m_pts1 2 0.0)<br/> (vla-put-startpoint m_obj m_pts)<br/> (vla-put-endpoint m_obj m_pts1)<br/> )</p><p> ((or (= "AcDbCircle" m_objname);;园(circle)<br/> (= "AcDbArc" m_objname);;圆弧(arc)<br/> (= "AcDbEllipse" m_objname);;椭圆及椭圆弧(ellipse)<br/> )<br/> (setq m_pts (vlax-variant-value (vla-get-center m_obj)));;取得中心点座标<br/> (vlax-safearray-put-element m_pts 2 0.0);;改变中心点座标z值为0.0<br/> (vla-put-center m_obj m_pts)<br/> )</p><p> ((or (= "AcDbPolyline" m_objname);;多段线(polyline、lwpolyline)<br/> (= "AcDb2dPolyline" m_objname);;拟合的2维多段线(polyline、lwpolyline)<br/> )<br/> (vla-put-elevation m_obj 0.0);;改变标高值为0.0<br/> )<br/> )<br/> (setq m_obj m_obj)<br/>)</p><p><br/>(defun C:test (/ m_ent1 m_ent2 m_jdtab)<br/><font color="#ff0033">; (vl-load-com)</font></p><p> (setq m_ent1 (car (entsel "\n请选择第一条曲线: ")))<br/> (setq m_ent2 (car (entsel "\n请选择第二条曲线: ")))<br/> (setq ZL-GETINTERS (<font color="#ff0033">m_IntersectWith</font> m_ent1 m_ent2))<br/> (princ"\n交点表: ")(princ ZL-GETINTERS)<br/> (princ)<br/>)</p><p>;Andyhon大侠</p><p>;帮我看看,测试后也不返回交点列表呀,也不知道哪里出错<br/></p><p>;AUTOCAD 2008 測試O.K</p> 向原创作者求助可能要快些有回应<br/>若能附上您调试失败的文件(*.Dwg)更利于厘清症结所在 本帖最后由 作者 于 2010-7-27 13:00:21 编辑 <br /><br /> <p>请问VLX怎么可以实现不相交的两实体延伸所得到的交点?</p>
<p> </p>
<p>呵呵,搞定了</p>
页:
[1]
2