Example #1
0
        private void OnConfirm(object sender, EventArgs e)
        {
            if (sender is ConfirmationButton && (sender as ConfirmationButton) == m_cbtn_confirm)
            {
                LocationState new_spot = new LocationState(
                    (double)m_nud_old_distance.Value,
                    (double)((m_nud_old_azimuth.Value + 180) % 360) // Point the other way
                    );

                foreach (string team in m_teams)
                {
                    foreach (RenamableButton key in m_locations[team])
                    {
                        LocationState location = m_states[team][key];
                        if (!location.Default)
                        {
                            location.Assign(LocationState.CalculateVector(new_spot, location));
                        }
                    }
                    m_locations[team].First().ActiveButton().PerformClick();
                }

                m_nud_old_distance.Value = 1;
                m_nud_old_azimuth.Value  = 0;
            }
        }
Example #2
0
        private void OnTextBoxValueUpdate(object sender, EventArgs e)
        {
            OnLocationSave(sender, e);

            string team  = m_teams.First();
            string other = m_teams.Last();

            // Get friend location state
            RenamableButton key    = m_locations[team].First().ActiveButton();
            LocationState   friend = m_states[team][key];

            // Get target location state
            key = m_locations[other].First().ActiveButton();
            LocationState target = m_states[other][key];

            // run calculation
            LocationState result = LocationState.CalculateVector(friend, target);

            double distance = Math.Round(result.Distance, 1);

            Color result_text = (distance < 75 || distance > 150) ? (new ColorPalette.BasePalette()).Accent : Color.White;

            m_lbl_result_dist_value.ForeColor = m_lbl_result_azim_value.ForeColor = result_text;

            m_lbl_result_dist_value.Text = distance.ToString("F1");
            m_lbl_result_azim_value.Text = Math.Round(result.Azimuth, 1).ToString("F1");
        }
Example #3
0
        private void OnLoadLocationState(object sender, EventArgs e)
        {
            RenamableButton key = (RenamableButton)sender;

            if (key != null)
            {
                // Get my LocationState
                string        control_set = "";
                LocationState location    = null;
                foreach (string team in m_teams)
                {
                    if (key.Name.Contains(team))
                    {
                        control_set = team;
                        location    = m_states[team][key];
                        break;
                    }
                }

                // Load state values into my Parent's boxes
                if (control_set == m_teams.First())
                {
                    m_nud_friend_distance.Value = (decimal)location.Distance;
                    m_nud_friend_azimuth.Value  = (decimal)location.Azimuth;
                }
                else if (control_set == m_teams.Last())
                {
                    m_nud_target_distance.Value = (decimal)location.Distance;
                    m_nud_target_azimuth.Value  = (decimal)location.Azimuth;
                }
            }
        }
Example #4
0
        public static LocationState CalculateVector(LocationState friend, LocationState target)
        {
            if (friend == target)
            {
                return(new LocationState(0, 0));
            }

            Side SF = new Side(friend.Distance);                    // Spotter to Friend
            Side ST = new Side(target.Distance);                    // Spotter to Target
            Side FT;                                                // Friend  to Target (result)

            Angle NSF = new Angle(Angle.ToRadians(friend.Azimuth)); // North   to Spotter to Friend
            Angle NST = new Angle(Angle.ToRadians(target.Azimuth)); // North   to Spotter to Target
            Angle NFT;                                              // North   to Friend  to Target (result)

            // Calculated values
            Angle SFT;                                              // Spotter to Friend  to Target
            Angle delta;                                            // Change between NSF and NST
            Angle PI = new Angle(Math.PI);                          // 180 degree angle for easy computing.

            delta = new Angle(Math.Abs(NSF.Radians - NST.Radians));
            FT    = MathExtension.LawOfCosines(SF, ST, delta);
            // Order matters here. Side ST must always be the 3rd parameter.
            SFT = MathExtension.LawOfCosines(SF, FT, ST);
            double SFTdegrees = Math.Round(SFT.Degrees);

            // Make sure Angle stays between 0 - 360 degrees or 0 and 2PI radians
            delta.Validate();
            NFT = NSF + PI + ((delta.Degrees > PI.Degrees ^ NST > NSF) ? -SFT : SFT);
            NFT.Validate();

            return(new LocationState(FT.Length, NFT.Degrees));
        }
Example #5
0
 public void Assign(LocationState rhs)
 {
     Distance = rhs.Distance;
     Azimuth  = rhs.Azimuth;
     Default  = rhs.Default;
 }
Example #6
0
 public LocationState(LocationState state)
 {
     SetCoords(state.Distance, state.Azimuth);
 }