public override Point GetWaypoint()
        {
            // update collided point status
            _me.SetStatus(_mo.X, _mo.Y, MapElementStatus.Collided);

            Vector vector = new Vector(_mo.X - _posX, _mo.Y - _posY);
            
            // opposite direction
            vector.Negate();

            // normalize vector (length = 1)
            vector.Normalize();

            // calculate distances to every border
            double tLeft = (-_posX) / vector.X;
            double tRight = (800 - _posX) / vector.X;
            double tTop = (-_posY) / vector.Y;
            double tBottom = (600 - _posY) / vector.Y;

            vector *= 20;

            _point.X = (int)_posX + (int)vector.X;
            _point.Y = (int)_posY + (int)vector.Y;

            _point.Status = MapElementStatus.Waypoint;

            return _point;
        }
        public override void Draw(StreamGeometryContext context, Point startPoint, Point endPoint)
        {
            Vector line = endPoint - startPoint;
            Vector perpendicularLine = new Vector(line.Y, -line.X);
            perpendicularLine.Normalize();

            double halfLength = line.Length/2;
            Point leftPoint = startPoint - (perpendicularLine*halfLength);
            Point rightPoint = startPoint + (perpendicularLine * halfLength);

            var norLine = new Vector(line.X, line.Y);
            norLine.Normalize();
            Point shortEndPoint = endPoint - (norLine * 4);

            context.BeginFigure(startPoint, true, false);
            context.LineTo(shortEndPoint, true, false);

            context.LineTo(leftPoint, false, false);
            context.LineTo(shortEndPoint, true, false);

            context.LineTo(rightPoint, false, false);
            context.LineTo(shortEndPoint, true, false);

            context.LineTo(endPoint, true, false);
        }
        public void TestPushBackBotRightToCenter()
        {
            //Preconfig
            Vector position1 = new Vector(0f, 50f);
            Vector target1 = new Vector(50f, 50f);

            int radius2 = 20;
            Vector center2 = new Vector(25, 55);
            Vector ballSpeed = new Vector(-5, -5);

            Vector hitPoint = new Vector(20, 50);
            Vector pushBackVec;
            Vector estimatedPushBackVec = new Vector(0, 1);
            estimatedPushBackVec.Normalize();

            //Creation
            Line parent = new Line();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingLine bL1 = new BoundingLine(position1, target1);

            bCont.AddBoundingBox(bL1);
            parent.Location = (new Vector(0, 0));

            //Operation
            pushBackVec = bL1.GetOutOfAreaPush(radius2 * 2, hitPoint, -ballSpeed, center2);
            pushBackVec.Normalize();

            //Assertion
            Assert.AreEqual(estimatedPushBackVec, pushBackVec);
        }
示例#4
0
        /// <summary>
        /// Reflect vector from segment
        /// </summary>
        /// <param name="I">vector</param>
        /// <param name="AB">segment</param>
        /// <returns>new vector</returns>
        public static Vector reflect(System.Windows.Vector I, Segment AB)                               //расчет вектора отражения от отрезка
        {
            System.Windows.Vector n      = new System.Windows.Vector(AB.A.Y - AB.B.Y, AB.B.X - AB.A.X); //Normal to vector
            System.Windows.Vector result = I - 2 * n * ((I * n) / (n * n));                             // Reflected vector
            result.Normalize();

            return(result);
        }
示例#5
0
 public void addGoalPoint(Point goal)
 {
     velocity = new Vector(goal.X - topLeft.X, goal.Y - topLeft.Y);
     if (velocity.Length > 5)
         velocity.Normalize();
     else
         velocity = new Vector(0, 0);
     velocity *= MAX_SPEED;
 }
示例#6
0
        /// <summary>
        /// Method that update input controller
        /// </summary>
        public override void Update(Int32 dt)
        {
            Vector direction = new Vector(0, 0);

            Action action = () =>
            {

                if ((Keyboard.GetKeyStates(Key.Up) & KeyStates.Down) > 0 || (Keyboard.GetKeyStates(Key.W) & KeyStates.Down) > 0)
                {
                    direction.Y += 1;
                }

                if ((Keyboard.GetKeyStates(Key.Down) & KeyStates.Down) > 0 || (Keyboard.GetKeyStates(Key.S) & KeyStates.Down) > 0)
                {
                    direction.Y -= 1;
                }

                if ((Keyboard.GetKeyStates(Key.Left) & KeyStates.Down) > 0 || (Keyboard.GetKeyStates(Key.A) & KeyStates.Down) > 0)
                {
                    direction.X -= 1;
                }

                if ((Keyboard.GetKeyStates(Key.Right) & KeyStates.Down) > 0 || (Keyboard.GetKeyStates(Key.D) & KeyStates.Down) > 0)
                {
                    direction.X += 1;
                }

                if (!(direction.X == 0 && direction.Y == 0))
                {
                    direction.Normalize();
                }

                if ((Keyboard.GetKeyStates(Key.Space) & KeyStates.Down) > 0)
                {
                    fireState = true;
                }

            };

            Application.Current.Dispatcher.Invoke(action);

            Camera camera = GameProcess.Current_Game.Camera;

            Vector mouseAbsLocation = camera.Focus - camera.ViewSize + mouseCanvasPosition;

            Vector towerDirection = mouseAbsLocation - Target.Gun.AbsoluteCenter;
            towerDirection.Normalize();     //Maybe check by zero


            UpdateTargetDirection(direction, dt);
            UpdateGunDirection(towerDirection ,dt);

            if (fireState == true)
                Target.Fire();

            fireState = false;
        }
示例#7
0
        public static PointF GetPointOnProfile(PointF[] array, PointF p)
        {
            PointF fClosest  = PointF.Empty;   //first closest
            double fDistance = double.MaxValue;
            PointF sClosest  = PointF.Empty;   //second closest
            double sDistance = double.MaxValue;
            PointF tmpP;
            double tmpD;


            foreach (PointF testPoint in array)
            {
                if (MainWindow.GetDistanceBetween(testPoint, p) < sDistance)
                {
                    sDistance = MainWindow.GetDistanceBetween(testPoint, p);
                    sClosest  = testPoint;
                }
                if (MainWindow.GetDistanceBetween(testPoint, p) < fDistance)
                {
                    tmpD      = fDistance;
                    tmpP      = fClosest;
                    fDistance = sDistance;
                    fClosest  = sClosest;
                    sClosest  = tmpP;
                    sDistance = tmpD;
                }
            }

            //User normal vector of vector fClosest and sClosest and select orientation
            double distace = MainWindow.GetDistanceBetween(fClosest, sClosest);
            double Ca      = ((fDistance * fDistance) - (sDistance * sDistance) + (distace * distace)) / (2 * distace);
            double Vc      = Math.Sqrt((fDistance * fDistance) - (Ca * Ca));

            double prdel  = sClosest.X - fClosest.X;
            double kysela = sClosest.Y - fClosest.Y;

            System.Windows.Vector v1 = new System.Windows.Vector((-1) * kysela, prdel);
            System.Windows.Vector v2 = new System.Windows.Vector(kysela, (-1) * prdel);

            v1.Normalize();
            v1 = System.Windows.Vector.Multiply(Vc, v1);
            v2.Normalize();
            v2 = System.Windows.Vector.Multiply(Vc, v2);

            if (MainWindow.GetDistanceBetween(fClosest, new PointF((float)((p.X + v1.X)), (float)((p.Y + v1.Y)))) > MainWindow.GetDistanceBetween(fClosest, new PointF((float)((p.X + v2.X)), (float)((p.Y + v2.Y)))))
            {
                v1.X = v2.X;
                v1.Y = v2.Y;
            }
            if ((distace < MainWindow.GetDistanceBetween(sClosest, new PointF((float)((p.X + v1.X)), (float)((p.Y + v1.Y))))) || double.IsNaN(v1.X))
            {
                return(fClosest);
            }

            return(new PointF((float)((p.X + v1.X)), (float)((p.Y + v1.Y))));
        }
示例#8
0
        private int CalculateAngle(SkeletonPoint origem, SkeletonPoint destino, SkeletonPoint baseOrigem, SkeletonPoint baseDestino)
        {
            Vector skeletonVector = new Vector(destino.X - origem.X, destino.Y - origem.Y);
            Vector baseVector = new Vector(baseDestino.X - baseOrigem.X, baseDestino.Y - baseOrigem.Y);

            skeletonVector.Normalize();
            baseVector.Normalize();

            double angle = Vector.AngleBetween(baseVector, skeletonVector);
            return (int) Math.Round(Math.Abs(angle));
        }
