1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
Sub plotDigLine(ByVal EG As Object, ByVal EGVertices)
Dim IsIntersect As Boolean
Call CAD.GetBoundingBox(buttomCONC, MinX, MinY, MaxX, MaxY)
Dim vertices(4 * 2 - 1) As Double
vertices(0) = MinX - 300 - 30 vertices(1) = MinY + 100 vertices(2) = MinX - 300 vertices(3) = MinY vertices(4) = MaxX + 300 vertices(5) = MinY vertices(6) = MaxX + 300 + 30 vertices(7) = MinY + 100
Set DL = CAD.AddLWPolyLine(vertices) Call CAD.setLayer(DL, "CAL")
retpt = myFunc.SortPTArray(CAD.IntersectWith(DL, EG, 1, IsIntersect))
If IsIntersect = False Then Exit Sub
vertices(0) = retpt(0, 0) vertices(1) = retpt(0, 1)
vertices(6) = retpt(UBound(retpt, 1), 0) vertices(7) = retpt(UBound(retpt, 1), 1)
DL.Delete
Set DL2 = CAD.AddLWPolyLine(vertices)
DL2.Layer = "CAL"
Dim stoneObj As New clsStone
DLArea = stoneObj.getDLArea(EG, DL2)
With Sheets("中心線") Set rng = .Columns(1).Find(loc) If Not rng Is Nothing Then r = rng.Row .Cells(r, 5) = DLArea End If
End With
End Sub
Function IntersectWith(ByVal PL1, ByVal PL2, ByVal mode As Byte, ByRef IsIntersect As Boolean)
IsIntersect = False
Dim coll As New Collection
If CADVer = "ICAD" Then On Error GoTo ERRORHANDLE Set retpt = PL1.IntersectWith(PL2, mode) For Each it In retpt coll.Add it.x coll.Add it.y coll.Add it.Z Next If coll Is Nothing Then ERRORHANDLE: Else IntersectWith = myFunc.tranColl2Array(coll) IsIntersect = True End If Else
retpt = PL1.IntersectWith(PL2, mode) If UBound(retpt) = -1 Then Else IntersectWith = retpt IsIntersect = True End If
End If
End Function
Function getDLArea(ByVal EG, ByVal DL)
Set PLobj1 = RevisePL(EG) EG.Delete
PL1_X = myFunc.tranColl2Array(getcoll(PLobj1, "X")) PL1_Y = myFunc.tranColl2Array(getcoll(PLobj1, "Y"))
Set PLobj2 = RevisePL(DL) DL.Delete
PL2_X = myFunc.tranColl2Array(getcoll(PLobj2, "X")) PL2_Y = myFunc.tranColl2Array(getcoll(PLobj2, "Y"))
Call defineBorder(PL1_X, PL2_X, BL, BR)
getDLArea = calculateArea_test(PL1_X, PL1_Y, PL2_X, PL2_Y, BL, BR)
End Function
Function RevisePL(ByVal PLobj)
Dim coll As New Collection
co = 3 If TypeName(PLobj) Like "*LWPolyline" Then co = 2
arr = CAD.tranIPoints(PLobj.coordinates)
Debug.Print TypeName(PLobj)
X1 = arr(0) Xn = arr(UBound(arr) - co + 1)
If X1 > Xn Then Set RevisePL = CAD.ReverseLine(ByVal PLobj) Else Set RevisePL = PLobj End If
For i = 0 To UBound(arr) - co Step co
X1 = arr(i) X2 = arr(i + co) If X1 = X2 Then arr(i + co) = arr(i + co) + 0.001
Next
Set RevisePL = CAD.AddLWPolyLine(arr) RevisePL.Layer = PLobj.Layer
End Function
Function calculateArea_test(ByVal PL1_X, ByVal PL1_Y, ByVal PL2_X, ByVal PL2_Y, ByVal BL, ByVal BR)
X_sort = myFunc.BubbleSort_array(myFunc.combineArray(PL1_X, PL2_X))
For i = LBound(X_sort) To UBound(X_sort) - 1 X1 = X_sort(i) X2 = X_sort(i + 1) dx = X2 - X1 If X1 >= BL And X2 <= BR Then Y1f = getYbyX(X1, PL1_X, PL1_Y) Y2f = getYbyX(X1, PL2_X, PL2_Y) dYf = Y1f - Y2f Y1b = getYbyX(X2, PL1_X, PL1_Y) Y2b = getYbyX(X2, PL2_X, PL2_Y) dYb = Y1b - Y2b
If dYf > 0 And dYb < 0 Then X_intersect = getIntersectX(X1, X2, Y1f, Y1b, Y2f, Y2b) dA = dYf * (X_intersect - X1) / 2 ElseIf dYf < 0 And dYb > 0 Then X_intersect = getIntersectX(X1, X2, Y1f, Y1b, Y2f, Y2b) dA = dYb * (X2 - X_intersect) / 2 ElseIf dYf >= 0 And dYb >= 0 Then dA = (dYf + dYb) * dx / 2 Else dA = 0 End If sA = sA + dA End If Next
calculateArea_test = Round(sA / 1000000, 2)
End Function
Function getIntersectX(ByVal X1 As Double, ByVal X2 As Double, _ ByVal Y1f As Double, ByVal Y1b As Double, _ ByVal Y2f As Double, ByVal Y2b As Double)
dx = X2 - X1
y1_slope = (Y1b - Y1f) / dx y2_slope = (Y2b - Y2f) / dx
slope_change = Abs(y1_slope - y2_slope) dY_f = Abs(Y1f - Y2f)
getIntersectX = X1 + dY_f / slope_change
End Function
Function getYbyX(ByVal x As Double, ByVal PL_X, ByVal PL_Y)
For i = LBound(PL_X) To UBound(PL_X) - 1 X1 = PL_X(i) X2 = PL_X(i + 1) Y1 = PL_Y(i) Y2 = PL_Y(i + 1) If X1 = X2 Then X2 = X2 + 0.001: Stop If x >= X1 And x <= X2 Then s1 = x - X1 s2 = X2 - x getYbyX = (s1 * Y2 + s2 * Y1) / (s1 + s2) Exit For End If Next
End Function
|