明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1507|回复: 2

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

[复制链接]
发表于 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 <= 24

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”属性搞错了,请各位师父改一下!

发表于 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坐标值)的列表。
 楼主| 发表于 2005-1-25 11:00:00 | 显示全部楼层
谢谢楼上的朋友,已搞定!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-27 21:06 , Processed in 0.159523 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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