请问如何过一点作一条直线的垂线
如题,如何过一个点作一条直线的垂线。谢谢。 本帖最后由 cabinsummer 于 2011-9-23 22:02 编辑程序如下。但该程序没有判断是否选取了直线和点,也就是说,没有错误处理
(defun c:per(/ el sp dp ep dsp dep dse al pp spx spy dpx dpy epx epy ppx ppy)
(prompt "请选择直线:")
(setq el (car (entsel)));;;直线图元名
(setq sp (cdr (assoc 10 (entget el))));;;直线起点
(setq dp (cdr (assoc 11 (entget el))));;;直线终点
(prompt "请选择点:")
(setq ep (getpoint));;;已知点选取
(setq dsp (distance ep sp));;;直线起点到选取点距离
(setq dep (distance ep dp));;;直线终点到选取点距离
(setq dse (distance sp dp));;;直线长度
(if
(or
(= dsp (+ dep dse))
(= dep (+ dsp dse))
(= dse (+ dsp dep))
);;;判断
(princ "\n点位于直线上")
(progn
(setq spx (car sp) spy (cadr sp));;;直线起点xy坐标
(setq dpx (car dp) dpy (cadr dp));;;直线终点xy坐标
(setq al (- (angle (list spx spy)(list dpx dpy))(/ pi 2.0)));;;直线的垂线方向角
(if (< al 0.0)(setq al (+ al (* pi 2.0))));;;如果垂线方向角<0则+360度
(setq pp (polar ep al 10));;;垂线上的某一点
(setq epx (car ep) epy (cadr ep));;;选取点的xy坐标
(setq ppx (car pp) ppy (cadr pp));;;垂线上某一点的xy坐标
(setq pp (append (inters (list spx spy)(list dpx dpy)(list epx epy)(list ppx ppy) nil) (list 0.0)));;;求垂足
(entmake (list '(0 . "LINE")(cons 10 ep)(cons 11 pp)));;;画选取点和垂足点之间的线,即垂线
)
)
(princ)
)
public static Point3d GetPrjPoint(Point3d pt, Point3d start, Point3d end)
{
Line3d l = new Line3d(start, end);
return l.GetClosestPointTo(pt).Point;
} 本帖最后由 cabinsummer 于 2011-9-23 22:04 编辑
(defun c:per(/ el obj cp ep)
(if (and (setq el (car (entsel "\n请选择直线:")))(= (cdr (assoc 0 (entget el))) "LINE"))
(progn
(setq obj (vlax-ename->vla-object el))
(if (setq ep (getpoint "\n请选择点:"))
(progn
(setq cp (vlax-curve-getClosestPointTo obj ep T))
(if (/= (distance ep cp) 0.0)
(entmake (list '(0 . "LINE")(cons 10 ep)(cons 11 cp)))
(princ "\n点位于直线上,三维无解")
)
)
(princ "\n未选取点")
)
)
(princ "\n未选取直线")
)
(princ)
) 新手学习了!! fsxm 发表于 2011-9-23 20:53 static/image/common/back.gif
如果直线外的那个点向直线作垂线时,垂足在延长线上,那么取最近点就不对了!!!
页:
[1]