|
|
本帖最后由 Capt.Murasa 于 2014-8-25 19:20 编辑
場函數F(x,y,t):
i分量: Cos(1.5 * y) * Sin(3 * t)
j分量: Sin(1.5 * x) * Cos(3 * t)
抱歉渣片質
上次也發過了圖片...這次就加入了時間參數..
另外, 為了顯示,箭矢實際長度被統一
哂技能向,除此之外,無其他用意.JPG)
最近的新人令我發現..........我真的是技窮了
完整程式碼如下:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Math
'除form之外,還外加了1個timer,label
Form1
Dim p1 As PointF
Dim p2 As PointF
Dim x As Double
Dim y As Double
Public time As Double
Dim pen1 As New Pen(Color.Red, 1)
Function Xdirect(Optional ByVal x As Double = 0, Optional ByVal y As Double = 0, Optional ByVal t As Double = 0) As Double
'此函式計算 i 分量值
Dim s As Double
s = Cos(1.5 * y) * Sin(3 * t) ' i 分量
Return s
End Function
Function Ydirect(Optional ByVal x As Double = 0, Optional ByVal y As Double = 0, Optional ByVal t As Double = 0) As Double
'此函式計算 j 分量值
Dim s As Double
s = Sin(1.5 * x) * Cos(3 * t) ' j 分量
Return s
End Function
Sub Adjusting(ByVal a As Double, ByVal b As Double) '此副程式用作 調整箭矢長度
Dim m As Double
If (a = 0 And b = 0) Then
y = 0 : x = 0
Else
m = Sqrt((a ^ 2) + (b ^ 2))
x = 0.2 * a / m
y = 0.2 * b / m
End If
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim myArrow As New AdjustableArrowCap(3, 6) '
Dim customArrow As CustomLineCap = myArrow
Dim capPen As New Pen(Color.Black) '
capPen.CustomStartCap = myArrow
e.Graphics.DrawLine(pen1, 0, 450, 970, 450)
e.Graphics.DrawLine(pen1, 450, 0, 450, 970)
For i As Double = -5 To 5 Step 0.3
For j As Double = -5 To 5 Step 0.3
Adjusting(Xdirect(i, j, time), Ydirect(i, j, time))
p1 = New PointF((i * 100 + 450), (450 - j * 100))
p2 = New PointF((i + x) * 100 + 450, 450 - (j + y) * 100)
e.Graphics.DrawLine(capPen, p2, p1)
Next
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
time += 0.05
Label1.Text = time '顯示參數t值
Me.Refresh()
End Sub
End Class
|
|