示例#9
0
 void WindowOnSizeChanged(object sender, SizeChangedEventArgs args)
 {
     double width = ActualWidth - 2*SystemParameters.ResizeFrameVerticalBorderWidth;
     double height = ActualHeight - 2*SystemParameters.ResizeFrameHorizontalBorderHeight - SystemParameters.CaptionHeight;
     Point ptCenter = new Point(width/2, height/2);
     Vector vectDiag = new Vector(width, -height);
     Vector vectPerp = new Vector(vectDiag.Y, -vectDiag.X);
     vectPerp.Normalize();
     vectPerp *= width*height / vectDiag.Length;
     brush.StartPoint = ptCenter + vectPerp;
     brush.EndPoint = ptCenter - vectPerp;
 }
示例#10
0
        public static void ComputeLinkBetweenRectangles(Rect sourceRectangle, Rect targetRectangle, double positionOffset, out Point linkStart, out Point linkEnd)
        {
            Point sourceCenter = new Point(sourceRectangle.X + sourceRectangle.Width / 2, sourceRectangle.Y + sourceRectangle.Height / 2);
            Point targetCenter = new Point(targetRectangle.X + targetRectangle.Width / 2, targetRectangle.Y + targetRectangle.Height / 2);
            Vector direction = targetCenter - sourceCenter;

            Vector normal = new Vector(-direction.Y, direction.X);
            normal.Normalize();
            Point offsettedSourceCenter = sourceCenter + (normal * positionOffset);
            Point offsettedTargetCenter = targetCenter + (normal * positionOffset);

            linkStart = GetRectangleAndLineIntersection(sourceRectangle, offsettedSourceCenter, offsettedTargetCenter);
            linkEnd = GetRectangleAndLineIntersection(targetRectangle, offsettedTargetCenter, offsettedSourceCenter);
        }
        public override void Draw(StreamGeometryContext context, Point startPoint, Point endPoint)
        {
            base.Draw(context, startPoint, endPoint);

            Vector line = endPoint - startPoint;
            Vector perpendicularLine = new Vector(line.Y, -line.X);
            perpendicularLine.Normalize();

            double halfLength = line.Length / 2;
            Point leftPoint = endPoint - (perpendicularLine * halfLength);
            Point rightPoint = endPoint + (perpendicularLine * halfLength);

            context.BeginFigure(leftPoint, true, false);
            context.LineTo(rightPoint, true, false);
        }
示例#12
0
文件: Spiky.cs 项目: hirekoke/FloWin
 /// <summary>
 /// Spikyカーネル関数勾配値の計算
 /// </summary>
 /// <param name="rv">位置の差ベクトル</param>
 public static void Gradient(Vector rv, Vector ov, ref Vector result)
 {
     double r = rv.Length;
     Vector nv = new Vector(rv.X, rv.Y);
     if (r == 0)
     {
         nv.X = ov.X; nv.Y = ov.Y;
     }
     nv.Normalize();
     if (r >= 0 && r < _h)
     {
         double q = _h - r;
         result = _CSpikyGradient * q * q * nv;
         return;
     }
     result.X = 0; result.Y = 0;
 }
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            double Width = ActualWidth - 2 * SystemParameters.ResizeFrameVerticalBorderWidth;
            double Height = ActualHeight - 2 * SystemParameters.ResizeFrameHorizontalBorderHeight - SystemParameters.CaptionHeight;

            Point ptCenter = new Point(Width / 2, Height / 2); //중간 좌표를 구한다.

            Vector vectDiag = new Vector(Width, -Height);       //좌측 하단부터 우측 상단까지의 대각선
            Vector vectPerp = new Vector(vectDiag.Y, -vectDiag.X); //vectDiag와 수직되는 대각선

            vectPerp.Normalize();               //정규화 시키기((0,0)~ (1,1))
            vectPerp *= Width * Height / vectDiag.Length;//vectPerp의 클라이언트 기준의 길이..
            //vectPerp의 클라이언트 기준의 길이를 구하는 이유는 길이를 알아야 Gradient가 그릴 좌표를 알 수 있기 때문이다.

            brush.StartPoint = ptCenter + vectPerp;     //해당하는 클라이언트의 시작과 끝 좌표를 대입한다.
            brush.EndPoint = ptCenter - vectPerp;
        }
        /// <summary>
        /// Gets the billboard positions with the current screen transform.
        /// </summary>
        /// <param name="billboards">The billboards.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="pinWidth">Width of the pins.</param>
        /// <returns>The mesh vertices.</returns>
        public Point3DCollection GetPinPositions(IList<Billboard> billboards, Vector offset, double pinWidth)
        {
            var pinStart = new Point(0, 0);
            var pinEnd = pinStart + (offset * (1 + (2 * pinWidth / offset.Length)));
            var pinNormal = new Vector(pinEnd.Y, -pinEnd.X);
            pinNormal.Normalize();
            pinNormal *= pinWidth * 0.5;

            var pinPoints = new Point[4];
            pinPoints[0] = new Point(0, 0) + (pinNormal * 0.5);
            pinPoints[1] = new Point(0, 0) - (pinNormal * 0.5);
            pinPoints[2] = pinEnd - pinNormal;
            pinPoints[3] = pinEnd + pinNormal;

            var positions = new Point3DCollection(billboards.Count * 4);
            foreach (var bb in billboards)
            {
                Point4D screenPoint;
                if (!bb.WorldDepthOffset.Equals(0))
                {
                    var viewPoint = (Point4D)bb.Position * this.visualToProjection;
                    screenPoint = new Point4D(viewPoint.X, viewPoint.Y, viewPoint.Z + bb.WorldDepthOffset, viewPoint.W) * this.projectionToScreen;
                }
                else
                {
                    screenPoint = (Point4D)bb.Position * this.visualToScreen;
                }

                double spw = screenPoint.W;
                double spx = screenPoint.X;
                double spy = screenPoint.Y;
                double spz = screenPoint.Z - ((bb.DepthOffset - 1e-5) * spw);

                foreach (var pinPoint in pinPoints)
                {
                    var p = new Point4D(spx + (pinPoint.X * spw), spy + (pinPoint.Y * spw), spz, spw) * this.screenToVisual;
                    double wi = 1 / p.W;
                    positions.Add(new Point3D(p.X * wi, p.Y * wi, p.Z * wi));
                }
            }

            positions.Freeze();
            return positions;
        }
 public override void TerminateGesture(object sender, Gesture_Event_Args gEventArgs)
 {
     Card c = gEventArgs.GestureObjects[0] as Card;
     Menu_Sort_Box b = gEventArgs.GestureObjects[1] as Menu_Sort_Box;
     if (!gestureControler.Control.MainWindow.MenuLayer.IsButtonInOriginPos(b))
     {
         c.SortToGroup(b);
         Group_List.Add(b, c);
         My_Point point = gEventArgs.GesturePoints[0];
         Vector v = new Vector(c.PreviousPostion.X - c.CurrentPosition.X, c.PreviousPostion.Y - c.CurrentPosition.Y);
         v.Normalize();
         c.MoveCard(v.X * 150, v.Y * 150, 0.5);
     }
     if (Group_List.CardGroups.ContainsKey(b))
     {
         Card[] cards = Group_List.CardGroups[b].ToArray();
         foreach (Card cc in cards) { cc.Dehightlight(); }
     }
     base.TerminateGesture(sender,gEventArgs);
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     PathSegmentCollection retVal = new PathSegmentCollection();
     PointCollection pointCollection = value as PointCollection;
     if (RoundRadius > 0)
     {
         if (pointCollection != null && pointCollection.Count > 0)
         {
             retVal.Add(new LineSegment(pointCollection[0], true));
             double curSegmentArcUsed = 0;
             for (int i = 1; i < pointCollection.Count - 1; i++)
             {
                 double dist1 = DesignerGeometryHelper.DistanceBetweenPoints(pointCollection[i - 1], pointCollection[i]);
                 double dist2 = DesignerGeometryHelper.DistanceBetweenPoints(pointCollection[i], pointCollection[i + 1]);
                 if (dist1 - curSegmentArcUsed > RoundRadius &&
                     dist2 > RoundRadius)
                 {
                     //build rounded arc at line join.
                     curSegmentArcUsed = RoundRadius;
                     Vector firstSegmentPointingVector = new Vector(pointCollection[i].X - pointCollection[i - 1].X, pointCollection[i].Y - pointCollection[i - 1].Y);
                     Vector secondSegmentPointingVector = new Vector(pointCollection[i + 1].X - pointCollection[i].X, pointCollection[i + 1].Y - pointCollection[i].Y);
                     firstSegmentPointingVector.Normalize();
                     secondSegmentPointingVector.Normalize();
                     Point turningPoint1 = Point.Add(pointCollection[i - 1], Vector.Multiply(dist1 - RoundRadius, firstSegmentPointingVector));
                     Point turningPoint2 = Point.Add(pointCollection[i], Vector.Multiply(RoundRadius, secondSegmentPointingVector));
                     double crossProductZ = firstSegmentPointingVector.X * secondSegmentPointingVector.Y - firstSegmentPointingVector.Y * secondSegmentPointingVector.X;
                     retVal.Add(new LineSegment(turningPoint1, true));
                     retVal.Add(new ArcSegment(turningPoint2, new Size(RoundRadius, RoundRadius), 0, false, crossProductZ > 0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, true));
                 }
                 else
                 {
                     curSegmentArcUsed = 0;
                     retVal.Add(new LineSegment(pointCollection[i], true));
                 }
             }
             retVal.Add(new LineSegment(pointCollection[pointCollection.Count - 1], true));
         }
     }
     return retVal;
 }
