Last active
April 26, 2016 07:40
-
-
Save BrunoVT1992/897790bac4c30d5171ff60c62668b3d0 to your computer and use it in GitHub Desktop.
Calculate the spline fling distance for Xamarin Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Android.App; | |
using Android.Hardware; | |
using Android.Views; | |
namespace Droid | |
{ | |
public static class Distance | |
{ | |
public static double CalculateSplineFlingDistance(float velocity) | |
{ | |
var physicalCoef = SensorManager.GravityEarth * 39.37 * (Application.Context.Resources.DisplayMetrics.Density * 160.0f) * 0.84; | |
var splineDeceleration = Math.Log(0.35f * Math.Abs(velocity) / (ViewConfiguration.ScrollFriction * physicalCoef)); | |
var deceleration = (float)(Math.Log(0.78) / Math.Log(0.9)); | |
var decelMinusOne = deceleration - 1.0; | |
var splineFlingDistance = ViewConfiguration.ScrollFriction * physicalCoef * Math.Exp(deceleration / decelMinusOne * splineDeceleration); | |
return splineFlingDistance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment