Skip to content

Instantly share code, notes, and snippets.

@OmarKRostom
Created March 7, 2021 13:40
Show Gist options
  • Save OmarKRostom/8de5016565b461a756decf9b9acd3f84 to your computer and use it in GitHub Desktop.
Save OmarKRostom/8de5016565b461a756decf9b9acd3f84 to your computer and use it in GitHub Desktop.
ComputeY component for a circular recyclerview
private fun computeYComponent(viewCenterX: Float,
h: Float): Pair<Int, Double> {
val screenWidth = context.resources.displayMetrics.widthPixels
val s = screenWidth.toDouble() / 2
val radius = (h * h + s * s) / (h * 2)
val xScreenFraction = viewCenterX.toDouble() / screenWidth.toDouble()
val beta = acos(s / radius)
val alpha = beta + (xScreenFraction * (Math.PI - (2 * beta)))
val yComponent = radius - (radius * sin(alpha))
return Pair(yComponent.toInt(), alpha)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment