已知点表中的两点,求与此两点共线且距离最远的点
如下图所示,已知点表,PT1,PT2;求与PT1,PT2共线且距离最远的点pt3,pt4 Z版的程序似乎角度要加上(/ pi 2)的判断,下面的程序供楼主参考;; ▓ (lt:pts-onLine <点列表>)
;; [功能] 判断点集是否共线
;; [参数] plst---点列表
;; [返回] 共线->T,反之->nil
(defun lt:pts-onLine (plst / a b)
(setq a (car plst) b (cadr plst))
(not (vl-catch-all-error-p
(vl-catch-all-apply
'mapcar (list '(lambda (x / an)
(setq an (angle a x))
(if (not (or (equal x a 1e-6)
(equal x b 1e-6)
(equal an (angle b x) 1e-6)
(equal an (angle x b) 1e-6)
)
)
(exit)
)
)
(cddr plst)
)
)
)
)
) <p>先做直线pl: PT1-PT2</p><p>用vlax-curve-getClosestPointTo求其余各点到pl的垂足,如果垂足与本点坐标相同/距离为零 则表示点在线pl上</p><p></p> <p>怎么判断是否是线上的点呢?</p> kry发表于2009-6-25 15:43:00static/image/common/back.gif怎么判断是否是线上的点呢?
<p>可通过角度进行判断<br/>(if (equal (- (angle pt1 pt2) (angle pt1 pt4)) 1e-6)<br/> (princ "\npt4 在线上.")<br/> (princ "\npt4 不在线上.")<br/>)</p> <p>角度法,距离法,向量法,辅助线法,垂距法,。。。。。。都可以</p><p>不过建议用while循环替代mapcar,效率更高</p> <p><font color="#000000">(</font><a href="http://www.mjtd.com/object/autolisp/vl-catch-all-error-p.htm" target="_black"><font color="#ff0000">vl-catch-all-error-p</font></a><br/><font color="#ff0000"> (</font><a href="http://www.mjtd.com/object/autolisp/vl-catch-all-apply.htm" target="_black"><font color="#ff0000">vl-catch-all-apply</font></a><br/><font color="#000000"> '<font color="#ff0000">mapcar</font> (</font><a href="http://www.mjtd.com/object/autolisp/list.htm" target="_black"><font color="#000000">list</font></a><font color="#000000"> '(</font><a href="http://www.mjtd.com/object/autolisp/lambda.htm" target="_black"><font color="#000000">lambda</font></a><font color="#000000"> (x / an)<br/> (</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#000000">setq</font></a><font color="#000000"> an (</font><a href="http://www.mjtd.com/object/autolisp/angle.htm" target="_black"><font color="#000000">angle</font></a><font color="#000000"> a x))<br/> (</font><a href="http://www.mjtd.com/object/autolisp/if.htm" target="_black"><font color="#000000">if</font></a><font color="#000000"> (</font><a href="http://www.mjtd.com/object/autolisp/not.htm" target="_black"><font color="#000000">not</font></a><font color="#000000"> (</font><a href="http://www.mjtd.com/object/autolisp/or.htm" target="_black"><font color="#000000">or</font></a><font color="#000000"> (</font><a href="http://www.mjtd.com/object/autolisp/equal.htm" target="_black"><font color="#000000">equal</font></a><font color="#000000"> x a 1e-6)<br/> (</font><a href="http://www.mjtd.com/object/autolisp/equal.htm" target="_black"><font color="#000000">equal</font></a><font color="#000000"> x b 1e-6)<br/> (</font><a href="http://www.mjtd.com/object/autolisp/equal.htm" target="_black"><font color="#000000">equal</font></a><font color="#000000"> an (</font><a href="http://www.mjtd.com/object/autolisp/angle.htm" target="_black"><font color="#000000">angle</font></a><font color="#000000"> b x) 1e-6)<br/> (</font><a href="http://www.mjtd.com/object/autolisp/equal.htm" target="_black"><font color="#000000">equal</font></a><font color="#000000"> an (</font><a href="http://www.mjtd.com/object/autolisp/angle.htm" target="_black"><font color="#000000">angle</font></a><font color="#000000"> x b) 1e-6)<br/> )<br/> )<br/> (</font><a href="http://www.mjtd.com/object/autolisp/exit.htm" target="_black"><font color="#ff3300">exit</font></a><font color="#ff3300">)</font></p><p><font color="#000000">谢无痕老师指教,红色部分的结构确保在指定条件下退出,和while差不多</font></p> 如果是空间点怎么判断
页:
[1]
2