Example #1
0
        private double PredictedAngleStraightLine()
        {
            var expectedVector        = new Vector2D(Garics.Position, EnemyExpectedPosition(Garics.BulletSpeed));
            var vectorToTarget        = new Vector2D(Garics.Position, Garics.TargetedEnemy.Position);
            var angleActualToExpected = expectedVector.Angle(vectorToTarget);
            var angleToEnemy          = Garics.HeadingRadians + angleActualToExpected + Garics.TargetedEnemy.BearingRadians -
                                        Garics.GunHeadingRadians;

            return(angleToEnemy);
        }
Example #2
0
        private double PredictedAngleStraightLine()
        {
            var expectedVector        = new Vector2D(Robot.Position, EnemyExpectedPosition(Robot.BulletSpeed));
            var vectorToTarget        = new Vector2D(Robot.Position, Robot.TargetedEnemy.Position);
            var angleActualToExpected = expectedVector.Angle(vectorToTarget);
            var angleToEnemy          = Robot.HeadingRadians + angleActualToExpected + Robot.TargetedEnemy.BearingRadians -
                                        Robot.GunHeadingRadians;

            //DEBUG
            Robot.DrawLineAndTarget(Color.Coral, Robot.Position, new Point2D(EnemyExpectedPosition(Robot.BulletSpeed)));
            return(angleToEnemy);
        }
 public void UpdateShip(TestCase testCase, Vector2D gravity)
 {
   if (Mouse.PrimaryDevice.LeftButton == MouseButtonState.Pressed)
   {
     var mousePoint = view.GetTransform().Inverse.Transform(Mouse.PrimaryDevice.GetPosition(view));
     var mouseVector = new Vector2D { X = mousePoint.X, Y = mousePoint.Y };
     var difference = mouseVector - testCase.Ship.Position;
     testCase.Ship.Turn = Vector2D.Angle(testCase.Ship.Direction, difference);
   }
   else
   {
     testCase.Ship.Turn = 0;
   }
 }
Example #4
0
        protected double Angle(int i)
        {
            if (i < 0 || i >= this.VertexCount)
            {
                throw (new ArgumentException());
            }

            int a = (i - 1) % this.VertexCount;
            int b = i % this.VertexCount;
            int c = (i + 1) % this.VertexCount;

            if (a < 0)
            {
                a = this.VertexCount - 1;
            }

            Vector2D v1    = this.GetPoint(b) - this.GetPoint(a);
            Vector2D v2    = this.GetPoint(c) - this.GetPoint(b);
            double   angle = Vector2D.Angle(v1, v2);

            return(angle);
        }
Example #5
0
        protected double GetAngle(Point2D point)
        {
            double angle = 0.0;

            for (int i = 0; i < this.VertexCount; i++)
            {
                Vector2D v1 = GetPoint(i) - point;
                Vector2D v2 = GetPoint((i + 1) % this.VertexCount) - point;
                double   a  = Vector2D.Angle(v1, v2);

                if (a > Math.PI)
                {
                    a -= 2 * Math.PI;
                }
                else if (a < -Math.PI)
                {
                    a += 2 * Math.PI;
                }

                angle += a;
            }

            return(angle);
        }
Example #6
0
        private void Divide(Polygon2D poly)
        {
            for (int i = 0; i < poly.VertexCount; i++)              //Find Convex Angle
            {
                if (poly.isConvexAngle(i))
                {
                    continue;
                }
                int    index    = i;
                double min_dist = 10000;

                for (int j = 0; j < poly.VertexCount; j++)                 //Divide Polygon
                {
                    if (j == i)
                    {
                        continue;
                    }
                    LineSegment2D line = new LineSegment2D(poly.GetPoint(i), poly.GetPoint(j));

                    if (poly.isDiagonal(line))
                    {
                        //double dist = line.Length;
                        Vector2D      v1    = line.ToVector();
                        LineSegment2D line1 = poly.GetEdge(i);
                        line1.SwapPoints();
                        LineSegment2D line2 = poly.GetEdge((i + 1) % poly.VertexCount);
                        Vector2D      v2    = line1.ToVector();
                        Vector2D      v3    = line2.ToVector();

                        double angle1 = Vector2D.Angle(v2, v1);
                        double angle2 = Vector2D.Angle(v1, v3);                          //选取划分角度最均匀的点作分割点

                        if (angle1 < 0)
                        {
                            angle1 += Math.PI * 2;
                        }
                        if (angle2 < 0)
                        {
                            angle2 += Math.PI * 2;
                        }

                        double dist = Math.Max(angle1, angle2);
                        if (!poly.isConvexAngle(j) && dist < Math.PI)
                        {
                            dist -= Math.PI;
                        }

                        if (dist < min_dist)
                        {
                            index    = j;
                            min_dist = dist;
                        }
                    }
                }
                if (index != i)
                {
                    this.DividedBy(new LineSegment2D(poly.GetPoint(i), poly.GetPoint(index)));
                    return;
                }
            }
            throw (new ArgumentException());
        }
Example #7
0
 /// <summary>
 /// Get the angle in degree between two vectors.
 /// </summary>
 public static double Angle(Vector2I v1, Vector2I v2)
 {
     return(Vector2D.Angle(v1, v2));
 }