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


C# Vector.IsValid方法代码示例

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


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

示例1: AngleRad

        public static double AngleRad(Vector v1, Vector v2)
        {
            Debug.Assert(v1.IsValid());
            Debug.Assert(v2.IsValid());

            double dot = Dot(v1, v2);
            double dotNormalize = dot / (v1.Length * v2.Length);
            double acos = Math.Acos(dotNormalize);

            return acos;
        }
开发者ID:hungdluit,项目名称:bot,代码行数:11,代码来源:GeoHelper.cs

示例2: Dot

        public static double Dot(Vector v1, Vector v2)
        {
            Debug.Assert(v1.IsValid());
            Debug.Assert(v2.IsValid());

            return v1.X * v2.X + v1.Y * v2.Y;
        }
开发者ID:heartszhang,项目名称:WeiZhi3,代码行数:7,代码来源:GeoHelper.cs

示例3: Animate

        public static bool Animate(
            Point currentValue, Vector currentVelocity, Point targetValue,
            double attractionFator, double dampening,
            double terminalVelocity, double minValueDelta, double minVelocityDelta,
            out Point newValue, out Vector newVelocity)
        {
            Debug.Assert(currentValue.IsValid());
            Debug.Assert(currentVelocity.IsValid());
            Debug.Assert(targetValue.IsValid());

            Debug.Assert(dampening.IsValid());
            Debug.Assert(dampening > 0 && dampening < 1);

            Debug.Assert(attractionFator.IsValid());
            Debug.Assert(attractionFator > 0);

            Debug.Assert(terminalVelocity > 0);

            Debug.Assert(minValueDelta > 0);
            Debug.Assert(minVelocityDelta > 0);

            Vector diff = targetValue.Subtract(currentValue);

            if (diff.Length > minValueDelta || currentVelocity.Length > minVelocityDelta)
            {
                newVelocity = currentVelocity * (1 - dampening);
                newVelocity += diff * attractionFator;
                if (currentVelocity.Length > terminalVelocity)
                {
                    newVelocity *= terminalVelocity / currentVelocity.Length;
                }

                newValue = currentValue + newVelocity;

                return true;
            }
            else
            {
                newValue = targetValue;
                newVelocity = new Vector();
                return false;
            }
        }
开发者ID:heartszhang,项目名称:WeiZhi3,代码行数:43,代码来源:GeoHelper.cs

