Home
Up
 

Basic Trajectory Plotter

Plots the trajectory of a projectile given an initial velocity and elevation angle.

Use the Reset command and Start to compare the effects of different launch angle

Form layout and controls are shown below:

Control Objects Required:

bulletForms: FrmTrajectory, FrmPlotTrajectory
bulletLabels: LblRangeMax, LblHeightMax, LblTime, LblRange, LblX, LblZ
bulletTextboxes: TxtV0, TxtElevation
bulletPicture: PicTrajectory
bulletCommand buttons: CmdStart, CmdReset, CmdExit, CmdClear
bulletTimer

Control Properties:

Control Name Properties and Assigned Default Values
   
   

Typical Code:

Const g = 9.816           'Constants and variables are defined in General
Const DTR = 57.295
Dim Vinitial As Double
Dim Theta As Double
Dim TheTime As Double
Dim Vx As Double
Dim Vz As Double


Private Sub CmdClear_Click()
    'Clear plot area
    FrmPlotTrajectory.Picture1.Cls
End Sub

Private Sub CmdExit_Click()
    End
End Sub

Private Sub CmdReset_Click()
    'Reset all parameters
    LblRangeMax.Caption = ""
    LblHeightMax.Caption = ""
    LblTime.Caption = ""
    LblRange.Caption = ""
    LblX.Caption = ""
    LblZCaption = ""
    TheTime = 0
    Vx = 0
    Vz = 0
    FrmPlotTrajectory.Label1.Visible = False
End Sub


Private Sub CmdStart_Click()
    'Check to see if user has entered a value for Initial velocity and Elevation
    If TxtV0.Text = "" Or TxtElevation.Text = "" Then
        MsgBox "Enter initial velocity and elevation angle", vbCritical
        TxtV0.SetFocus
    Else
        FrmPlotTrajectory.Show
        Vinitial = Val(TxtV0.Text)
        Theta = Val(TxtElevation.Text) / DTR
        Timer1.Enabled = True
        MaxHeight = ((Vinitial ^ 2) * (Sin(Theta) ^ 2)) / (2 * g)
        LblHeightMax.Caption = MaxHeight
        MaxRange = (Vinitial ^ 2 * Sin(2 * Theta)) / g
        LblRangeMax.Caption = MaxRange
    End If
End Sub


Private Sub Timer1_Timer()
    'Increment plot step time
    TheTime = TheTime + Val(TxtPlotDt.Text)
    t = TheTime
    LblTime.Caption = t

    'Perform trajectory calculations
    Vx = Vinitial * Cos(Theta) * t
    LblX.Caption = Vx
    Vz = Vinitial * Sin(Theta) * t - 0.5 * g * t ^ 2
    LblZ.Caption = Vz
    range = Vinitial * Co