文章预览
学习Excel技术,关注微信公众号: excelperfect 标签: VBA 使用三角法,可以计算物体撞击闭合矩形区域内壁时的路径。 代码如下: Dim x!(1 To 3), y!(1 To 3), deg, rad!, tg!, res(), rig As Boolean, _ down As Boolean, tp, bt, lf, rg, fx, fy Const maxx = 20, maxy = 10 Sub Main() ReDim tp(1 To 4), bt(1 To 4), lf(1 To 4), rg(1 To 4), res(1 To 2) Dim i%, keep(1 To 2), s As Series, co As Shape, ns% tp(1) = 0: tp(2) = maxy: tp(3) = maxx: tp(4) = maxy ' 上边线 bt(1) = 0: bt(2) = 0: bt(3) = maxx: bt(4) = 0 ' 下边线 lf(1) = 0: lf(2) = 0: lf(3) = 0: lf(4) = maxy ' 左边线 rg(1) = maxx: rg(2) = 0: rg(3) = maxx: rg(4) = maxy ' 右边线 rig = True ns = 23 ReDim fx(1 To ns), fy(1 To ns) down = False x(1) = 1: y(1) = 3 ' 起始点 res(1)
………………………………