当前位置: 首页>>代码示例>>C#>>正文


C# Vector.Normalize方法代码示例

本文整理汇总了C#中System.Windows.Vector.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Normalize方法的具体用法?C# Vector.Normalize怎么用?C# Vector.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Vector的用法示例。


在下文中一共展示了Vector.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetWaypoint

        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;
        }
开发者ID:villj2,项目名称:ch.bfh.bti7301.searchrobot,代码行数:28,代码来源:WayDecisionCollision.cs

示例2: TestPushBackBotRightToCenter

        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);
        }
开发者ID:EusthEnoptEron,项目名称:Sketchball,代码行数:30,代码来源:BoundingLine_pushBack.cs

示例3: Draw

        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);
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:25,代码来源:ManyConnectorEndPoint.cs

示例4: addGoalPoint

 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;
 }
开发者ID:TomWerner,项目名称:HandsOnInterface,代码行数:9,代码来源:PhysWindow.cs

示例5: Update

        /// <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;
        }
开发者ID:Vlad7,项目名称:TanksStory,代码行数:60,代码来源:HITankController.cs

示例6: CalculateAngle

        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));
        }
开发者ID:brunosccosta,项目名称:Marionect,代码行数:11,代码来源:MainWindow.xaml.cs

示例7: WindowOnSizeChanged

 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;
 }
开发者ID:JianchengZh,项目名称:kasicass,代码行数:12,代码来源:AdjustTheGradient.cs

示例8: ComputeLinkBetweenRectangles

        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);
        }
开发者ID:bzamecnik,项目名称:XRouter,代码行数:14,代码来源:MathUtils.cs

示例9: Draw

        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);
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:15,代码来源:IConnectorEndPointDrawingStrategy.cs

示例10: Gradient

 /// <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;
 }
开发者ID:hirekoke,项目名称:FloWin,代码行数:21,代码来源:Spiky.cs

示例11: Window_SizeChanged

        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;
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:17,代码来源:MainWindow.xaml.cs

示例12: GetPinPositions

        /// <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;
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:51,代码来源:BillboardGeometryBuilder.cs

示例13: TerminateGesture

 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);
 }
开发者ID:nius1989,项目名称:CardDataSorting,代码行数:20,代码来源:Gesture_Sorting_Listener.cs

示例14: Convert

 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;
 }
开发者ID:blacklensama,项目名称:1709,代码行数:40,代码来源:ConnectorPointsToSegmentsConverter.cs

示例15: NormalizeVector

        protected Vector NormalizeVector(Vector v)
        {
            var vector = new Vector(v.X, v.Y);
            vector.Normalize();

            return vector;
        }
开发者ID:EusthEnoptEron,项目名称:Sketchball,代码行数:7,代码来源:BoundingBox.cs


注:本文中的System.Windows.Vector.Normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。