示例#17
0
        /// <summary>
        /// Moves the customer towards the give location.
        /// </summary>
        public bool MoveTowardsLocation(System.Windows.Vector location)
        {
            if (Customer.Group == null)
            {
                return(false);
            }
            var cL = Customer.Location;

            var delta = new System.Windows.Vector(location.X - cL.X, location.Y - cL.Y);

            delta.Normalize();
            var target = System.Windows.Vector.Add(Customer.Location, delta);

            foreach (var road in Customer.Group.RoadsNear)
            {
                if (road.IsOnRoad(target))
                {
                    return(false);
                }
            }

            Customer.Location = target;
            return(true);
        }
示例#18
0
文件: VectorTest.cs 项目: nobled/mono
		public void Normalize ()
		{
			Vector v = new Vector (5, 5);
			v.Normalize ();

			Assert.AreEqual (v.X, v.Y);
			Assert.AreEqual (1, v.Length, DELTA);
		}
示例#19
0
 private static Vector Normalize(Vector v)
 {
     v.Normalize();
     Debug.Assert(IsGoodVector(v));
     return v;
 }
示例#20
0
文件: Graph.cs 项目: edealbag/bot
 private static Vector Normalize(Vector v)
 {
     v.Normalize();
       Debug.Assert(v.IsValid());
       return v;
 }
示例#21
0
 public static Vector GetPerpendicularLine(Vector line)
 {
     Vector perpendicularLine = new Vector(line.Y, -line.X);
     perpendicularLine.Normalize();
     return perpendicularLine;
 }
示例#22
0
        /// <summary>
        /// Sets the position of the node to p, while trying to keep the radius constant.
        /// Note that this is not always possible. In this case the radius is increased.
        /// 
        /// There is a twofold ambiguity in choosing the new center. We resolve by picking the one closer to the old center.
        /// Also note that there is a twofold ambiguitiy as to whether we pick the small or large arc.
        /// We keep this as it was. (Note that this is often not what the user desires... more control is
        /// provided through the arcedit tool.)
        /// </summary>
        /// <param name="p">Target point.</param>
        void SetAbsPosConstR(Point p)
        {
            if (IsBroken)
                return;
            if (r2 != null)
                return;     // currently unsupported

            // store the old center (in local coordinates)
            Point oldcenter;
            if (!GetArcCenter(out oldcenter))
                return;            

            // compute the starting point (=offset) and desired shift, in local coordinates
            Point offset;
            if (!GetStartPoint(out offset))
                return;
            // transform p into local coordinates
            TikzMatrix M;
            if (!parent.GetCurrentTransformAt(this, out M))
                return;
            Point ploc = M.Inverse().Transform(p);
            Vector relp = ploc - offset;    // this is, in local coordinates, the vector from start- to desired endpoint.

            // compute the new parameters          
            //double a1 = phi1.GetInCM() * 2 * Math.PI / 360, a2 = phi2.GetInCM() * 2 * Math.PI / 360, a = a2 - a1;  // angles in radians

            //double R = Math.Abs(.5 * relp.Length / Math.Sin(a / 2));
            //if (!(R < 50))
            //    return;

            // the new center lies on the line midpoint + lambda * normal
            Point midpoint = offset + relp / 2;
            Vector normal = new Vector(relp.Y, -relp.X);
            normal.Normalize();                        
            double alpha = Math.Atan2(relp.Y, relp.X);  // inclination of line offset -> p

            // the target parameters
            double R;
            double a1, a2;

            // check whether we can keep R constant
            if (relp.Length <= 2 * r1.GetInCM())
            {
                // Yes
                R = r1.GetInCM();                
                double d = Math.Sqrt(R * R - relp.LengthSquared / 4);
                // two center candidates
                Point c1 = midpoint + d * normal, c2 = midpoint - d * normal, c;
                // pick the one closer to old center                
                if ((oldcenter - c1).Length < (oldcenter - c2).Length)
                    c = c1;
                else
                    c = c2;

                // compute angles
                Vector v1 = offset - c, v2 = ploc - c;
                
                a1 = Math.Atan2(v1.Y, v1.X);
                a2 = Math.Atan2(v2.Y, v2.X);

                // account for large arc/small arc
                if ((Math.Abs(a1 - a2) > Math.PI) != IsLargeArc)
                {
                    a2 += 2 * Math.PI * Math.Sign(a1 - a2);
                }

            }
            else
            {
                // No -> adjust radius
                R = relp.Length / 2;                
                a1 = Math.PI + alpha;
                a2 = alpha;
            }
            
            r1.SetInCM(R);
            phi1.SetInCM(a1 * 180 / Math.PI);
            phi2.SetInCM(a2 * 180 / Math.PI);
        }
