public FreeChargeSettings(FreeCharge charge)
        {
            InitializeComponent();

            lblLocation.Content = "Location : (" + charge.RenderTransform.Value.OffsetX + "," +
                                  charge.RenderTransform.Value.OffsetY + ")";
        }
Exemple #2
0
        public IEnumerable<Point> ChargeChargeDistance(FreeCharge freeCharge, Point orgin,
            int duration, Point startLocation)
        {
            var returnList = new List<Point>();
            IEnumerable<PointStatistics> data = FreeChargeLocationTracker(freeCharge, duration, startLocation);
            foreach (PointStatistics points in data)
            {
                var newpoint = new Point(points.Time, Helper.Distance(points.Position, orgin));

                returnList.Add(newpoint);
            }

            return returnList;
        }
Exemple #3
0
        //public IEnumerable<Point> ChargeChargeDistance(FreeCharge freeCharge, PositiveCharge positiveCharge,
        //                                                         int duration, Point startLocation)
        //{
        //    var returnList = new List<Point>();
        //    var data = FreeChargeLocationTracker(freeCharge, duration, startLocation);
        //    foreach (var points in data)
        //    {
        //        var temp = new Point(positiveCharge.RenderTransform.Value.OffsetX,
        //                             positiveCharge.RenderTransform.Value.OffsetY);
        //        var newpoint = new Point(points.Time, Helper.Distance(points.Position, temp));
        //        returnList.Add(newpoint);
        //    }
        //    return returnList;
        //}
        public IEnumerable<PointStatistics> FreeChargeLocationTracker(FreeCharge freeCharge, int duration,
            Point startLocation)
        {
            var returnList = new List<PointStatistics>();
            int counter = 1;
            bool forceEnd = false;
            while (counter <= duration && !forceEnd)
            {
                //Calculation
                //freeCharge.RenderTransform.Value.OffsetX = startLocation.X;
                //freeCharge.RenderTransform.Value.OffsetX = startLocation.Y;

                double fcX = freeCharge.RenderTransform.Value.OffsetX;
                double fcY = freeCharge.RenderTransform.Value.OffsetY;
                Vector moveVector = GetForceAtDesirePosition(fcX, fcY, 0);

                MainWindow.Instance.MoveIt(moveVector, freeCharge.LastVector, freeCharge);

                int nDist = MainWindow.Instance.NearestDistancetoNegative(freeCharge);
                double mag = Helper.VectorMagnitude(moveVector);
                if (Math.Abs(nDist - mag) < 40)
                {
                    forceEnd = true;
                }
                else if (Math.Abs((int) freeCharge.RenderTransform.Value.OffsetX) >= 900 ||
                         Math.Abs((int) freeCharge.RenderTransform.Value.OffsetY) >= 900)
                {
                    forceEnd = true;
                }
                freeCharge.LastVector += moveVector;

                var newPoint = new PointStatistics(new Point(fcX, fcY), counter, 0, 0,
                                                   Helper.VectorMagnitude(GetForceAtDesirePosition(fcX, fcY, 1)));
                returnList.Add(newPoint);

                counter++;
            }

            return returnList;
        }
        private void AddNewFreeChargeClick(object sender, RoutedEventArgs e)
        {
            var freecharge = new FreeCharge();
            freecharge.Margin = new Thickness(0, 0, 0, 0);
            freecharge.VerticalAlignment = VerticalAlignment.Top;
            freecharge.HorizontalAlignment = HorizontalAlignment.Left;
            freecharge.MyCharge = new Charge();
            freecharge.Height = 12;
            freecharge.Width = 12;

            string chargename = "Free-charge " + (TotalFrees() + 1).ToString(CultureInfo.InvariantCulture);
            int counter = 1;
            while (CheckExistingChargeWithName(chargename))
            {
                counter++;
                chargename = "Free-charge " + (TotalFrees() + counter).ToString(CultureInfo.InvariantCulture);
            }
            freecharge.MyCharge.Name = chargename;

            var group = new TransformGroup();

            var transfer = new TranslateTransform
                               {
                                   X = Helper.RandomNumber(10, (int) gridField.Width - 45),
                                   Y = Helper.Clamp(Helper.RandomNumber(10, ((int) gridField.Height - 35)/2), 0,
                                                    (int) gridField.Height - 65)
                               };
            gridField.Children.Add(freecharge);
            group.Children.Add(transfer);
            freecharge.StartPoint = new Point(transfer.X, transfer.Y);
            freecharge.RenderTransform = group;

            FieldOutline.Update();
        }
        public int NearestDistancetoNegative(FreeCharge freeCharge)
        {
            int nearestDistance = 100000;
            var location1 = new Point((int) freeCharge.RenderTransform.Value.OffsetX,
                                      (int) freeCharge.RenderTransform.Value.OffsetY);

            foreach (object uiElement in gridField.Children)
            {
                if (uiElement.GetType() == typeof (NegativeCharge))
                {
                    var location2 = new Point((int) ((NegativeCharge) uiElement).RenderTransform.Value.OffsetX + 16,
                                              (int) ((NegativeCharge) uiElement).RenderTransform.Value.OffsetY + 16);

                    var distance = (int) Helper.Distance(location1, location2);
                    if (distance < nearestDistance)
                    {
                        nearestDistance = distance;
                    }
                }
            }

            return nearestDistance;
        }