已知一条直线和直线外一点求垂足??
<p>求助:已知一条线两端点坐标(x1,y1);(x2,y2)和直线外一点(x3,y3),用VBA怎样求出垂足????请那位老兄给个代码!!!</p> <p>提问前先搜索下,有的:</p><p><a href="http://www.mjtd.com/BBS/dispbbs.asp?BoardID=4&replyID=61741&id=27865&skin=0">http://www.mjtd.com/BBS/dispbbs.asp?BoardID=4&replyID=61741&id=27865&skin=0</a></p> 本帖最后由 作者 于 2007-2-9 19:19:43 编辑 <br /><br /> <p>Option Explicit<br/>Public Sub Sample()<br/> Dim objline As AcadLine<br/> Dim lineObj As AcadLine<br/> Dim returnPnt As Variant<br/> Dim sp(0 To 2) As Double<br/> Dim ep(0 To 2) As Double<br/> Dim ang As Double<br/> Dim pt(0 To 2) As Double<br/> Const pi = 3.14159</p><p> '1. 一条线两端点坐标(x1,y1);(x2,y2) :设该直线为objline<br/> ' 如果只有两端点坐标(x1,y1);(x2,y2), 可用 addline 方法画出该直线<br/> ThisDrawing.Utility.GetEntity objline, pt, "Select a line"<br/> ang = objline.Angle<br/> returnPnt = ThisDrawing.Utility.GetPoint(, "Enter a point: ")<br/> sp(0) = returnPnt(0)<br/> sp(1) = returnPnt(1)<br/> sp(2) = returnPnt(2)</p><p> '2.做直线objline的垂线lineObj<br/> ep(0) = sp(0) + Cos(ang + pi / 2)<br/> ep(1) = sp(1) + Sin(ang + pi / 2)<br/> ep(2) = sp(2)<br/> Set lineObj = ThisDrawing.ModelSpace.AddLine(sp, ep)<br/> <br/> '3.找出直线objline和它的垂线lineObj的交点pt<br/> returnPnt = lineObj.IntersectWith(objline, acExtendNone)<br/> If VarType(returnPnt) <> vbEmpty Then<br/> If LBound(returnPnt) <= UBound(returnPnt) Then<br/> pt(0) = returnPnt(0)<br/> pt(1) = returnPnt(1)<br/> pt(2) = returnPnt(2)<br/> End If<br/> End If<br/> returnPnt = lineObj.IntersectWith(objline, acExtendBoth)<br/> If VarType(returnPnt) <> vbEmpty Then<br/> If LBound(returnPnt) <= UBound(returnPnt) Then<br/> pt(0) = returnPnt(0)<br/> pt(1) = returnPnt(1)<br/> pt(2) = returnPnt(2)<br/> End If<br/> End If<br/> lineObj.Delete<br/> <br/> '4.画垂线<br/> Dim obj1 As AcadLine<br/> Set obj1 = ThisDrawing.ModelSpace.AddLine(sp, pt)<br/>End Sub<br/></p> <p></p><p>如何是空间任意直线,你这种就有局限了.你这个公式是解决X-Y平面的.</p><p>我不会3X3矩阵的展开式.你能将下列成</p><p>X=??</p><p>Y= ??</p><p>Z = ??</p><p>形体的旋转变换有绕主轴旋转,或绕空间任一直线旋转等多种形式。若令Rθ表示绕z轴转θ角,Rβ表示绕y轴转β角,Rγ表示绕x轴转γ角,则点P绕x、y、z轴转γ、β、θ角的变换公式是<br/>R=RθRβRγ<br/> | cosθ sinθ 0 |<br/>Rθ= | -sinθ cosθ 0 |<br/> | 0 0 1 |</p><p><br/> | cosβ -sinβ 0 |<br/>Rβ= | 0 1 0 |<br/> | sinβ cosβ 1 |</p><p> | 1 0 0 |<br/>Rγ= | 0 cosγ sinγ |<br/> | 0 -sinγ cosγ |<br/></p><p></p> <p>三楼的函数有问题吧,</p><p>ep(0) = sp(0) + Cos(ang + pi / 2)<br/>ep(1) = sp(1) + Sin(ang + pi / 2)</p><p>这部分没有乘上垂线长度.<br/></p>
页:
[1]