VERSION 5.00 Begin VB.Form frmMain Caption = "Laser Range Map" ClientHeight = 6585 ClientLeft = 60 ClientTop = 345 ClientWidth = 8790 LinkTopic = "Form1" ScaleHeight = 6585 ScaleWidth = 8790 StartUpPosition = 3 'Windows Default Begin VB.Frame frmGeometry Caption = "Geometry Demo" Height = 6375 Left = 60 TabIndex = 0 Top = 120 Width = 8655 Begin VB.TextBox txtAngleA Height = 285 Left = 1200 TabIndex = 9 Text = "0" Top = 2340 Width = 795 End Begin VB.TextBox txtAngleB Height = 285 Left = 1200 TabIndex = 8 Text = "0" Top = 2640 Width = 795 End Begin VB.TextBox txtDsta Height = 285 Left = 1200 TabIndex = 7 Text = "0" Top = 2940 Width = 795 End Begin VB.TextBox txtDstb Height = 285 Left = 1200 TabIndex = 6 Text = "0" Top = 3240 Width = 795 End Begin VB.TextBox txtDstc Height = 285 Left = 1200 TabIndex = 5 Text = "0" Top = 3540 Width = 795 End Begin VB.TextBox txtDstd Height = 285 Left = 1200 TabIndex = 4 Text = "0" Top = 3840 Width = 795 End Begin VB.TextBox txtDstx Height = 285 Left = 1200 TabIndex = 3 Text = "0" Top = 4140 Width = 795 End Begin VB.Timer tmrMain Left = 60 Top = 1320 End Begin VB.CommandButton cmdStart Caption = "Start" Height = 315 Left = 7200 TabIndex = 2 Top = 180 Width = 675 End Begin VB.CommandButton cmdStep Caption = "Step" Height = 315 Left = 7920 TabIndex = 1 Top = 180 Width = 615 End Begin VB.Line Line1 X1 = 2100 X2 = 480 Y1 = 1020 Y2 = 2040 End Begin VB.Line Line2 X1 = 480 X2 = 480 Y1 = 420 Y2 = 2040 End Begin VB.Line Line3 X1 = 480 X2 = 2100 Y1 = 420 Y2 = 1020 End Begin VB.Label Label1 BackStyle = 0 'Transparent Caption = "A" Height = 255 Index = 0 Left = 360 TabIndex = 26 Top = 240 Width = 195 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "B" Height = 255 Left = 360 TabIndex = 25 Top = 2040 Width = 195 End Begin VB.Label Label3 BackStyle = 0 'Transparent Caption = "C" Height = 255 Left = 2160 TabIndex = 24 Top = 900 Width = 195 End Begin VB.Label Label4 BackStyle = 0 'Transparent Caption = "a" Height = 255 Left = 1320 TabIndex = 23 Top = 1560 Width = 195 End Begin VB.Label Label5 BackStyle = 0 'Transparent Caption = "b" Height = 255 Left = 1320 TabIndex = 22 Top = 480 Width = 195 End Begin VB.Line Line4 BorderStyle = 3 'Dot X1 = 2100 X2 = 480 Y1 = 1020 Y2 = 1020 End Begin VB.Label Label6 BackStyle = 0 'Transparent Caption = "d" Height = 255 Left = 960 TabIndex = 21 Top = 1020 Width = 195 End Begin VB.Label Label7 BackStyle = 0 'Transparent Caption = "c" Height = 255 Left = 120 TabIndex = 20 Top = 960 Width = 195 End Begin VB.Label Label8 BackStyle = 0 'Transparent Caption = "x" Height = 255 Left = 300 TabIndex = 19 Top = 600 Width = 195 End Begin VB.Label Label11 BackStyle = 0 'Transparent Caption = "A" Height = 255 Left = 2400 TabIndex = 18 Top = 300 Width = 195 End Begin VB.Label Label1 BackStyle = 0 'Transparent Caption = "B" Height = 255 Index = 1 Left = 2460 TabIndex = 17 Top = 5940 Width = 195 End Begin VB.Line Linea X1 = 2640 X2 = 8400 Y1 = 420 Y2 = 4140 End Begin VB.Line Lineb BorderColor = &H000000C0& X1 = 2640 X2 = 8520 Y1 = 6120 Y2 = 4860 End Begin VB.Label Label12 BackStyle = 0 'Transparent Caption = "Angle A" Height = 255 Left = 360 TabIndex = 16 Top = 2400 Width = 675 End Begin VB.Line Lined BorderStyle = 3 'Dot X1 = 2640 X2 = 8460 Y1 = 4680 Y2 = 4680 End Begin VB.Line Linex BorderStyle = 3 'Dot X1 = 2640 X2 = 2640 Y1 = 420 Y2 = 6120 End Begin VB.Label Label13 BackStyle = 0 'Transparent Caption = "Angle B" Height = 255 Left = 360 TabIndex = 15 Top = 2700 Width = 675 End Begin VB.Label Label14 BackStyle = 0 'Transparent Caption = "Distance a" Height = 255 Left = 360 TabIndex = 14 Top = 3000 Width = 795 End Begin VB.Label Label15 BackStyle = 0 'Transparent Caption = "Distance b" Height = 255 Left = 360 TabIndex = 13 Top = 3300 Width = 795 End Begin VB.Label Label16 BackStyle = 0 'Transparent Caption = "Distance c" Height = 255 Left = 360 TabIndex = 12 Top = 3600 Width = 795 End Begin VB.Label Label17 BackStyle = 0 'Transparent Caption = "Distance d" Height = 255 Left = 360 TabIndex = 11 Top = 3900 Width = 795 End Begin VB.Label Label18 BackStyle = 0 'Transparent Caption = "Distance x" Height = 255 Left = 360 TabIndex = 10 Top = 4200 Width = 795 End Begin VB.Shape box BackStyle = 1 'Opaque FillStyle = 7 'Diagonal Cross Height = 2055 Index = 0 Left = 6000 Top = 2760 Width = 135 End Begin VB.Shape box BackStyle = 1 'Opaque FillStyle = 7 'Diagonal Cross Height = 975 Index = 1 Left = 6420 Top = 4560 Width = 135 End End End Attribute VB_Name = "frmMain" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Const min_a = 10 Const max_a = 80 Const min_b = 10 Const max_b = 80 Const step_a = 2 Const step_b = 2 Private Sub cmdShowImageDemo_Click() frmImageDemo.Show End Sub Private Sub Form_Load() tmrMain.Enabled = False tmrMain.Interval = 1 txtAngleA.Text = min_a txtAngleB.Text = min_b 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() If (txtAngleB.Text + step_b > max_b) Then txtAngleB.Text = min_b If (txtAngleA.Text + step_a > max_a) Then txtAngleA.Text = min_a Else txtAngleA.Text = txtAngleA.Text + step_a End If Else txtAngleB.Text = txtAngleB.Text + step_b End If End Sub Private Sub tmrMain_Timer() cmdStep_Click End Sub Private Sub txtAngleA_Change() UpdateLines UpdateIntersect End Sub Private Sub txtAngleB_Change() UpdateLines UpdateIntersect End Sub Function UpdateLines() Dim ya As Double, yb As Double If (txtAngleA.Text > 0) Then ya = Linea.Y1 + (Linea.X2 - Linea.X1) * Tan(DtoR(90 - txtAngleA.Text)) Linea.Visible = True Linea.Y2 = ya Else Linea.Visible = False End If If (txtAngleB.Text > 0) Then yb = Lineb.Y1 - (Lineb.X2 - Lineb.X1) / Tan(DtoR(txtAngleB.Text)) Lineb.Visible = True Lineb.Y2 = yb Else Lineb.Visible = False End If End Function Function UpdateIntersect() Dim m_a, b_a, m_b, b_b, X, Y As Double Dim obox As Shape Dim is_intersect As Boolean is_intersect = False If (Linea.Visible = True And Lineb.Visible = True) Then ' y = mx+b m_a = (Linea.Y2 - Linea.Y1) / (Linea.X2 - Linea.X1) b_a = Linea.Y1 - m_a * Linea.X1 ' y = mx+b m_b = (Lineb.Y2 - Lineb.Y1) / (Lineb.X2 - Lineb.X1) b_b = Lineb.Y1 - m_b * Lineb.X1 ' intersection If (m_a - m_b > 0) Then X = (b_b - b_a) / (m_a - m_b) Y = m_a * X + b_a For Each obox In box If (X > obox.Left And X < obox.Left + obox.Width And Y > obox.Top And Y < obox.Top + obox.Height) Then is_intersect = True Exit For End If Next ' if point of crossing is inside object If (is_intersect) Then txtDsta.Text = (Lined.X2 - Lined.X1) / Sin(DtoR(txtAngleB.Text)) ' txtDstb.Text = ((Lineb.Y1 - Linea.Y1) * Sin(DtoR(txtAngleB.Text))) / Sin(DtoR(180 - txtAngleA.Text - txtAngleB.Text)) txtDstb.Text = (Lined.X2 - Lined.X1) / Sin(DtoR(txtAngleA.Text)) txtDstc.Text = Lineb.Y1 - Linea.Y1 Lined.Visible = True Lined.Y1 = Y Lined.Y2 = Y Lined.X2 = X txtDstd.Text = Lined.X2 - Lined.X1 Linex.Visible = True Linex.Y2 = Y txtDstx.Text = Y Else Lined.Visible = False Linex.Visible = False txtDsta.Text = "-1" txtDstb.Text = "-1" txtDstc.Text = "-1" txtDstd.Text = "-1" txtDstx.Text = "-1" End If Else Lined.Visible = False Linex.Visible = False End If End If End Function Function DtoR(degrees As Double) DtoR = degrees * (3.141592654 / 180) End Function Function RtoD(radians As Double) RtoD = radians * (180 / 3.141592654) End Function