Skip to content

Instantly share code, notes, and snippets.

@virendersran01
Forked from OmarKRostom/computeY.kt
Created March 17, 2021 04:20
Show Gist options
  • Save virendersran01/c3b06ef5afe58c34408f104ed1d31343 to your computer and use it in GitHub Desktop.
Save virendersran01/c3b06ef5afe58c34408f104ed1d31343 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