旋转线与毕达哥拉斯公式

时间:2015-01-03 09:47:07

标签: vb.net

我想要旋转一条线,但我不想使用弧度或pi。我创建了一个算法(如果我可以这样称呼它)。我使用带有两个函数和两个定时器的毕达哥拉斯公式来旋转但我认为这是一个错误,因为它在旋转180度后旋转得更快。为什么?这是我的代码:

Public Class Form1
Private Structure poi
    Dim x As Integer
    Dim y As Integer
End Structure

Dim x1 As Integer, y1 As Integer
Dim x As Integer, y As Integer
Dim val As Integer
Dim obxy As poi
Dim moupos As poi
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    Call calcxy(val, 100)

    x = obxy.x
    y = obxy.y
    val = val - 1

    Refresh()
    If -val > 100 Then
        Timer1.Enabled = False
        Timer2.Enabled = True
    End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If Button1.Text = "Start" Then
        Timer1.Enabled = True
        Button1.Text = "Stop"
    Else

        Timer1.Enabled = False
        Timer2.Enabled = False
        Button1.Text = "Start"
    End If

End Sub

Sub calcxy(choice As Integer, radius As Integer)
    Dim yval As Integer
    yval = Math.Sqrt(radius ^ 2 - choice ^ 2)

    obxy.x = moupos.x - choice
    obxy.y = moupos.y - yval
End Sub
Sub recalcxy(choice As Integer, radius As Integer)
    Dim yval As Integer
    yval = Math.Sqrt(radius ^ 2 - choice ^ 2)

    obxy.x = moupos.x - choice
    obxy.y = moupos.y + yval
End Sub

Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
    moupos.x = e.X
    moupos.y = e.Y
End Sub

Private Sub Form1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
    Dim pen As New System.Drawing.Pen(System.Drawing.Color.Black, 1)
    e.Graphics.DrawLine(pen, moupos.x, moupos.y, x, y)
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    val = 100
End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    val = val + 1

    Call recalcxy(val, 100)

    x = obxy.x
    y = obxy.y
    Refresh()
    If val + 1 > 100 Then
        Timer2.Enabled = False
        Timer1.Enabled = True
    End If
End Sub
 End Class

0 个答案:

没有答案