示例#23
0
        private PointF pointSurfaceCoor(double dist, bool down)
        {
            int    i             = 0;
            double droveDistance = 0;
            double upperDistance = 0;
            double lowerDistance = 0;
            PointF pointTmp      = new PointF();
            int    flag          = 0;

            for (i = 0; i < MainWindow.nacaProfile.Count - 1; i++)
            {
                if (flag == 1 && MainWindow.nacaProfile[i].X == 0 && MainWindow.nacaProfile[i].Y == 0)
                {
                    flag = 2;
                }
                if (flag == 0)
                {
                    upperDistance += MainWindow.GetDistanceBetween(MainWindow.nacaProfile[i], MainWindow.nacaProfile[i + 1]);
                    if (MainWindow.nacaProfile[i + 1].X == 0 ||
                        (MainWindow.nacaProfile[i].X <= MainWindow.A.X && MainWindow.nacaProfile[i + 1].X >= MainWindow.A.X))
                    {
                        flag = 1;
                    }
                }
                else if (flag == 2)
                {
                    lowerDistance += MainWindow.GetDistanceBetween(MainWindow.nacaProfile[i], MainWindow.nacaProfile[i + 1]);
                    if (MainWindow.nacaProfile[i + 1].X == 0 ||
                        (MainWindow.nacaProfile[i].X <= MainWindow.B.X && MainWindow.nacaProfile[i + 1].X >= MainWindow.B.X))
                    {
                        break;
                    }
                }
            }

            for (i = 0; i < MainWindow.nacaProfile.Count - 1; i++)
            {
                if (MainWindow.nacaProfile[i].Y >= 0 && MainWindow.nacaProfile[i + 1].Y > 0 && down)
                {
                    droveDistance += MainWindow.GetDistanceBetween(MainWindow.nacaProfile[i], MainWindow.nacaProfile[i + 1]);

                    if (droveDistance >= dist * lowerDistance)
                    {
                        System.Windows.Vector v = new System.Windows.Vector(MainWindow.nacaProfile[i].X - MainWindow.nacaProfile[i + 1].X,
                                                                            MainWindow.nacaProfile[i].Y - MainWindow.nacaProfile[i + 1].Y);
                        v.Normalize();
                        v = System.Windows.Vector.Multiply(droveDistance - dist * lowerDistance, v);

                        pointTmp = new PointF((float)(MainWindow.nacaProfile[i + 1].X + v.X), (float)(MainWindow.nacaProfile[i + 1].Y + v.Y));
                        break;
                    }
                }
                else if (MainWindow.nacaProfile[i].Y <= 0 && MainWindow.nacaProfile[i + 1].Y < 0 && !down)
                {
                    droveDistance += MainWindow.GetDistanceBetween(MainWindow.nacaProfile[i], MainWindow.nacaProfile[i + 1]);

                    if (droveDistance >= dist * upperDistance)
                    {
                        System.Windows.Vector v = new System.Windows.Vector(MainWindow.nacaProfile[i].X - MainWindow.nacaProfile[i + 1].X,
                                                                            MainWindow.nacaProfile[i].Y - MainWindow.nacaProfile[i + 1].Y);
                        v.Normalize();
                        v = System.Windows.Vector.Multiply(droveDistance - dist * upperDistance, v);

                        pointTmp = new PointF((float)(MainWindow.nacaProfile[i + 1].X + v.X), (float)(MainWindow.nacaProfile[i + 1].Y + v.Y));
                        break;
                    }
                }
            }

            double d = MainWindow.GetDistanceBetween(point1.Point, point1.Point);

            if (MainWindow.PercentRealLenght == 100)
            {
                MainWindow.PercentRealLenght = 99.999f;
            }
            d = (d / MainWindow.PercentRealLenght) * 100;

            pointTmp.X *= (float)d;
            pointTmp.Y *= (float)d;

            return(pointTmp);
        }
        void DoArrow(Point3D pt1, Point3D pt2, Point3DCollection points, 
                     Int32Collection indices, ref int indicesBase)
        {
            Point3D pt1Screen = pt1 * matxVisualToScreen;
            Point3D pt2Screen = pt2 * matxVisualToScreen;

            Vector vectArrow = new Vector(pt1Screen.X - pt2Screen.X,
                                          pt1Screen.Y - pt2Screen.Y);
            vectArrow.Normalize();
            vectArrow *= ArrowLength;

            Matrix matx = new Matrix();
            matx.Rotate(ArrowAngle / 2);
            Point3D ptArrow1 = Widen(pt2, vectArrow * matx);
            matx.Rotate(-ArrowAngle);
            Point3D ptArrow2 = Widen(pt2, vectArrow * matx);

            DoLine(pt2, ptArrow1, points, indices, ref indicesBase);
            DoLine(pt2, ptArrow2, points, indices, ref indicesBase);
        }
示例#25
0
        public override Vector Reflect(Vector vecIn, Vector hitPoint, Vector ballpos)
        {
            Vector dLine = this.target - this.Position;
            Vector normal = new Vector(-dLine.Y,dLine.X);

            if (hitPoint == this.Position + this.BoundingContainer.ParentElement.Location)
            {
                normal = ballpos - (this.Position + this.BoundingContainer.ParentElement.Location);
            }

            if (hitPoint == this.target + this.BoundingContainer.ParentElement.Location)
            {
                normal = ballpos - (this.target + this.BoundingContainer.ParentElement.Location);
            }

            normal.Normalize();

            return ReflectVector(ref vecIn, ref normal);
        }
示例#26
0
        public override Vector GetOutOfAreaPush(int diameterBall, Vector hitPoint, Vector velocity, Vector ballPos)
        {
            //check if hit at the end (corner reflection must be handled with less simplification
            if (hitPoint == this.Position + this.BoundingContainer.ParentElement.Location)
            {
                Vector t = ballPos + new Vector(diameterBall / 2f, diameterBall / 2f) - (this.Position + this.BoundingContainer.ParentElement.Location);
                if (t.X == 0 && t.Y == 0)
                {
                    return NormalizeVector(velocity) * (diameterBall / pushBackByPointsCoefficient);
                }
                return (diameterBall / pushBackByPointsCoefficient) * NormalizeVector(t);
            }

            if (hitPoint == this.target + this.BoundingContainer.ParentElement.Location)
            {
                Vector t = NormalizeVector(ballPos + new Vector(diameterBall / 2f, diameterBall / 2f) - (this.target + this.BoundingContainer.ParentElement.Location));
                if (t.X == 0 && t.Y == 0)
                {
                    return NormalizeVector(velocity) * (diameterBall / pushBackByPointsCoefficient);
                }
                return (diameterBall / pushBackByPointsCoefficient) * NormalizeVector(t);
            }

            //now check which normal we have to take (depends on velocity)
            Vector norm = NormalizeVector((this.target - this.Position).Normal());
            Vector dLine = this.target - this.Position;

            double d = Vector.Multiply((velocity), NormalizeVector(dLine));    //distance on dLine from pos to the point where the normal from velocity hits

            Vector q = d * NormalizeVector(dLine);       //point where normal on dline through Velocity point hits
            Vector h = velocity-q;         //horizontal line through velocitiy point and  normal on dline

            //if h and normal have not same sign => take other normal (so we move in right direction)
            if (h.X * norm.X < 0 || h.Y * norm.Y < 0)
            {
                norm = -norm;
            }

            if (d == 0)
            {
                //vertical
                norm = velocity;
                if (velocity.X == 0 && velocity.Y == 0)
                {
                    //Bug velocity 0 with collision
                    norm.X = 1;
                }
                norm.Normalize();
            }
            return (diameterBall / pushBackByLineCoefficient) * norm;
        }
示例#27
0
        /// <summary>
        /// Finds the approximante tangent at a given StylusPoint
        /// </summary>
        /// <param name="ptT">Tangent vector</param>
        /// <param name="nAt">Index at which the tangent is calculated</param>
        /// <param name="nPrevCusp">Index of the previous cusp</param>
        /// <param name="nNextCusp">Index of the next cusp</param>
        /// <param name="bReverse">Forward or reverse tangent</param>
        /// <param name="bIsCusp">Whether the current idex is a cusp StylusPoint</param>
        /// <returns>Return whether the tangent computation succeeded</returns>
        internal bool Tangent(ref Vector ptT, int nAt, int nPrevCusp, int nNextCusp, bool bReverse, bool bIsCusp)
        {
            // Tangent is computed as the unit vector along 
            // PT = (P1 - P0) + (P2 - P0) + (P3 - P0)
            // => PT = P1 + P2 + P3 - 3 * P0
            int i_1, i_2, i_3;

            if (bIsCusp)
            {
                if (bReverse)
                {
                    i_1 = _points[nAt].TanPrev;
                    if (i_1 < nPrevCusp || (0 > i_1))
                    {
                        i_2 = nPrevCusp;
                        i_1 = (i_2 + nAt) / 2;
                    }
                    else
                    {
                        i_2 = _points[i_1].TanPrev;
                        if (i_2 < nPrevCusp)
                            i_2 = nPrevCusp;
                    }
                }
                else
                {
                    i_1 = _points[nAt].TanNext;
                    if (i_1 > nNextCusp || (0 > i_1))
                    {
                        i_2 = nNextCusp;
                        i_1 = (i_2 + nAt) / 2;
                    }
                    else
                    {
                        i_2 = _points[i_1].TanNext;
                        if (i_2 > nNextCusp)
                            i_2 = nNextCusp;
                    }
                }
                ptT = XY(i_1) + 0.5 * XY(i_2) - 1.5 * XY(nAt);
            }
            else
            {
                Debug.Assert(bReverse);
                i_1 = nAt;
                i_2 = _points[nAt].TanPrev;
                if (i_2 < nPrevCusp)
                {
                    i_3 = nPrevCusp;
                    i_2 = (i_3 + i_1) / 2;
                }
                else
                {
                    i_3 = _points[i_2].TanPrev;
                    if (i_3 < nPrevCusp)
                        i_3 = nPrevCusp;
                }

                nAt = _points[nAt].TanNext;
                if (nAt > nNextCusp)
                    nAt = nNextCusp;

                ptT = XY(i_1) + XY(i_2) + 0.5 * XY(i_3) - 2.5 * XY(nAt);
            }

            if (DoubleUtil.IsZero(ptT.LengthSquared))
            {
                return false;
            }

            ptT.Normalize();
            return true;
        }
