找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1040|回复: 0

[VBA函数]:公路坐标计算-复化辛普森ExcelVBA

[复制链接]
发表于 2008-7-8 20:47:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
**************************************************************
'****************      作者:Leon Zhang         ***************
'****************      Email:z_2_z@sina.com     ***************
'**************************************************************
Function SPS(DKi As Double, CS As Integer, DKa As Double, DKb As Double, Xa As Double, Ya As Double, Ca As Double, Ra As Double, Rb As Double)
'DKi 计算点桩号, CS 参数, DKa 起点桩号, DKb 终点桩号, Xa 起点X坐标, Ya 起点Y坐标, Ca 起点方位角(弧度), Ra 起点半径, Rb 终点半径
Dim X As Double, Y As Double, J As Double '坐标、方位角
Dim N As Integer, k As Integer '精度参数、计算参数
Dim Pa As Double, Pb As Double 'A点曲率、B点曲率
Dim Pi As Double, H As Double '计算点曲率、积分步长
Dim W As Double, Z As Double, V As Double, U As Double '中间变量
Dim DK As Double, P As Double, C As Double '中间曲率、方位角变量
N = 120 '控制计算精度,根据精度和速度均衡考虑。
If Ra = 0 And Rb <> 0 Then
    Pa = 0: Pb = 1 / Rb
ElseIf Rb = 0 And Ra <> 0 Then
    Pb = 0: Pa = 1 / Ra
ElseIf Ra = 0 And Rb = 0 Then
    Pa = 0: Pb = 0
Else
    Pa = 1 / Ra: Pb = 1 / Rb
End If '将半径换算成曲率
Pi = Pa + (Pb - Pa) * Abs(DKi - DKa) / Abs(DKb - DKa) '计算点曲率
J = Ca + 0.5 * (Pa + Pi) * Abs(DKi - DKa) '计算点方位角
H = Abs(DKi - DKa) / N '积分步长
W = 0: Z = 0: U = 0: V = 0
For k = 1 To 2 * N - 1
    DK = DKa + k * H / 2 '桩号
    P = Pa + (Pb - Pa) * Abs(DK - DKa) / Abs(DKb - DKa) '曲率
    C = Ca + 0.5 * (Pa + P) * Abs(DK - DKa) '方位角
If k Mod 2 = 0 Then 'k为双数时
    W = W + Cos(C): Z = Z + Sin(C)
ElseIf k Mod 2 = 1 Then 'k为单数时
    U = U + Cos(C): V = V + Sin(C)
End If
Next k
X = Xa + H / 6 * (Cos(Ca) + 4 * U + 2 * W + Cos(J)) '计算X坐标
Y = Ya + H / 6 * (Sin(Ca) + 4 * V + 2 * Z + Sin(J)) '计算Y坐标
If CS = 1 Then '输出X坐标
    SPS = X
ElseIf CS = 2 Then '输出Y坐标
    SPS = Y
ElseIf CS = 3 Then '输出方位角
    SPS = J
ElseIf CS = 4 Then
    SPS = Format(X, "0.000") & "," & Format(Y, "0.000") '输出X,Y
Else
    MsgBox "输出参数只能是1,2,3,4!1代表X坐标,2是Y坐标,3是方位角,4是X.Y坐标。"
End If
End Function
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-22 05:59 , Processed in 0.168425 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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