- 积分
- 2108
- 明经币
- 个
- 注册时间
- 2002-9-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2015-10-10 11:37:39
|
显示全部楼层
Public Function 拟合(ByVal entId As ObjectId) As Spline
Dim db As Database = HostApplicationServices.WorkingDatabase
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim ent As Spline = trans.GetObject(entId, OpenMode.ForWrite)
ent.Type = SplineType.FitPoints
trans.Commit()
Return ent
End Using
End Function
Public Function 样条曲线方向(ByVal entSpline As Spline) As Integer '逆时针返回1,顺时针返回-1,其它情况返回0.
If entSpline.Closed = False Then Return 0
entSpline = 拟合(entSpline.ObjectId)
Dim W, S, N As Integer
Dim DistW, DistS, DistN As Double
Dim pointW, pointS, pointN As Point3d
For I As Integer = 0 To entSpline.GetDistanceAtParameter(entSpline.Area) Step entSpline.GetDistanceAtParameter(entSpline.Area) / 360
If I = 0 Then pointW = entSpline.GetPointAtDist(I) : pointS = pointW : pointN = pointW
If pointW.X > entSpline.GetPointAtDist(I).X Then pointW = entSpline.GetPointAtDist(I)
If pointS.Y > entSpline.GetPointAtDist(I).Y Then pointS = entSpline.GetPointAtDist(I)
If pointN.Y < entSpline.GetPointAtDist(I).Y Then pointN = entSpline.GetPointAtDist(I)
Next
W = 0 : S = 0 : N = 0
For I As Integer = 0 To entSpline.NumFitPoints - 1
If I = 0 Then DistW = pointW.DistanceTo(entSpline.GetFitPointAt(I)) : DistS = DistW : DistN = DistW
If DistW > pointW.DistanceTo(entSpline.GetFitPointAt(I)) Then DistW = pointW.DistanceTo(entSpline.GetFitPointAt(I)) : W = I
If DistS > pointS.DistanceTo(entSpline.GetFitPointAt(I)) Then DistS = pointS.DistanceTo(entSpline.GetFitPointAt(I)) : S = I
If DistN > pointN.DistanceTo(entSpline.GetFitPointAt(I)) Then DistN = pointN.DistanceTo(entSpline.GetFitPointAt(I)) : N = I
Next
Return IIf(S < N, IIf((W <= S And W <= N) Or (W >= S And W >= N), 1, -1), IIf(W < S And W > N, 1, -1))
End Function |
|