像这样的函数,有必要读懂它吗?
比如这个函数
该函数作用是创建一个多边形至scnPts结构中,供CreatePolygonRgn()这样的函数使用,还有很多类似的函数,都有涉及数学方面的知识,我一看就头大。我想问,像这样的函数,有必要读懂它吗,还是会用就行?
Private Static Sub CalcRgnPoints()
ReDim scnPts(0 To nPts) As POINTAPI
ReDim rgnPts(0 To nPts) As POINTAPI
Dim offset As Long
Dim angle As Long
Dim theta As Double
Dim radius1 As Long
Dim radius2 As Long
Dim x1 As Long
Dim y1 As Long
Dim xOff As Long
Dim yOff As Long
Dim n As Long
' Some useful constants.
Const Pi# = 3.14159265358979
Const DegToRad# = Pi / 180
' Calc radius based on form size.
x1 = Me.ScaleWidth \ 2
y1 = Me.ScaleHeight \ 2
If x1 > y1 Then
radius1 = y1 * 0.85
Else
radius1 = x1 * 0.85
End If
radius2 = radius1 * 0.5
' Offsets to move origin to upper
' left of window.
xOff = GetSystemMetrics(SM_CXFRAME)
yOff = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION)
' Step through a circle, 10 degrees each
' loop, finding points for polygon.
n = 0
For angle = 0 To 360 Step 10
theta = (angle - offset) * DegToRad
' First region is for drawing.
' One long, one short, one long...
If n Mod 2 Then
scnPts(n).X = x1 + (radius1 * (Sin(theta)))
scnPts(n).Y = y1 + (radius1 * (Cos(theta)))
Else
scnPts(n).X = x1 + (radius2 * (Sin(theta)))
scnPts(n).Y = y1 + (radius2 * (Cos(theta)))
End If
' Second region is for clipping.
' Add offsets.
rgnPts(n).X = scnPts(n).X + xOff
rgnPts(n).Y = scnPts(n).Y + yOff
n = n + 1
Next angle
offset = (offset + 2) Mod 360
End Sub
[解决办法]
先搞明白传入参数和返回值再说
[解决办法]
能看懂就看懂,看不懂就抄上去吧
既成算法的函数最好弄懂了,这样对自己是个提高
[解决办法]
千万不要被一些本来很简单的英语单词或组合吓坏了
其实就是数学+几何+几个英语单词!!
[解决办法]
用到高中学的三角函数。。。
计算圆弧的xy坐标