[求助]请教,有没有直接求点到直线的垂足方法?
本帖最后由 作者 于 2004-10-24 16:57:22 编辑已知一点的坐标和一条直线的端点坐标
想偷懒不计算就能能获得点到直线的垂足坐标
我翻了半天ActiveX与VBA参考手册,找不到相关的方法。
可是cad里面都提供捕捉点到直线的垂足,是不是我没找到而已?
请指教,先谢谢了。 ;;;点到line线的垂足-- chz<BR>(defun c:chz(/ pt s1 pt1-s1 pt2-s1 ang pt-per)<BR> (while(not(setq pt (getpoint"\n点1 : "))))<BR> (while(not(setq s1(entsel"选线 : "))))<BR> (setq pt1-s1 (vlax-curve-getstartPoint (car s1))<BR> pt2-s1 (vlax-curve-getEndPoint (car s1))<BR> ang (vla-get-angle (vlax-ename->vla-object (car s1)))<BR> pt-per (inters pt1-s1 pt2-s1 pt (polar pt (+ ang (/ pi 2)) 1000) nil)<BR> )<BR> (dzb pt-per)<BR> (grvecs (list 1 pt pt-per))<BR> (princ"\n垂足坐标 : ")<BR> (princ pt-per)<BR> (princ)<BR> )
;;;点坐标处加十字线<BR>(defun dzb(pt1 / ll)<BR> (SETQ ll 500)<BR> (grvecs (list 1 (POLAR PT1 0 ll)(POLAR PT1 PI ll)))<BR> (grvecs (list 1 (POLAR PT1 (/ PI 2) ll)(POLAR PT1 (* PI 1.5) ll)))<BR> ) 能不能请高手解释一下,我看不明白。
上面这段代码是VBA么? 获取直线角度a-》做过该点的直线,角度为a+90-》求两直线交点即为垂足 ‘请参考我做的五个子程序
Public Function 三点垂足(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double, X3 As Double, Y3 As Double) As Variant()<BR>'直线的两端点坐标:(X1,Y1)-(X2,Y2),已知点:(X3,Y3)<BR>fw1 = 方位(X1, Y1, X2, Y2)<BR>fw2 = 方位(X1, Y1, X3, Y3)<BR>fw1 = DMS(DEG(fw2) - DEG(fw1))<BR>pj0 = 平距(X1, Y1, X2, Y2)<BR>If pj0 = 0 Then pj0 = 1E-20<BR>Pj1 = 平距(X1, Y1, X3, Y3) * Cos(RAD(fw1))<BR>Var(0) = X1 + (X2 - X1) * Pj1 / pj0<BR>Var(1) = Y1 + (Y2 - Y1) * Pj1 / pj0<BR>三点垂足 = Var<BR>End Function<BR>’求方位角
Function 方位(ddd As Double, ddd0 As Double, ddd1 As Double, ddd2 As Double)<BR>dd = ddd1 - ddd<BR>dd0 = ddd2 - ddd0<BR>If dd0 <> 0 Then<BR> 方位 = DMS(180 - 90 * Sgn(dd0) - Atn(dd / dd0) * 180 / Pi)<BR>Else<BR> 方位 = 0<BR>End If<BR>方位 = 方位 + 360<BR>方位 = 方位 - Int(方位 / 360) * 360<BR>End Function<BR>‘求两点平距
Function 平距(ddd As Double, ddd0 As Double, ddd1 As Double, ddd2 As Double)<BR>平距 = Sqr((ddd - ddd1) ^ 2 + (ddd0 - ddd2) ^ 2)<BR>End Function<BR>
Function DEG(dfmm)
dfm = dfmm<BR>If dfm = 0 Then<BR> DEG = 0<BR>Else<BR> ddd0 = dfm<BR> dfm = Abs(dfm) + 0.000001<BR> 'If Int(dfmm * 100) = 13253 Then MsgBox Int(dfm * 10000)<BR> ddd1 = Int(dfm * 100) - Int(dfm) * 100<BR> ddd2 = Int(dfm * 10000) - Int(dfm * 100) * 100<BR> <BR> ddd = (Int(dfm) + ddd1 / 60 + ddd2 / 3600) * Abs(ddd0) / ddd0<BR> DEG = ddd<BR>End If<BR>End Function
Function DMS(dddd)<BR>ddd = dddd<BR>If ddd = 0 Then<BR> DMS = 0<BR>Else<BR> ddd0 = ddd<BR> ddd = Abs(ddd) + 0.000001<BR> ddd1 = Int(ddd * 100) - Int(ddd) * 100<BR> ddd2 = (ddd * 10000) - Int(ddd) * 10000 - Int(ddd1) * 100 + (ddd1 * 0.6 - Int(ddd1 * 0.6)) * 100 / 0.6<BR> ddd = Int(ddd)<BR> ddd1 = Int(ddd1 * 0.6) / 100<BR> ddd2 = ddd2 * 0.000036<BR>If ddd2 >= 0.006 Then<BR> ddd1 = ddd1 + 0.01<BR> ddd2 = ddd2 - 0.006<BR>End If<BR>If ddd1 >= 0.6 Then<BR> ddd = ddd + 1<BR> ddd1 = ddd1 - 0.6<BR>End If<BR> dfm = (ddd + ddd1 + ddd2) * ddd0 / Abs(ddd0)<BR> DMS = dfm<BR>End If<BR>End Function<BR> Vlisp中用vlax-curve-getClosestPointToProjection最简单
VBA中遗憾好像没有对应的函数,只能用数学方法了。 版主,看了你们推荐的《VBA开发精彩实例教程》里面135-136页介绍了计算点到只显得距离。我用的那种方法求点坐标,可是用语句set linep=thisdrawing.modelspace.addline(pt,linet.startpoint)画初的不是点到直线的垂线而是直接连接了点到直线的起点。我事先应经把捕捉模式设为捕捉垂足了
请问是怎么回事?谢谢! VBA的方法和捕捉模式无关 foxlinshan发表于2004-10-25 10:09:00static/image/common/back.gif能不能请高手解释一下,我看不明白。 上面这段代码是VBA么?
<p>跟我想的一样嘻嘻</p> 编程还得会点数学地........
页:
[1]
2