Skip to content

Instantly share code, notes, and snippets.

@BrunoVT1992

BrunoVT1992/Distance.cs

Last active Apr 26, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.