|
楼主 |
发表于 2014-10-3 23:07
|
显示全部楼层
旋转与对称分写函数代码:
- Option Explicit
- Public Function XuanZhuan(rng As Range, jd%, Optional ro% = 0, Optional col% = 0)
- If jd <> 90 And jd <> 180 And jd <> 270 Then XuanZhuan = "旋转角度取值应为:90、180、270度!": Exit Function
- Dim arr, h%, l%, i%, j%, hl%, x!, y!, hd#, h1%, l1%, m%, k%
- If rng.Count = 1 Then XuanZhuan = rng.Value: Exit Function
- arr = rng.Value '原始数据数组
- h = UBound(arr): l = UBound(arr, 2)
- If jd = 90 Then jd = 270 Else If jd = 270 Then jd = 90 '工作表其实是第四象限,相当于转为第一象限
- hl = WorksheetFunction.Max(h, l): hd = jd / 180 * Application.Pi()
- ReDim brr(-hl To hl, -hl To hl) '过渡数组
- For i = 1 To h '对应y
- For j = 1 To l '对应x
- x = j * Cos(hd) - i * Sin(hd)
- y = j * Sin(hd) + i * Cos(hd)
- brr(y, x) = arr(i, j)
- Next j
- Next i
- h1 = 0: l1 = 0
- For i = -hl To hl '非空列
- m = 0
- For j = -hl To hl
- If brr(i, j) <> "" Then m = m + 1
- Next j
- If l1 < m Then l1 = m
- Next i
- If l1 = l Then h1 = h Else h1 = l '非空行
- ReDim crr(1 To h1, 1 To l1)
- m = 0: k = 1
- For i = -hl To hl '剔除brr中的空值,保留非空值位置
- For j = -hl To hl
- If brr(i, j) <> "" Then m = m + 1: crr(k, m) = brr(i, j)
- Next j
- If m <> 0 Then k = k + 1
- m = 0
- Next i
- If ro = 0 Or col = 0 Then XuanZhuan = crr Else XuanZhuan = crr(ro, col)
- End Function
- Public Function DuiChen(rng As Range, jd%, Optional ro% = 0, Optional col% = 0)
- If jd <> 45 And jd <> 90 And jd <> 135 And jd <> 180 Then DuiChen = "对称轴角度取值应为:45、90、135、180度!": Exit Function
- Dim arr, h%, l%, i%, j%, hl%, x!, y!, hd#, h1%, l1%, m%, k%
- If rng.Count = 1 Then DuiChen = rng.Value: Exit Function
- arr = rng.Value '原始数据数组
- h = UBound(arr): l = UBound(arr, 2)
- If jd = 45 Then jd = 135 Else If jd = 135 Then jd = 45 '工作表其实是第四象限,相当于转为第一象限
- hl = WorksheetFunction.Max(h, l): hd = jd / 180 * Application.Pi()
- ReDim brr(-hl To hl, -hl To hl) '过渡数组
- For i = 1 To h '对应y
- For j = 1 To l '对应x
- x = j * Cos(hd * 2) + i * Sin(hd * 2)
- y = j * Sin(hd * 2) - i * Cos(hd * 2)
- brr(y, x) = arr(i, j)
- Next j
- Next i
- h1 = 0: l1 = 0
- For i = -hl To hl '非空列
- m = 0
- For j = -hl To hl
- If brr(i, j) <> "" Then m = m + 1
- Next j
- If l1 < m Then l1 = m
- Next i
- If l1 = l Then h1 = h Else h1 = l '非空行
- ReDim crr(1 To h1, 1 To l1)
- m = 0: k = 1
- For i = -hl To hl '剔除brr中的空值,保留非空值位置
- For j = -hl To hl
- If brr(i, j) <> "" Then m = m + 1: crr(k, m) = brr(i, j)
- Next j
- If m <> 0 Then k = k + 1
- m = 0
- Next i
- If ro = 0 Or col = 0 Then DuiChen = crr Else DuiChen = crr(ro, col)
- End Function
复制代码
|
|