乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 43|回复: 2

请各位帮忙查我程序中的一点小错误

[复制链接]

3

主题

6

帖子

1

银币

初来乍到

Rank: 1

铜币
18
发表于 2005-1-24 11:03:00 | 显示全部楼层 |阅读模式
Sub 拟合求视速度1()
Dim n As Integer, vp As Integer, i As Integer, k As Integer
Dim x(1 To 2000) As Double
Dim y(1 To 2000) As Double
Dim da As Double, db As Double, a00 As Double, a01 As Double, a10 As Double
Dim a11 As Double, c0 As Double, c1 As Double, f0 As Double, fn As Double, height As Double
Dim lineObj As AcadLine
Dim textString As String
Dim startPoint(0 To 2) As Double
Dim endPoint(0 To 2) As Double
Dim sset As AcadSelectionSet
Dim pline As AcadLWPolyline
       
ThisDrawing.Utility.Prompt "请选择要拟合的曲线:"
Set sset = ThisDrawing.SelectionSets.Add("SS1")
sset.SelectOnScreen
Set pline = sset.Item(0)
Dim retCoord As Variant
retCoord = pline.Coordinates
pline.Delete
                         i = 1
                         k = 0
                         Do While i                                                  x(i) = retCoord(k)
                                                 y(i) = retCoord(k + 1)
                                                 i = i + 1
                                                 k = k + 3
                         Loop
                 
n = 24
a00 = n
a01 = 0#
For i = 1 To n
                         a01 = a01 + x(i)
Next
a10 = a01
a11 = 0
For i = 1 To n
                         a11 = a11 + x(i) * x(i)
Next
c0 = 0
For i = 1 To n
                         c0 = c0 + y(i)
Next
c1 = 0
For i = 1 To n
                         c1 = c1 + x(i) * y(i)
Next
db = (c0 * a10 - c1 * a00) / (a01 * a10 - a00 * a11)
da = (c0 * a11 - c1 * a01) / (a11 * a00 - a01 * a10)
f0 = da + db * x(1)
fn = da + db * x(n)
startPoint(0) = x(1): startPoint(1) = f0: startPoint(2) = 0#
endPoint(0) = x(n): endPoint(1) = fn: endPoint(2) = 0#
Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
height = 4
vp = 1000 / db
textString = "vp" & "=" & vp
Set blockObj = ThisDrawing.ModelSpace.AddText(textString, endPoint, height)
End Sub
       
       
在给x(i),y(i)赋值时可能“Coordinates”属性搞错了,请各位师父改一下!
回复

使用道具 举报

11

主题

51

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
95
发表于 2005-1-24 11:57:00 | 显示全部楼层
AutoCAD上的帮助文件对坐标值是这么说的:
Coordinates
        Variant (array of doubles); read-write
        The array of points.
        LightweightPolyline objects: The variant is an array of 2D points in OCS.
        Polyline objects: The variant is an array of 3D points: the X and Y coordinates are in OCS;
                                 the Z coordinate is ignored.
        All other objects: The variant is an array of 3D points in WCS.
你定义了Dim pline As AcadLWPolyline,所以pline.Coordinates返回的是两维数据(XY坐标值)的列表。
回复

使用道具 举报

3

主题

6

帖子

1

银币

初来乍到

Rank: 1

铜币
18
发表于 2005-1-25 11:00:00 | 显示全部楼层
谢谢楼上的朋友,已搞定!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-16 20:53 , Processed in 0.427185 second(s), 58 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表