Created
March 7, 2021 13:40
-
-
Save OmarKRostom/8de5016565b461a756decf9b9acd3f84 to your computer and use it in GitHub Desktop.
ComputeY component for a circular recyclerview
This file contains 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