示例4: TickData

        public bool TickData(Vector lastMouse, bool isFlipped)
        {
            bool somethingChanged = false;

            //active means nothing in the "flipped" mode
            bool isActiveItem = IsMouseOver && !isFlipped;
            bool goodMouse = lastMouse.IsValid();

            #region rotation

            Quaternion rotationTarget = new Quaternion(new Vector3D(1, 0, 0), 0);

            //apply forces
            rotationTarget.Normalize();
            m_rotationCurrent.Normalize();

            double angle = 0;
            Vector3D axis = new Vector3D(0, 0, 1);
            if (lastMouse.IsValid() && !isFlipped)
            {
                Point3D mouse = new Point3D(lastMouse.X, lastMouse.Y, 1);
                Vector3D line = mouse - m_locationCurrent;
                Vector3D straight = new Vector3D(0, 0, 1);

                angle = Vector3D.AngleBetween(line, straight);
                axis = Vector3D.CrossProduct(line, straight);
            }
            Quaternion rotationForceTowardsMouse = new Quaternion(axis, -angle);

            Quaternion rotationForceToDesired = rotationTarget - m_rotationCurrent;

            Quaternion rotationForce = rotationForceToDesired + rotationForceTowardsMouse;

            m_rotationVelocity *= new Quaternion(rotationForce.Axis, rotationForce.Angle * .2);

            //dampenning
            m_rotationVelocity = new Quaternion(m_rotationVelocity.Axis, m_rotationVelocity.Angle * (m_weird - .3));

            //apply terminal velocity
            m_rotationVelocity = new Quaternion(m_rotationVelocity.Axis, m_rotationVelocity.Angle);

            m_rotationVelocity.Normalize();

            //apply to position
            m_rotationCurrent *= m_rotationVelocity;
            m_rotationCurrent.Normalize();

            //see if there is any real difference between what we calculated and what actually exists
            if (AnyDiff(m_quaternionRotation3D.Quaternion.Axis, m_rotationCurrent.Axis, c_diff) ||
                AnyDiff(m_quaternionRotation3D.Quaternion.Angle, m_rotationCurrent.Angle, c_diff))
            {
                //if the angles are both ~0, the axis may be way off but the result is basically the same
                //check for this and forget animating in this case
                if (AnyDiff(m_quaternionRotation3D.Quaternion.Angle, 0, c_diff) || AnyDiff(m_rotationCurrent.Angle, 0, c_diff))
                {
                    m_quaternionRotation3D.Quaternion = m_rotationCurrent;
                    somethingChanged = true;
                }
            }

            #endregion

            #region flip
            double verticalFlipTarget = isFlipped ? 180 : 0;
            double verticalFlipCurrent = m_verticalFlipRotation.Angle;

            //force
            double verticalFlipForce = verticalFlipTarget - verticalFlipCurrent;

            //velocity
            m_flipVerticalVelocity += .3 * verticalFlipForce;

            //dampening
            m_flipVerticalVelocity *= (m_weird - .3);

            //terminal velocity
            m_flipVerticalVelocity = limitDouble(m_flipVerticalVelocity, 10);

            //apply
            verticalFlipCurrent += m_flipVerticalVelocity;

            if (AnyDiff(verticalFlipCurrent, m_verticalFlipRotation.Angle, c_diff) && AnyDiff(m_flipVerticalVelocity, 0, c_diff))
            {
                m_verticalFlipRotation.Angle = verticalFlipCurrent;
            }

            #endregion

            #region scale
            if (isActiveItem && !isFlipped)
            {
                this.m_scaleDesired = 2;
            }
            else
            {
                this.m_scaleDesired = 1;
            }

            double scaleForce = this.m_scaleDesired - this.m_scaleCurrent;
            this.m_scaleVelocity += .1 * scaleForce;
//.........这里部分代码省略.........
开发者ID:hungdluit,项目名称:bot,代码行数:101,代码来源:FlipTile.cs

示例5: Normalize

 private static Vector Normalize(Vector v)
 {
     v.Normalize();
       Debug.Assert(v.IsValid());
       return v;
 }
开发者ID:edealbag,项目名称:bot,代码行数:6,代码来源:Graph.cs

示例6: GetSpringForce

        private static Vector GetSpringForce(Vector x)
        {
            Vector force = new Vector();
              //negative is attraction
              force += GetAttractionForce(x);
              //positive is repulsion
              force += GetRepulsiveForce(x);

              Debug.Assert(force.IsValid());

              return force;
        }
开发者ID:edealbag,项目名称:bot,代码行数:12,代码来源:Graph.cs

示例7: GetCurrentValueCore

      /// <summary/>
      protected override Vector GetCurrentValueCore(Vector baseFromValue, Vector baseToValue, AnimationClock animationClock) {
         var progress = animationClock.CurrentProgress;
         if (!progress.HasValue || Interpolator == null) {
            return base.GetCurrentValueCore(baseFromValue, baseToValue, animationClock);
         }

         var fromValue = new Vector();
         var toValue = new Vector();
         var offset = new Vector();
         var isValid = true;

         if (From.HasValue) {
            fromValue = From.Value;
            if (To.HasValue) {
               // from ... to 
               toValue = To.Value;
               if (IsAdditive) {
                  offset = baseFromValue;
                  isValid = offset.IsValid();
               }
            } else if (By.HasValue) {
               // from ... from+by
               toValue = fromValue + By.Value;
               if (IsAdditive) {
                  offset = baseFromValue;
                  isValid = offset.IsValid();
               }
            } else {
               // from ... base
               toValue = baseToValue;
               isValid = toValue.IsValid();
            }
         } else if (To.HasValue) {
            // base ... to
            fromValue = baseFromValue;
            toValue = To.Value;
            isValid = fromValue.IsValid();
         } else if (By.HasValue) {
            // base ... base+by
            toValue = By.Value;
            offset = baseFromValue;
            isValid = offset.IsValid();
         } else {
            // base ... base
            fromValue = baseFromValue;
            toValue = baseToValue;
            isValid = fromValue.IsValid() && toValue.IsValid();
         }
         if (!isValid) {
            throw new InvalidOperationException("GetCurrentValueCore");
         }

         if (IsCumulative) {
            var iteration = animationClock.CurrentIteration;
            if (iteration.HasValue && iteration.Value > 1) {
               offset += (toValue - fromValue) * (iteration.Value - 1);
            }
         }

         var interpolator = Interpolator ?? Interpolators.Linear;
         return fromValue + (toValue - fromValue) * interpolator(progress.Value, 0.0, 1.0) + offset;
      }
开发者ID:borkaborka,项目名称:gmit,代码行数:63,代码来源:VectorInterpolation.cs


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