两条直线的交点的解法。
本帖最后由 作者 于 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/> Dim Aa(3) As Variant<br/> Aa(0) = Array(-10, 3)<br/> Aa(1) = Array(20, 50)<br/> Aa(2) = Array(14, 10)<br/> Aa(3) = Array(-20, 56)<br/> <br/> Dim pp(0 To 2) As Double, ppp(0 To 2) As Double</p><p><br/> Dim kkk As Double<br/> Kab = (Aa(1)(1) - Aa(0)(1)) / (Aa(1)(0) - Aa(0)(0))<br/> kkk = -1 / Kab<br/> k1 = (Aa(1)(1) - Aa(0)(1)) / (Aa(1)(0) - Aa(0)(0))<br/> k2 = (Aa(3)(1) - Aa(2)(1)) / (Aa(3)(0) - Aa(2)(0))<br/> b1 = Aa(1)(1) - k1 * Aa(1)(0)<br/> b2 = Aa(3)(1) - k2 * Aa(3)(0)<br/> x = (b2 - b1) / (k1 - k2)<br/> y = k2 * x + b2<br/> Debug.Print x, y<br/>ii = 0<br/> For jj = 0 To 1<br/> pp(jj) = Aa(ii)(jj)<br/> ppp(jj) = Aa(ii + 1)(jj)<br/> Next jj<br/> Set ll = ThisDrawing.ModelSpace.AddLine(pp, ppp)<br/> ll.color = 1<br/> <br/>ii = 2<br/> For jj = 0 To 1<br/> pp(jj) = Aa(ii)(jj)<br/> ppp(jj) = Aa(ii + 1)(jj)<br/> Next jj<br/> Set ll = ThisDrawing.ModelSpace.AddLine(pp, ppp)<br/> 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/> Dim Kab, Kac<br/> Kab = (lineVar(1)(1) - lineVar(0)(1)) / (lineVar(1)(0) - lineVar(0)(0))<br/> Kac = -1 / Kab<br/> VerticalPoint = Array(lineVar(1)(0) + Delta / Sqr(1 + Kac ^ 2), lineVar(1)(1) - Delta / Sqr(1 + (1 / Kac) ^ 2), 0) <br/>End Function</p><p>' Paralle Line<br/>Function yParallelLine(linePoint As Variant, K As Double, Y As Double, Z As Double) 'As Variant<br/> Dim tempX As Double<br/> tempX = (Y - linePoint(1)) / K + linePoint(0)<br/> yParallelLine = Array(tempX, Y, Z)<br/>End Function</p><p>' Slope in Xy Plane<br/>Function xySlope(Point1 As Variant, Point2) As Double<br/> xySlope = (Point2(1) - Point1(1)) / (Point2(0) - Point1(0))<br/>End Function<br/></p>
页:
[1]