VERSION 5.00 Begin VB.Form frmMain Caption = "Image Demo" ClientHeight = 10995 ClientLeft = 60 ClientTop = 345 ClientWidth = 10920 LinkTopic = "Form1" ScaleHeight = 10995 ScaleWidth = 10920 StartUpPosition = 3 'Windows Default Begin VB.TextBox txtDistance Height = 285 Left = 7800 TabIndex = 19 Text = "-1" Top = 9060 Width = 615 End Begin VB.TextBox txtLaserAngleZ Height = 315 Left = 7800 TabIndex = 17 Text = "-1" Top = 7980 Width = 615 End Begin VB.TextBox txtScanAngleZ Height = 285 Left = 7800 TabIndex = 16 Text = "-1" Top = 8700 Width = 615 End Begin VB.TextBox txtScanAngleX Height = 285 Left = 7800 TabIndex = 14 Text = "-1" Top = 8340 Width = 615 End Begin VB.TextBox txtDistBetween Height = 285 Left = 1380 TabIndex = 10 Text = "54.5" Top = 8340 Width = 615 End Begin VB.TextBox txtLaserAngleX Height = 315 Left = 7800 TabIndex = 9 Text = "-1" Top = 7620 Width = 615 End Begin VB.TextBox txtFOVLaser Height = 285 Left = 1380 TabIndex = 7 Text = "180" Top = 7980 Width = 615 End Begin VB.CommandButton cmdStep Caption = "Step" Height = 315 Left = 9360 TabIndex = 3 Top = 60 Width = 495 End Begin VB.CommandButton cmdStart Caption = "Start" Height = 315 Left = 8820 TabIndex = 0 Top = 60 Width = 495 End Begin VB.TextBox txtFOVCamera Height = 315 Left = 1380 TabIndex = 1 Text = "60" Top = 7620 Width = 615 End Begin VB.Timer tmrMain Left = 8100 Top = 60 End Begin VB.Label Label16 Caption = "o" Height = 195 Left = 2040 TabIndex = 26 Top = 7920 Width = 255 End Begin VB.Label Label14 Caption = "o" Height = 195 Left = 8460 TabIndex = 24 Top = 7920 Width = 255 End Begin VB.Label Label13 Caption = "o" Height = 195 Left = 8460 TabIndex = 23 Top = 8280 Width = 255 End Begin VB.Label Label12 Caption = "o" Height = 195 Left = 8460 TabIndex = 22 Top = 8640 Width = 255 End Begin VB.Label Label11 Caption = """" Height = 195 Left = 8460 TabIndex = 21 Top = 9120 Width = 255 End Begin VB.Label lbldistance Caption = "Distance" Height = 195 Left = 6720 TabIndex = 20 Top = 9120 Width = 975 End Begin VB.Label Label10 Caption = "Laser Angle Z" Height = 195 Left = 6720 TabIndex = 18 Top = 8040 Width = 1095 End Begin VB.Label Label8 Caption = "Scan Angle Z" Height = 195 Left = 6720 TabIndex = 15 Top = 8760 Width = 975 End Begin VB.Label Label7 Caption = "Scan Angle X" Height = 195 Left = 6720 TabIndex = 13 Top = 8400 Width = 975 End Begin VB.Label Label6 Caption = """" Height = 195 Left = 2040 TabIndex = 12 Top = 8400 Width = 255 End Begin VB.Label Label5 Caption = "Dist Between" Height = 195 Left = 300 TabIndex = 11 Top = 8340 Width = 1035 End Begin VB.Shape testdot FillColor = &H000000FF& FillStyle = 0 'Solid Height = 195 Index = 3 Left = 8160 Shape = 3 'Circle Tag = "130" Top = 3720 Width = 195 End Begin VB.Shape testdot FillColor = &H000000FF& FillStyle = 0 'Solid Height = 195 Index = 1 Left = 1440 Shape = 3 'Circle Tag = "97.69" Top = 3900 Width = 195 End Begin VB.Shape testdot FillColor = &H000000FF& FillStyle = 0 'Solid Height = 195 Index = 2 Left = 7740 Shape = 3 'Circle Tag = "125" Top = 3780 Width = 195 End Begin VB.Shape testdot FillColor = &H000000FF& FillStyle = 0 'Solid Height = 195 Index = 0 Left = 3420 Shape = 3 'Circle Tag = "125.92" Top = 3900 Width = 195 End Begin VB.Label Label4 Caption = "Laser Angle X" Height = 195 Left = 6720 TabIndex = 8 Top = 7680 Width = 1095 End Begin VB.Label Label3 Caption = "Laser FOV" Height = 195 Left = 300 TabIndex = 6 Top = 7980 Width = 1035 End Begin VB.Line Line14 BorderColor = &H0000FF00& X1 = 5100 X2 = 4860 Y1 = 9240 Y2 = 9420 End Begin VB.Line Line11 BorderColor = &H0000FF00& BorderStyle = 3 'Dot X1 = 2400 X2 = 5100 Y1 = 3960 Y2 = 9540 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "A" ForeColor = &H0000FF00& Height = 255 Left = 4800 TabIndex = 5 Top = 9000 Width = 255 End Begin VB.Line Line10 BorderColor = &H0000FF00& X1 = 5100 X2 = 5340 Y1 = 9240 Y2 = 9420 End Begin VB.Label Label1 BackStyle = 0 'Transparent Caption = "FOV" ForeColor = &H0000FF00& Height = 255 Left = 4920 TabIndex = 4 Top = 9660 Width = 375 End Begin VB.Line Line9 BorderColor = &H0000FF00& X1 = 5100 X2 = 10140 Y1 = 9540 Y2 = 3660 End Begin VB.Line Line8 BorderColor = &H0000FF00& X1 = 60 X2 = 5100 Y1 = 3660 Y2 = 9600 End Begin VB.Line Line13 BorderColor = &H00FF0000& X1 = 5100 X2 = 5100 Y1 = 7740 Y2 = 240 End Begin VB.Line Line15 BorderColor = &H00FF0000& X1 = 10080 X2 = 120 Y1 = 3960 Y2 = 3960 End Begin VB.Line Line12 BorderColor = &H00FF0000& X1 = 9900 X2 = 120 Y1 = 7560 Y2 = 240 End Begin VB.Line Line6 BorderColor = &H00FF0000& X1 = 300 X2 = 10140 Y1 = 7560 Y2 = 180 End Begin VB.Line Line3 BorderColor = &H00FF0000& X1 = 60 X2 = 720 Y1 = 360 Y2 = 360 End Begin VB.Line Line2 BorderColor = &H00FF0000& X1 = 300 X2 = 300 Y1 = 60 Y2 = 780 End Begin VB.Line Line1 BorderColor = &H000000FF& BorderStyle = 0 'Transparent Index = 0 X1 = 5100 X2 = 1620 Y1 = 9600 Y2 = 5100 End Begin VB.Shape shpCurrent FillColor = &H0000FFFF& FillStyle = 0 'Solid Height = 135 Left = 1200 Shape = 4 'Rounded Rectangle Top = 1320 Width = 135 End Begin VB.Label Label9 Caption = "Camera FOV" Height = 195 Left = 300 TabIndex = 2 Top = 7680 Width = 975 End Begin VB.Image imgInput Height = 7200 Left = 300 Picture = "frmImageDemo.frx":0000 Top = 360 Width = 9600 End Begin VB.Label Label17 Caption = "o" Height = 195 Left = 2040 TabIndex = 27 Top = 7560 Width = 255 End Begin VB.Label Label15 Caption = "o" Height = 195 Left = 8460 TabIndex = 25 Top = 7560 Width = 255 End End Attribute VB_Name = "frmMain" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim cur_laser As Integer Dim step_x As Integer Dim step_y As Integer Private Sub Form_Load() Dim dot As Shape tmrMain.Enabled = False tmrMain.Interval = 1 shpCurrent.Left = imgInput.Left shpCurrent.Top = imgInput.Top step_x = shpCurrent.Width step_y = shpCurrent.Height Dim step As Double step = txtFOVLaser.Text / testdot.Count For Each dot In testdot dot.Visible = False Next testdot(0).Visible = True txtLaserAngleX.Text = testdot(0).Tag End Sub Private Sub cmdStart_Click() If (tmrMain.Enabled = True) Then tmrMain.Enabled = False cmdStart.Caption = "Start" Else tmrMain.Enabled = True cmdStart.Caption = "Stop" End If End Sub Private Sub cmdStep_Click() '1) move dot col '2) move dot row '3) switch laser If (shpCurrent.Left + shpCurrent.Width + step_x > imgInput.Left + imgInput.Width) Then ' overrun right shpCurrent.Left = imgInput.Left If (shpCurrent.Top + shpCurrent.Height + step_y > imgInput.Top + imgInput.Height) Then ' overrun right shpCurrent.Top = imgInput.Top testdot(cur_laser).Visible = False ' hide last If (cur_laser = testdot.ubound) Then cur_laser = testdot.LBound Else cur_laser = cur_laser + 1 End If testdot(cur_laser).Visible = True txtLaserAngleX.Text = testdot(cur_laser).Tag Else shpCurrent.Top = shpCurrent.Top + step_y End If Else shpCurrent.Left = shpCurrent.Left + step_x End If Dim cameraOffsetX As Double cameraOffsetX = 90 - txtFOVCamera.Text / 2 txtScanAngleX.Text = cameraOffsetX + ((shpCurrent.Left / (imgInput.Left + imgInput.Width)) * txtFOVCamera.Text) txtScanAngleZ.Text = (shpCurrent.Top / (imgInput.Top + imgInput.Height)) * txtFOVCamera.Text ' find intersect If (testdot(cur_laser).Left >= shpCurrent.Left And testdot(cur_laser).Left <= shpCurrent.Left + shpCurrent.Width) Then If (testdot(cur_laser).Top >= shpCurrent.Top And testdot(cur_laser).Top <= shpCurrent.Top + shpCurrent.Height) Then ' intersected Dim angle_A As Double, dist_b As Double If (txtLaserAngleX.Text >= 90 And txtLaserAngleX.Text < 180 And txtScanAngleX.Text >= 0 And txtScanAngleX.Text < 90) Then angle_A = 180 - txtLaserAngleX.Text dist_b = (txtDistBetween.Text * Sin(DtoR(txtScanAngleX.Text))) / Sin(DtoR(180 - angle_A - txtScanAngleX.Text)) txtDistance.Text = dist_b * Sin(DtoR(angle_A)) ' txtDistance.Text = dist_b Else txtDistance.Text = "-1" End If MsgBox "hit at (" & testdot(cur_laser).Left & ", " & testdot(cur_laser).Top & ")" End If End If End Sub Private Sub tmrMain_Timer() cmdStep_Click End Sub Function DtoR(degrees As Double) DtoR = degrees * (3.141592654 / 180) End Function Function RtoD(radians As Double) RtoD = radians * (180 / 3.141592654) End Function