示例#28
0
		private Triangle CreateTriangle(Point position, Vector direction)
		{
			direction.Normalize();
			direction *= vectorLength;

			Point p1 = position + 1.7 / 3 * direction;
			Point basePoint = position - 0.3333333 * direction;
			var perpendicular = direction.Perpendicular();
			perpendicular.Normalize();
			perpendicular *= 0.166666666666;
			Point p2 = basePoint + perpendicular;
			Point p3 = basePoint - perpendicular;

			Triangle triangle = trianglesPool.GetOrCreate();
			triangle.Point1 = new Point3D(p1.X, p1.Y, 0);
			triangle.Point2 = new Point3D(p2.X, p2.Y, 0);
			triangle.Point3 = new Point3D(p3.X, p3.Y, 0);
			return triangle;
		}
示例#29
0
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            var li = sender as RadioButton;

            // Strings used to display results
            string syntaxString, resultType, operationString;

            switch (li?.Name)
            {
                //begin switch

                case "rb1":
                {
                    // Translates a Point by a Vector using the overloaded + operator.

                    var point1 = new Point(10, 5);
                    var vector1 = new System.Windows.Vector(20, 30);

                    var pointResult = point1 + vector1;

                    // pointResult is equal to (-10,-25) 

                    // Displaying Results
                    syntaxString = "pointResult = point1 + vector1;";
                    resultType = "Point";
                    operationString = "Translating a Point by a Vector";
                    ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb2":
                {
                    // Adds a Vector to a Vector using the overloaded + operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);


                    // vectorResult is equal to (65,100)
                    var vectorResult = vector1 + vector2;


                    // Displaying Results
                    syntaxString = "vectorResult = vector1 + vector2;";
                    resultType = "Vector";
                    operationString = "Adding a Vector to a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb3":
                {
                    // Adds a Vector to a Vector using the static Add method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var vectorResult = System.Windows.Vector.Add(vector1, vector2);

                    // vectorResult is equal to (65,100)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Add(vector1, vector2);";
                    resultType = "Vector";
                    operationString = "Adding a Vector to a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb4":
                {
                    // Translates a Point by a Vector using the static Add method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var point1 = new Point(10, 5);

                    var pointResult = System.Windows.Vector.Add(vector1, point1);

                    // vectorResult is equal to (30,35)

                    // Displaying Results
                    syntaxString = "pointResult = Vector.Add(vector1, point1);";
                    resultType = "Point";
                    operationString = "Translating a Point by a Vector";
                    ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb5":
                {
                    // Subtracts a Vector from a Vector using the overloaded - operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var vectorResult = vector1 - vector2;

                    // vector Result is equal to (-25, -40)

                    // Displaying Results 
                    syntaxString = "vectorResult = vector1 - vector2;";
                    resultType = "Vector";
                    operationString = "Subtracting a Vector from a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb6":
                {
                    // Subtracts a Vector from a Vector using the static Subtract method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var vectorResult = System.Windows.Vector.Subtract(vector1, vector2);

                    // vector Result is equal to (-25, -40)

                    // Displaying Results
                    syntaxString = "Vector.Subtract(vector1, vector2);";
                    resultType = "Vector";
                    operationString = "Subtracting a Vector from a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb7":
                {
                    // Multiplies a Vector by a Scalar using the overloaded * operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = vector1*scalar1;

                    // vectorResult is equal to (1500,2250)

                    // Displaying Results
                    syntaxString = "vectorResult = vector1 * scalar1;";
                    resultType = "Vector";
                    operationString = "Multiplies a Vector by a Scalar";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb8":
                {
                    // Multiplies a Scalar by a Vector using the overloaded * operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = scalar1*vector1;

                    // vectorResult is equal to (1500,2250)

                    // Displaying Results
                    syntaxString = "vectorResult = scalar1 * vector1;";
                    resultType = "Vector";
                    operationString = "Multiplies a Scalar by a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb9":
                {
                    // Multiplies a Vector by a Vector using the overloaded * operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var doubleResult = vector1*vector2;

                    // doubleResult is equal to 3000

                    // Displaying Results
                    syntaxString = "doubleResult = vector1 * vector2;";
                    resultType = "Double";
                    operationString = "Multiplies a Vector by a Vector";
                    ShowResults(doubleResult.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }

                case "rb10":
                {
                    // Multiplies a Vector by a Matrix using the overloaded * operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                    var vectorResult = vector1*matrix1;

                    // vector Result is equal to (2600,3100)


                    // Displaying Results
                    syntaxString = "vectorResult = vector1 * matrix1;";
                    resultType = "Vector";
                    operationString = "Multiplies a Vector by a Matrix";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb11":
                {
                    // Multiplies a Vector by a Scalar using the static Multiply method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = System.Windows.Vector.Multiply(vector1, scalar1);

                    // vectorResult is equal to (1500,2250)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Multiply(vector1, scalar1);";
                    resultType = "Vector";
                    operationString = "Multiplies a Vector by a Scalar";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb12":
                {
                    // Multiplies a Scalar by a Vector using the static Multiply method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = System.Windows.Vector.Multiply(scalar1, vector1);

                    // vectorResult is equal to (1500,2250)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Multiply(scalar1, vector1);";
                    resultType = "Vector";
                    operationString = "Multiplies a Scalar by a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb13":
                {
                    // Multiplies a Vector by a Vector using the static Multiply method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var doubleResult = System.Windows.Vector.Multiply(vector1, vector2);

                    // doubleResult is equal to 3000

                    // Displaying Results
                    syntaxString = "DoubleResult = Vector.Multiply(vector1,vector2);";
                    resultType = "Double";
                    operationString = "Multiplies a Vector by a Vector";
                    ShowResults(doubleResult.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }

                case "rb14":
                {
                    // Multiplies a Vector by a Matrix using the static Multiply method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                    var vectorResult = System.Windows.Vector.Multiply(vector1, matrix1);

                    // vector Result is equal to (2600,3100)


                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Multiply(vector1,matrix1);";
                    resultType = "Vector";
                    operationString = "Multiplies a Vector by a Matrix";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb15":
                {
                    // Divides a Vector by a Scalar using the overloaded / operator.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = vector1/scalar1;

                    // vectorResult is approximately equal to (0.26667,0.4)

                    // Displaying Results
                    syntaxString = "vectorResult = vector1 / scalar1;";
                    resultType = "Vector";
                    operationString = "Dividing a Vector by a Scalar";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb16":
                {
                    // Divides a Vector by a Double using the static Divide method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    double scalar1 = 75;

                    var vectorResult = System.Windows.Vector.Divide(vector1, scalar1);

                    // vectorResult is approximately equal to (0.26667,0.4)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Divide(vector1, scalar1);";
                    resultType = "Vector";
                    operationString = "Dividing a Vector by a Scalar";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb17":
                {
                    // Gets the hashcode of a Vector structure

                    var vector1 = new System.Windows.Vector(20, 30);

                    var vectorHashCode = vector1.GetHashCode();

                    // Displaying Results
                    syntaxString = "vectorHashCode = vector1.GetHashCode();";
                    resultType = "int";
                    operationString = "Getting the hashcode of a Vector";
                    ShowResults(vectorHashCode.ToString(), syntaxString, resultType, operationString);
                    break;
                }


                case "rb18":
                {
                    // Gets the length of a Vector.  

                    var vector1 = new System.Windows.Vector(20, 30);

                    var length = vector1.Length;

                    // length is approximately equal to 36.0555


                    // Displaying Results
                    syntaxString = "length = vector1.Length();";
                    resultType = "Double";
                    operationString = "Getting the length of a Vector";
                    ShowResults(length.ToString(CultureInfo.InvariantCulture), syntaxString, resultType, operationString);
                    break;
                }

                case "rb19":
                {
                    // Gets the square of the length of a Vector.  

                    var vector1 = new System.Windows.Vector(20, 30);

                    var lengthSq = vector1.LengthSquared;

                    // lengthSq is equal to 1300

                    // Displaying Results
                    syntaxString = "lengthSq = vector1.LengthSquared;";
                    resultType = "Double";
                    operationString = "Getting the length square of a Vector";
                    ShowResults(lengthSq.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }
                case "rb20":
                {
                    // Normalizes a Vector using the Normalize method.  

                    var vector1 = new System.Windows.Vector(20, 30);

                    vector1.Normalize();

                    // vector1 is approximately equal to (0.5547,0.8321) 

                    // Displaying Results
                    syntaxString = "vector1.Normalize();";
                    resultType = "Vector";
                    operationString = "Normalizing a Vector";
                    ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb21":
                {
                    // Calculates the angle between two Vectors using the static AngleBetween method. 

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var angleBetween = System.Windows.Vector.AngleBetween(vector1, vector2);

                    // angleBetween is approximately equal to 0.9548

                    // Displaying Results
                    syntaxString = "angleBetween = Vector.AngleBetween(vector1, vector2);";
                    resultType = "Double";
                    operationString = "Calculating the angle between two Vectors";
                    ShowResults(angleBetween.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }

                case "rb22":
                {
                    // Calculates the cross product of two Vectors using the static  CrossProduct method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var crossProduct = System.Windows.Vector.CrossProduct(vector1, vector2);

                    // crossProduct is equal to 50

                    // Displaying Results
                    syntaxString = "crossProduct = Vector.CrossProduct(vector1,vector2);";
                    resultType = "Double";
                    operationString = "Calculating the crossproduct of two Vectors";
                    ShowResults(crossProduct.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }


                case "rb23":
                {
                    // Calculates the determinant of two Vectors using the static Determinant method.  

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var determinant = System.Windows.Vector.Determinant(vector1, vector2);

                    // determinant is equal to 50

                    // Displaying Results
                    syntaxString = "determinant = Vector.Determinant(vector1, vector2);";
                    resultType = "Double";
                    operationString = "Calculating the determinant of two Vectors";
                    ShowResults(determinant.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                        operationString);
                    break;
                }


                case "rb24":
                {
                    // Checks if two Vectors are equal using the overloaded equality operator.

                    // Declaring vecto1 and initializing x,y values
                    var vector1 = new System.Windows.Vector(20, 30);

                    // Declaring vector2 without initializing x,y values
                    var vector2 = new System.Windows.Vector
                    {
                        X = 45,
                        Y = 70
                    };

                    // Boolean to hold the result of the comparison

                    // assigning values to vector2

                    // Comparing Vectors for equality
                    var areEqual = (vector1 == vector2);

                    // areEqual is False

                    // Displaying Results
                    syntaxString = "areEqual = (vector1 == vector2);";
                    resultType = "Boolean";
                    operationString = "Checking if two vectors are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }


                case "rb25":
                {
                    // Checks if two Vectors are equal using the static Equals method.

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var areEqual = System.Windows.Vector.Equals(vector1, vector2);

                    // areEqual is False    

                    // Displaying Results
                    syntaxString = "areEqual = Vector.Equals(vector1, vector2);";
                    resultType = "Boolean";
                    operationString = "Checking if two vectors are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb26":
                {
                    // Compares an Object and a Vector for equality using the non-static Equals method.

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var areEqual = vector1.Equals(vector2);

                    // areEqual is False    


                    // Displaying Results
                    syntaxString = "areEqual = vector1.Equals(vector2);";
                    resultType = "Boolean";
                    operationString = "Checking if two vectors are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb27":
                {
                    // Converts a string representation of a vector into a Vector structure

                    var vectorResult = System.Windows.Vector.Parse("1,3");

                    // vectorResult is equal to (1,3)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Parse(\"1,3\");";
                    resultType = "Vector";
                    operationString = "Converting a string into a Vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb28":
                {
                    // Checks if two Vectors are not equal using the overloaded inequality operator.

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    var areNotEqual = (vector1 != vector2);

                    // areNotEqual is True

                    // Displaying Results
                    syntaxString = "areNotEqual = (vector1 != vector2);";
                    resultType = "Boolean";
                    operationString = "Checking if two points are not equal";
                    ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb29":
                {
                    // Negates a Vector using the Negate method.

                    var vector1 = new System.Windows.Vector(20, 30);

                    vector1.Negate();

                    // vector1 is equal to (-20, -30)

                    // Displaying Results
                    syntaxString = "vector1.Negate();";
                    resultType = "void";
                    operationString = "Negating a vector";
                    ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb30":
                {
                    // Negates a Vector using the overloaded unary negation operator.

                    var vector1 = new System.Windows.Vector(20, 30);

                    var vectorResult = -vector1;

                    // vectorResult is equal to (-20, -30)

                    // Displaying Results
                    syntaxString = "vectorResult = -vector1;";
                    resultType = "Vector";
                    operationString = "Negating a vector";
                    ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb31":
                {
                    // Gets a String representation of a Vector structure

                    var vector1 = new System.Windows.Vector(20, 30);

                    var vectorString = vector1.ToString();

                    // vectorString is equal to 10,5

                    // Displaying Results
                    syntaxString = "vectorString = vector1.ToString();";
                    resultType = "String";
                    operationString = "Getting the string representation of a Vector";
                    ShowResults(vectorString, syntaxString, resultType, operationString);
                    break;
                }
                case "rb32":
                {
                    // Explicitly converts a Vector structure into a Size structure
                    // Returns a Size.

                    var vector1 = new System.Windows.Vector(20, 30);

                    var size1 = (Size) vector1;

                    // size1 has a width of 20 and a height of 30

                    // Displaying Results
                    syntaxString = "size1 = (Size)vector1;";
                    resultType = "Size";
                    operationString = "Expliciting casting a Vector into a Size";
                    ShowResults(size1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb33":
                {
                    // Explicitly converts a Vector structure into a Point structure
                    // Returns a Point.

                    var vector1 = new System.Windows.Vector(20, 30);

                    var point1 = (Point) vector1;

                    // point1 is equal to (20, 30)

                    // Displaying Results
                    syntaxString = "point1 = (Point)vector1;";
                    resultType = "Point";
                    operationString = "Expliciting casting a Vector into a Point";
                    ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                // task example.  this case statement is not referenced from the list of radio buttons
                case "rb40":
                {
                    // adds two vectors using Add and +

                    var vector1 = new System.Windows.Vector(20, 30);
                    var vector2 = new System.Windows.Vector(45, 70);

                    vector1 = vector1 + vector2;
                    // vector1 is now equal to (65, 100)

                    vector1 = System.Windows.Vector.Add(vector1, vector2);
                    // vector1 is now equal to (110, 170)

                    // Displaying Results
                    syntaxString = "vectorResult = Vector.Negate(vector1);";
                    resultType = "Vector";
                    operationString = "Negating a vector";
                    ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
            } // end switch
        }
示例#30
0
        protected Vector NormalizeVector(Vector v)
        {
            var vector = new Vector(v.X, v.Y);
            vector.Normalize();

            return vector;
        }
示例#31
0
 private Vector _normalize(Vector v) {
    v.Normalize();
    return v;
 }
示例#32
0
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            var li = sender as RadioButton;

            // Strings used to display results
            string syntaxString, resultType, operationString;

            switch (li?.Name)
            {
            //begin switch

            case "rb1":
            {
                // Translates a Point by a Vector using the overloaded + operator.

                var point1  = new Point(10, 5);
                var vector1 = new System.Windows.Vector(20, 30);

                var pointResult = point1 + vector1;

                // pointResult is equal to (-10,-25)

                // Displaying Results
                syntaxString    = "pointResult = point1 + vector1;";
                resultType      = "Point";
                operationString = "Translating a Point by a Vector";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb2":
            {
                // Adds a Vector to a Vector using the overloaded + operator.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);


                // vectorResult is equal to (65,100)
                var vectorResult = vector1 + vector2;


                // Displaying Results
                syntaxString    = "vectorResult = vector1 + vector2;";
                resultType      = "Vector";
                operationString = "Adding a Vector to a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb3":
            {
                // Adds a Vector to a Vector using the static Add method.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var vectorResult = System.Windows.Vector.Add(vector1, vector2);

                // vectorResult is equal to (65,100)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Add(vector1, vector2);";
                resultType      = "Vector";
                operationString = "Adding a Vector to a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb4":
            {
                // Translates a Point by a Vector using the static Add method.

                var vector1 = new System.Windows.Vector(20, 30);
                var point1  = new Point(10, 5);

                var pointResult = System.Windows.Vector.Add(vector1, point1);

                // vectorResult is equal to (30,35)

                // Displaying Results
                syntaxString    = "pointResult = Vector.Add(vector1, point1);";
                resultType      = "Point";
                operationString = "Translating a Point by a Vector";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb5":
            {
                // Subtracts a Vector from a Vector using the overloaded - operator.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var vectorResult = vector1 - vector2;

                // vector Result is equal to (-25, -40)

                // Displaying Results
                syntaxString    = "vectorResult = vector1 - vector2;";
                resultType      = "Vector";
                operationString = "Subtracting a Vector from a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb6":
            {
                // Subtracts a Vector from a Vector using the static Subtract method.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var vectorResult = System.Windows.Vector.Subtract(vector1, vector2);

                // vector Result is equal to (-25, -40)

                // Displaying Results
                syntaxString    = "Vector.Subtract(vector1, vector2);";
                resultType      = "Vector";
                operationString = "Subtracting a Vector from a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb7":
            {
                // Multiplies a Vector by a Scalar using the overloaded * operator.

                var    vector1 = new System.Windows.Vector(20, 30);
                double scalar1 = 75;

                var vectorResult = vector1 * scalar1;

                // vectorResult is equal to (1500,2250)

                // Displaying Results
                syntaxString    = "vectorResult = vector1 * scalar1;";
                resultType      = "Vector";
                operationString = "Multiplies a Vector by a Scalar";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb8":
            {
                // Multiplies a Scalar by a Vector using the overloaded * operator.

                var    vector1 = new System.Windows.Vector(20, 30);
                double scalar1 = 75;

                var vectorResult = scalar1 * vector1;

                // vectorResult is equal to (1500,2250)

                // Displaying Results
                syntaxString    = "vectorResult = scalar1 * vector1;";
                resultType      = "Vector";
                operationString = "Multiplies a Scalar by a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb9":
            {
                // Multiplies a Vector by a Vector using the overloaded * operator.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var doubleResult = vector1 * vector2;

                // doubleResult is equal to 3000

                // Displaying Results
                syntaxString    = "doubleResult = vector1 * vector2;";
                resultType      = "Double";
                operationString = "Multiplies a Vector by a Vector";
                ShowResults(doubleResult.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                            operationString);
                break;
            }

            case "rb10":
            {
                // Multiplies a Vector by a Matrix using the overloaded * operator.

                var vector1 = new System.Windows.Vector(20, 30);
                var matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                var vectorResult = vector1 * matrix1;

                // vector Result is equal to (2600,3100)


                // Displaying Results
                syntaxString    = "vectorResult = vector1 * matrix1;";
                resultType      = "Vector";
                operationString = "Multiplies a Vector by a Matrix";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb11":
            {
                // Multiplies a Vector by a Scalar using the static Multiply method.

                var    vector1 = new System.Windows.Vector(20, 30);
                double scalar1 = 75;

                var vectorResult = System.Windows.Vector.Multiply(vector1, scalar1);

                // vectorResult is equal to (1500,2250)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Multiply(vector1, scalar1);";
                resultType      = "Vector";
                operationString = "Multiplies a Vector by a Scalar";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb12":
            {
                // Multiplies a Scalar by a Vector using the static Multiply method.

                var    vector1 = new System.Windows.Vector(20, 30);
                double scalar1 = 75;

                var vectorResult = System.Windows.Vector.Multiply(scalar1, vector1);

                // vectorResult is equal to (1500,2250)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Multiply(scalar1, vector1);";
                resultType      = "Vector";
                operationString = "Multiplies a Scalar by a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb13":
            {
                // Multiplies a Vector by a Vector using the static Multiply method.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var doubleResult = System.Windows.Vector.Multiply(vector1, vector2);

                // doubleResult is equal to 3000

                // Displaying Results
                syntaxString    = "DoubleResult = Vector.Multiply(vector1,vector2);";
                resultType      = "Double";
                operationString = "Multiplies a Vector by a Vector";
                ShowResults(doubleResult.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                            operationString);
                break;
            }

            case "rb14":
            {
                // Multiplies a Vector by a Matrix using the static Multiply method.

                var vector1 = new System.Windows.Vector(20, 30);
                var matrix1 = new Matrix(40, 50, 60, 70, 80, 90);

                var vectorResult = System.Windows.Vector.Multiply(vector1, matrix1);

                // vector Result is equal to (2600,3100)


                // Displaying Results
                syntaxString    = "vectorResult = Vector.Multiply(vector1,matrix1);";
                resultType      = "Vector";
                operationString = "Multiplies a Vector by a Matrix";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb15":
            {
                // Divides a Vector by a Scalar using the overloaded / operator.

                var    vector1 = new System.Windows.Vector(20, 30);
                double scalar1 = 75;

                var vectorResult = vector1 / scalar1;

                // vectorResult is approximately equal to (0.26667,0.4)

                // Displaying Results
                syntaxString    = "vectorResult = vector1 / scalar1;";
                resultType      = "Vector";
                operationString = "Dividing a Vector by a Scalar";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb16":
            {
                // Divides a Vector by a Double using the static Divide method.

                var    vector1 = new System.Windows.Vector(20, 30);
                double scalar1 = 75;

                var vectorResult = System.Windows.Vector.Divide(vector1, scalar1);

                // vectorResult is approximately equal to (0.26667,0.4)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Divide(vector1, scalar1);";
                resultType      = "Vector";
                operationString = "Dividing a Vector by a Scalar";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb17":
            {
                // Gets the hashcode of a Vector structure

                var vector1 = new System.Windows.Vector(20, 30);

                var vectorHashCode = vector1.GetHashCode();

                // Displaying Results
                syntaxString    = "vectorHashCode = vector1.GetHashCode();";
                resultType      = "int";
                operationString = "Getting the hashcode of a Vector";
                ShowResults(vectorHashCode.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb18":
            {
                // Gets the length of a Vector.

                var vector1 = new System.Windows.Vector(20, 30);

                var length = vector1.Length;

                // length is approximately equal to 36.0555


                // Displaying Results
                syntaxString    = "length = vector1.Length();";
                resultType      = "Double";
                operationString = "Getting the length of a Vector";
                ShowResults(length.ToString(CultureInfo.InvariantCulture), syntaxString, resultType, operationString);
                break;
            }

            case "rb19":
            {
                // Gets the square of the length of a Vector.

                var vector1 = new System.Windows.Vector(20, 30);

                var lengthSq = vector1.LengthSquared;

                // lengthSq is equal to 1300

                // Displaying Results
                syntaxString    = "lengthSq = vector1.LengthSquared;";
                resultType      = "Double";
                operationString = "Getting the length square of a Vector";
                ShowResults(lengthSq.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                            operationString);
                break;
            }

            case "rb20":
            {
                // Normalizes a Vector using the Normalize method.

                var vector1 = new System.Windows.Vector(20, 30);

                vector1.Normalize();

                // vector1 is approximately equal to (0.5547,0.8321)

                // Displaying Results
                syntaxString    = "vector1.Normalize();";
                resultType      = "Vector";
                operationString = "Normalizing a Vector";
                ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb21":
            {
                // Calculates the angle between two Vectors using the static AngleBetween method.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var angleBetween = System.Windows.Vector.AngleBetween(vector1, vector2);

                // angleBetween is approximately equal to 0.9548

                // Displaying Results
                syntaxString    = "angleBetween = Vector.AngleBetween(vector1, vector2);";
                resultType      = "Double";
                operationString = "Calculating the angle between two Vectors";
                ShowResults(angleBetween.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                            operationString);
                break;
            }

            case "rb22":
            {
                // Calculates the cross product of two Vectors using the static  CrossProduct method.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var crossProduct = System.Windows.Vector.CrossProduct(vector1, vector2);

                // crossProduct is equal to 50

                // Displaying Results
                syntaxString    = "crossProduct = Vector.CrossProduct(vector1,vector2);";
                resultType      = "Double";
                operationString = "Calculating the crossproduct of two Vectors";
                ShowResults(crossProduct.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                            operationString);
                break;
            }


            case "rb23":
            {
                // Calculates the determinant of two Vectors using the static Determinant method.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var determinant = System.Windows.Vector.Determinant(vector1, vector2);

                // determinant is equal to 50

                // Displaying Results
                syntaxString    = "determinant = Vector.Determinant(vector1, vector2);";
                resultType      = "Double";
                operationString = "Calculating the determinant of two Vectors";
                ShowResults(determinant.ToString(CultureInfo.InvariantCulture), syntaxString, resultType,
                            operationString);
                break;
            }


            case "rb24":
            {
                // Checks if two Vectors are equal using the overloaded equality operator.

                // Declaring vecto1 and initializing x,y values
                var vector1 = new System.Windows.Vector(20, 30);

                // Declaring vector2 without initializing x,y values
                var vector2 = new System.Windows.Vector
                {
                    X = 45,
                    Y = 70
                };

                // Boolean to hold the result of the comparison

                // assigning values to vector2

                // Comparing Vectors for equality
                var areEqual = (vector1 == vector2);

                // areEqual is False

                // Displaying Results
                syntaxString    = "areEqual = (vector1 == vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two vectors are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb25":
            {
                // Checks if two Vectors are equal using the static Equals method.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var areEqual = System.Windows.Vector.Equals(vector1, vector2);

                // areEqual is False

                // Displaying Results
                syntaxString    = "areEqual = Vector.Equals(vector1, vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two vectors are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb26":
            {
                // Compares an Object and a Vector for equality using the non-static Equals method.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var areEqual = vector1.Equals(vector2);

                // areEqual is False


                // Displaying Results
                syntaxString    = "areEqual = vector1.Equals(vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two vectors are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb27":
            {
                // Converts a string representation of a vector into a Vector structure

                var vectorResult = System.Windows.Vector.Parse("1,3");

                // vectorResult is equal to (1,3)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Parse(\"1,3\");";
                resultType      = "Vector";
                operationString = "Converting a string into a Vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb28":
            {
                // Checks if two Vectors are not equal using the overloaded inequality operator.

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                var areNotEqual = (vector1 != vector2);

                // areNotEqual is True

                // Displaying Results
                syntaxString    = "areNotEqual = (vector1 != vector2);";
                resultType      = "Boolean";
                operationString = "Checking if two points are not equal";
                ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb29":
            {
                // Negates a Vector using the Negate method.

                var vector1 = new System.Windows.Vector(20, 30);

                vector1.Negate();

                // vector1 is equal to (-20, -30)

                // Displaying Results
                syntaxString    = "vector1.Negate();";
                resultType      = "void";
                operationString = "Negating a vector";
                ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb30":
            {
                // Negates a Vector using the overloaded unary negation operator.

                var vector1 = new System.Windows.Vector(20, 30);

                var vectorResult = -vector1;

                // vectorResult is equal to (-20, -30)

                // Displaying Results
                syntaxString    = "vectorResult = -vector1;";
                resultType      = "Vector";
                operationString = "Negating a vector";
                ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb31":
            {
                // Gets a String representation of a Vector structure

                var vector1 = new System.Windows.Vector(20, 30);

                var vectorString = vector1.ToString();

                // vectorString is equal to 10,5

                // Displaying Results
                syntaxString    = "vectorString = vector1.ToString();";
                resultType      = "String";
                operationString = "Getting the string representation of a Vector";
                ShowResults(vectorString, syntaxString, resultType, operationString);
                break;
            }

            case "rb32":
            {
                // Explicitly converts a Vector structure into a Size structure
                // Returns a Size.

                var vector1 = new System.Windows.Vector(20, 30);

                var size1 = (Size)vector1;

                // size1 has a width of 20 and a height of 30

                // Displaying Results
                syntaxString    = "size1 = (Size)vector1;";
                resultType      = "Size";
                operationString = "Expliciting casting a Vector into a Size";
                ShowResults(size1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb33":
            {
                // Explicitly converts a Vector structure into a Point structure
                // Returns a Point.

                var vector1 = new System.Windows.Vector(20, 30);

                var point1 = (Point)vector1;

                // point1 is equal to (20, 30)

                // Displaying Results
                syntaxString    = "point1 = (Point)vector1;";
                resultType      = "Point";
                operationString = "Expliciting casting a Vector into a Point";
                ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            // task example.  this case statement is not referenced from the list of radio buttons
            case "rb40":
            {
                // adds two vectors using Add and +

                var vector1 = new System.Windows.Vector(20, 30);
                var vector2 = new System.Windows.Vector(45, 70);

                vector1 = vector1 + vector2;
                // vector1 is now equal to (65, 100)

                vector1 = System.Windows.Vector.Add(vector1, vector2);
                // vector1 is now equal to (110, 170)

                // Displaying Results
                syntaxString    = "vectorResult = Vector.Negate(vector1);";
                resultType      = "Vector";
                operationString = "Negating a vector";
                ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                break;
            }
            } // end switch
        }
示例#33
0
 /// <summary>
 /// Returns the movement vector of force after adding friction to
 /// current vector.
 /// </summary>
 /// <param name="force">The given vector.</param>
 /// <returns></returns>
 private Vector Friction(Vector force)
 {
     double l = force.Length;
     force.Normalize(); // We use the fact that Vector is passed by copy
                        // as it is structure.
     force *= FrictionFunction(l);
     if (!Double.IsNaN(force.X) && !Double.IsNaN(force.Y))
     {
         return force;
     }
     else
     {
         return new Vector(0.0, 0.0);
     }
 }
示例#34
0
        /// <summary>
        /// Receive mouse move event and do the actual autoscroll if it is active.
        /// </summary>
        /// <param name="sender">The container</param>
        /// <param name="e">Mouse move info</param>
        void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (_autoScrolling)
            {
                Point pt = e.GetPosition(_container);
                Vector v = new Vector(pt.X - _startPos.X, pt.Y - _startPos.Y);
                Vector v2 = new Vector(pt.X - _startPos.X, _startPos.Y);
                double angle = Vector.AngleBetween(v, v2);

                // Calculate which quadrant the mouse is in relative to start position.
                Cursor c = null;
                if (angle > -22.5 && angle < 22.5)
                {
                    c = Cursors.ScrollS;
                }
                else if (angle <= -22.5 && angle > -67.5)
                {
                    c = Cursors.ScrollSW;
                }
                else if (angle <= -67.5 && angle > -112.5)
                {
                    c = Cursors.ScrollW;
                }
                else if (angle <= -112.5 && angle > -157.5)
                {
                    c = Cursors.ScrollNW;
                }
                else if (angle <= -157.5 || angle > 157.5)
                {
                    c = Cursors.ScrollN;
                }
                else if (angle <= 157.5 && angle > 112.5)
                {
                    c = Cursors.ScrollNE;
                }
                else if (angle <= 112.5 && angle > 67.5)
                {
                    c = Cursors.ScrollE;
                }
                else if (angle <= 67.5 && angle > 22.5)
                {
                    c = Cursors.ScrollSE;
                }
                _container.Cursor = c;

                double length = v.Length;
                if (length > 0)
                {
                    v.Normalize();
                    v = Vector.Multiply(length / 50, v);

                    Point translate = _zoom.Offset;
                    translate.X -= v.X;
                    translate.Y -= v.Y;
                    _zoom.Offset = translate;
                }
            }
        }
示例#35
0
        protected virtual void GetMove()
        {
            if (this.Type == ShotType.Normal)
            {
                this.MoveX = 0;
                this.MoveY = this.MoveSpeed;
            }
                /*
            else if (this.Type == ShotType.Direction)
            {

                if (this.moveX == 0 && this.moveY == 0)
                {
                    this.moveY = this.MoveSpeed;
                }
            }
            else if (this.Type == ShotType.Aim)
            {

                if (this.moveX == 0 && this.moveY == 0)
                {
                    this.moveY = this.MoveSpeed;
                }
            }*/
            else if (this.Type == ShotType.Homing)
            {
                Vector vec1 = new Vector(Target.PosX - this.position.PosX, Target.PosY - this.position.PosY);
                vec1.Normalize();
                vec1 *= vec1.Length;
                Vector outVec = vec1 + vec2;
                outVec.Normalize();
                outVec *= this.MoveSpeed;
                vec2 = outVec;

                this.MoveX = (int)Math.Round(vec2.X);

                this.MoveY = this.MoveSpeed;

                if (this.MoveX == 0 && this.MoveY == 0)
                {
                    this.MoveY = this.MoveSpeed;
                }
            }
            else if (this.Type == ShotType.Sin)
            {

                this.MoveX = SinRadius * (int)Math.Round(Math.Cos(this.loopCount));
                this.MoveY = SinRadius * (int)Math.Round(Math.Sin(this.loopCount)) + 1;

                this.loopCount += 1.0D / this.LoopSpeed;

            }
        }