Exemplo n.º 1
0
        /// <summary>
        /// Rotates vector begins on A on degree in degrees
        /// </summary>
        /// <param name="_A"></param>
        /// <param name="_B"></param>
        /// <returns></returns>
        public static PairDouble Rotate(PairDouble _A, PairDouble _B, double _degree)
        {
            PairDouble toRotate = _B - _A;
            var        rotated  = Rotate(toRotate, _degree);

            return(rotated + _A);
        }
Exemplo n.º 2
0
        public static int GetDegreeBetveen(PairDouble _a, PairDouble _b)
        {
            var scalarAB = _a.First * _b.First + _a.Second * _b.Second;

            var ab = _a.ABS() * _b.ABS();

            return((int)(180 * Math.Acos(scalarAB / ab) / Math.PI));
        }
Exemplo n.º 3
0
        public static PairDouble Rotate(PairDouble _A, double _degree)
        {
            var cos = Math.Cos(_degree * Math.PI / 180);
            var sin = Math.Sin(_degree * Math.PI / 180);

            var xn = _A.First * cos - _A.Second * sin;
            var yn = _A.First * sin + _A.Second * cos;

            return(new PairDouble(xn, yn));
        }
Exemplo n.º 4
0
        public Particle(double _x, double _y, IDrawer _drawer)
        {
            Drawer           = _drawer;
            m_CoordinatesNew = m_Coordinates = new PairDouble(_x, _y);

            Random k = new Random((int)DateTime.Now.ToBinary());
            Random r = new Random(k.GetHashCode());

            m_Speed = new PairDouble(Miscelaneous.ParticleSpeed * (0.5 - r.NextDouble()), Miscelaneous.ParticleSpeed * (0.5 - r.NextDouble()));
            m_Speed.Normalize();
        }
Exemplo n.º 5
0
        public virtual void NextStep(IEnumerable <IParticle> _particles, IBorder _border)
        {
            GetNearests(_particles);
            Interract();

            int?check = _border.Check(this);

            if (check != null)
            {
                _border.Interract(this, (int)check);
            }
            else
            {
                m_CoordinatesNew = m_Coordinates + m_Speed;
            }
        }
Exemplo n.º 6
0
 public static bool Intersect(PairDouble _a, PairDouble _b, PairDouble _c, PairDouble _d)
 {
     try
     {
         var    ip = IntersectionPoint(_a, _b, _c, _d);
         double xA1 = _a.First, xB1 = _b.First, yA1 = _a.Second, yB1 = _b.Second;
         double xA2 = _c.First, xB2 = _d.First, yA2 = _c.Second, yB2 = _d.Second;
         var    X = ip.First;
         var    Y = ip.Second;
         return(Between(xA1, xB1, X) && Between(xA2, xB2, X) && Between(yA1, yB1, Y) && Between(yA2, yB2, Y));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 7
0
        public virtual void Interract()
        {
            var cumulativeSpeed = new PairDouble(0, 0);

            foreach (var particle in m_Nearest)
            {
                cumulativeSpeed = cumulativeSpeed + particle.SpeedInDouble;
            }
            PairDouble averSpd = cumulativeSpeed / m_Nearest.Count();

            averSpd.Normalize();

            if (averSpd.IsNaN())
            {
                averSpd = new PairDouble(0, 0);
            }

            m_Speed = averSpd * Miscelaneous.ParticleSpeed;
            AddNoize(Miscelaneous.Noize);
        }
Exemplo n.º 8
0
        public static PairDouble IntersectionPoint(PairDouble _a, PairDouble _b, PairDouble _c, PairDouble _d)
        {
            const double eps = 1E-9;
            double       xA1 = _a.First, xB1 = _b.First, yA1 = _a.Second, yB1 = _b.Second;
            double       xA2 = _c.First, xB2 = _d.First, yA2 = _c.Second, yB2 = _d.Second;
            double       c1 = yA1 * xB1 - xA1 * yB1, c2 = yA2 * xB2 - xA2 * yB2;

            double det = Det(xB1 - xA1, -(yB1 - yA1), xB2 - xA2, -(yB2 - yA2));

            if (Math.Abs(det - 0) > eps)
            {
                double detX = Det(xB1 - xA1, c1, xB2 - xA2, c2);
                double detY = Det(c1, -(yB1 - yA1), c2, -(yB2 - yA2));

                double X = detX / det, Y = detY / det;

                return(new PairDouble(X, Y));
            }
            throw new Exception("I don't know where interception is because lines are parallels");
        }
Exemplo n.º 9
0
        public override void Interract(IParticle _particle, int _index)
        {
            PairDouble newPos = new PairDouble(0, 0);

            if (_index == 0)
            {
                newPos = _particle.CoordinatesInDouble + new PairDouble(m_SizeX, 0);
            }
            if (_index == 1)
            {
                newPos = _particle.CoordinatesInDouble - new PairDouble(0, m_SizeY);
            }
            if (_index == 2)
            {
                newPos = _particle.CoordinatesInDouble - new PairDouble(m_SizeX, 0);
            }
            if (_index == 3)
            {
                newPos = _particle.CoordinatesInDouble + new PairDouble(0, m_SizeY);
            }
            _particle.UpdCoordinates(newPos + _particle.SpeedInDouble);
        }
Exemplo n.º 10
0
 public void Move()
 {
     m_Coordinates = m_CoordinatesNew;
 }
Exemplo n.º 11
0
 public void UpdCoordinates(PairDouble _newPos)
 {
     m_CoordinatesNew = _newPos;
 }
Exemplo n.º 12
0
 public void UpdSpeed(PairDouble _newSpd)
 {
     m_Speed = _newSpd;
 }
Exemplo n.º 13
0
 public static int GetDegreeBetveen(PairDouble _a, PairDouble _b, PairDouble _c, PairDouble _d)
 {
     return(GetDegreeBetveen(_b - _a, _d - _c));
 }