兰州人 发表于 2008-9-18 14:11:00

两条直线的交点的解法。

本帖最后由 作者 于 2008-9-24 9:33:20 编辑 <br /><br /> <p>直线方程</p><p>y=kx+b</p><p>第一条直线方程</p><p>b1=y1-k1*x1</p><p>第二条直线方程</p><p>b2=y2-k2*x1</p><p>交点X,Y一定在第一条和第二条直线上</p><p>y=k1*x+b1</p><p>y=k2*x+b2</p><p>联解</p><p>x= (b2-b1)/(k1-k2)</p><p>y= k2x+b2</p><p>程序如下</p><p>Sub mLSs()<br/>&nbsp; Dim Aa(3) As Variant<br/>&nbsp; Aa(0) = Array(-10, 3)<br/>&nbsp; Aa(1) = Array(20, 50)<br/>&nbsp; Aa(2) = Array(14, 10)<br/>&nbsp; Aa(3) = Array(-20, 56)<br/>&nbsp; <br/>&nbsp; Dim pp(0 To 2) As Double, ppp(0 To 2) As Double</p><p><br/>&nbsp; Dim kkk As Double<br/>&nbsp; Kab = (Aa(1)(1) - Aa(0)(1)) / (Aa(1)(0) - Aa(0)(0))<br/>&nbsp; kkk = -1 / Kab<br/>&nbsp; k1 = (Aa(1)(1) - Aa(0)(1)) / (Aa(1)(0) - Aa(0)(0))<br/>&nbsp; k2 = (Aa(3)(1) - Aa(2)(1)) / (Aa(3)(0) - Aa(2)(0))<br/>&nbsp; b1 = Aa(1)(1) - k1 * Aa(1)(0)<br/>&nbsp; b2 = Aa(3)(1) - k2 * Aa(3)(0)<br/>&nbsp; x = (b2 - b1) / (k1 - k2)<br/>&nbsp; y = k2 * x + b2<br/>&nbsp; Debug.Print x, y<br/>ii = 0<br/>&nbsp; For jj = 0 To 1<br/>&nbsp;&nbsp;&nbsp; pp(jj) = Aa(ii)(jj)<br/>&nbsp;&nbsp;&nbsp; ppp(jj) = Aa(ii + 1)(jj)<br/>&nbsp; Next jj<br/>&nbsp; Set ll = ThisDrawing.ModelSpace.AddLine(pp, ppp)<br/>&nbsp; ll.color = 1<br/>&nbsp; <br/>ii = 2<br/>&nbsp; For jj = 0 To 1<br/>&nbsp;&nbsp;&nbsp; pp(jj) = Aa(ii)(jj)<br/>&nbsp;&nbsp;&nbsp; ppp(jj) = Aa(ii + 1)(jj)<br/>&nbsp; Next jj<br/>&nbsp; Set ll = ThisDrawing.ModelSpace.AddLine(pp, ppp)<br/>&nbsp; ll.color = 2</p><p>End Sub<br/></p><p></p><p>带功能函数</p><p>'Vertical Point</p><p>Function VerticalPoint(lineVar As Variant, Delta As Double) As Variant<br/>&nbsp; Dim Kab, Kac<br/>&nbsp; Kab = (lineVar(1)(1) - lineVar(0)(1)) / (lineVar(1)(0) - lineVar(0)(0))<br/>&nbsp; Kac = -1 / Kab<br/>&nbsp; VerticalPoint = Array(lineVar(1)(0) + Delta / Sqr(1 + Kac ^ 2), lineVar(1)(1) - Delta / Sqr(1 + (1 / Kac) ^ 2), 0)&nbsp; <br/>End Function</p><p>'&nbsp; Paralle Line<br/>Function yParallelLine(linePoint As Variant, K As Double, Y As Double, Z As Double) 'As Variant<br/>&nbsp; Dim tempX As Double<br/>&nbsp; tempX = (Y - linePoint(1)) / K + linePoint(0)<br/>&nbsp; yParallelLine = Array(tempX, Y, Z)<br/>End Function</p><p>' Slope in Xy Plane<br/>Function xySlope(Point1 As Variant, Point2) As Double<br/>&nbsp; xySlope = (Point2(1) - Point1(1)) / (Point2(0) - Point1(0))<br/>End Function<br/></p>
页: [1]
查看完整版本: 两条直线的交点的解法。