Skip to content

Instantly share code, notes, and snippets.

@BrunoVT1992
Last active April 26, 2016 07:40
Show Gist options
  • Save BrunoVT1992/897790bac4c30d5171ff60c62668b3d0 to your computer and use it in GitHub Desktop.
Save BrunoVT1992/897790bac4c30d5171ff60c62668b3d0 to your computer and use it in GitHub Desktop.
Calculate the spline fling distance for Xamarin Android
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