明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1757|回复: 0

两条直线的交点的解法。

[复制链接]
发表于 2008-9-18 14:11:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-9-24 9:33:20 编辑

直线方程

y=kx+b

第一条直线方程

b1=y1-k1*x1

第二条直线方程

b2=y2-k2*x1

交点X,Y一定在第一条和第二条直线上

y=k1*x+b1

y=k2*x+b2

联解

x= (b2-b1)/(k1-k2)

y= k2x+b2

程序如下

Sub mLSs()
  Dim Aa(3) As Variant
  Aa(0) = Array(-10, 3)
  Aa(1) = Array(20, 50)
  Aa(2) = Array(14, 10)
  Aa(3) = Array(-20, 56)
 
  Dim pp(0 To 2) As Double, ppp(0 To 2) As Double


  Dim kkk As Double
  Kab = (Aa(1)(1) - Aa(0)(1)) / (Aa(1)(0) - Aa(0)(0))
  kkk = -1 / Kab
  k1 = (Aa(1)(1) - Aa(0)(1)) / (Aa(1)(0) - Aa(0)(0))
  k2 = (Aa(3)(1) - Aa(2)(1)) / (Aa(3)(0) - Aa(2)(0))
  b1 = Aa(1)(1) - k1 * Aa(1)(0)
  b2 = Aa(3)(1) - k2 * Aa(3)(0)
  x = (b2 - b1) / (k1 - k2)
  y = k2 * x + b2
  Debug.Print x, y
ii = 0
  For jj = 0 To 1
    pp(jj) = Aa(ii)(jj)
    ppp(jj) = Aa(ii + 1)(jj)
  Next jj
  Set ll = ThisDrawing.ModelSpace.AddLine(pp, ppp)
  ll.color = 1
 
ii = 2
  For jj = 0 To 1
    pp(jj) = Aa(ii)(jj)
    ppp(jj) = Aa(ii + 1)(jj)
  Next jj
  Set ll = ThisDrawing.ModelSpace.AddLine(pp, ppp)
  ll.color = 2

End Sub

带功能函数

'Vertical Point

Function VerticalPoint(lineVar As Variant, Delta As Double) As Variant
  Dim Kab, Kac
  Kab = (lineVar(1)(1) - lineVar(0)(1)) / (lineVar(1)(0) - lineVar(0)(0))
  Kac = -1 / Kab
  VerticalPoint = Array(lineVar(1)(0) + Delta / Sqr(1 + Kac ^ 2), lineVar(1)(1) - Delta / Sqr(1 + (1 / Kac) ^ 2), 0) 
End Function

'  Paralle Line
Function yParallelLine(linePoint As Variant, K As Double, Y As Double, Z As Double) 'As Variant
  Dim tempX As Double
  tempX = (Y - linePoint(1)) / K + linePoint(0)
  yParallelLine = Array(tempX, Y, Z)
End Function

' Slope in Xy Plane
Function xySlope(Point1 As Variant, Point2) As Double
  xySlope = (Point2(1) - Point1(1)) / (Point2(0) - Point1(0))
End Function

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-24 06:03 , Processed in 0.147069 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表