-
-
Save virendersran01/c3b06ef5afe58c34408f104ed1d31343 to your computer and use it in GitHub Desktop.
ComputeY component for a circular recyclerview
This file contains hidden or 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
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