/// <summary> /// Retrieves the angle, expressed in radians, between the two specified vectors. /// </summary> /// <param name="vector1">The first vector to evaluate.</param> /// <param name="vector2">The second vector to evaluate.</param> /// <returns>The angle, in radians, between vector1 and vector2.</returns> public static float AngleBetween(VectorF vector1, VectorF vector2) { vector1.Normalize(); vector2.Normalize(); double angle = Math.Atan2(vector2.y, vector2.x) - Math.Atan2(vector1.y, vector1.x); if (angle > Math.PI) { angle -= Math.PI * 2.0; } else if (angle < -Math.PI) { angle += Math.PI * 2.0; } return (float)angle; }
/// <summary> /// Start the inertia processor in Surface screen space. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnAffine2DManipulationCompleted(object sender, Manipulation2DCompletedEventArgs e) { if (inertiaProcessor != null) { inertiaProcessor.Delta -= OnAffine2DInertiaDelta; inertiaProcessor.Completed -= OnAffine2DInertiaCompleted; inertiaProcessor.Complete(stopwatch.Elapsed100Nanoseconds()); } VectorF translation = new VectorF(e.Total.TranslationX, e.Total.TranslationY); // Don't start inertia if the tranlation is less than roughly 1/8" regardless of velocity. if (translation.Length < 96 / 8f) { return; } // Scroll in the opposite direction because a ScrollViewer moves with the touch. VectorF initialVelocity = new VectorF(-e.Velocities.LinearVelocityX, -e.Velocities.LinearVelocityY); // Check velocity. if (initialVelocity.Length < FlickUtilities.MinimumFlickVelocity) { // If velocity is below this threshold ignore it. return; } if (initialVelocity.Length >= FlickUtilities.MaximumFlickVelocity) { // If velocity is too large, reduce it to a reasonable value. initialVelocity.Normalize(); initialVelocity = FlickUtilities.MaximumFlickVelocity * initialVelocity; } processInertia = true; inertiaProcessor = new InertiaProcessor2D(); inertiaProcessor.Delta += OnAffine2DInertiaDelta; inertiaProcessor.Completed += OnAffine2DInertiaCompleted; inertiaProcessor.TranslationBehavior = new InertiaTranslationBehavior2D { DesiredDisplacement = ConvertFromVerticalValueToScreenSpace(VerticalViewportSize), InitialVelocityX = initialVelocity.X * HorizontalViewportSize, InitialVelocityY = initialVelocity.Y * VerticalViewportSize }; inertiaProcessor.InitialOriginX = ConvertFromHorizontalValueToScreenSpace(horizontalScrollBarStateMachine.Value); inertiaProcessor.InitialOriginY = ConvertFromVerticalValueToScreenSpace(verticalScrollBarStateMachine.Value); }