Kotlin 圆上找p点

Posted aikongmeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kotlin 圆上找p点相关的知识,希望对你有一定的参考价值。


𝑥=𝑟 sin 𝜃, 𝑦= 𝑟 cos 𝜃

fun printPointOnTheCircle(
    thetaInDegrees: Double,
    radius: Float,
    cX: Float,
    cY: Float
): Pair<Float, Float> 

    val x = cX + (radius * kotlin.math.sin(Math.toRadians(thetaInDegrees)).toFloat())
    val y = cY + (radius * kotlin.math.cos(Math.toRadians(thetaInDegrees)).toFloat())

    println("(x,y) = ($x,$y)")

    return Pair(x, y)



@Preview()
@Composable
- fun CustomProgressBar() 
+	fun CustomProgressBar(
+		progressPercentage: Float = 1.0f
+	) 
	Canvas(
    	modifider = Modifier
        .size(150.dp)
        .padding(10.dp)
    	) 
        	// Background Arc
            drawArc(
                color = Color(android.graphics.Color.parseColor("#90A4AE")),
                140f,
                260f,
                false,
                style = Stroke(10.dp.toPx(), cap = StrokeCap.Round),
                size = Size(size.width, size.height)
        	)    
            
            // Foreground Arc
            drawArc(
                color = Color(android.graphics.Color.parseColor("#4DB6AC")),
                140f,
-                260f,
+				progressPercentage * 260f,
                false,
                style = Stroke(10.dp.toPx(), cap = StrokeCap.Round),
                size = Size(size.width, size.height)
        	)
+         var angleInDegrees = (progressPercentage * 260.0) + 50.0
+         var radius = (size.height / 2)
+         var x = -(radius * sin(Math.toRadians(angleInDegrees))).toFloat() + (size.width / 2)
+         var y = (radius * cos(Math.toRadians(angleInDegrees))).toFloat() + (size.height / 2)
           
            
            // Progress dot
              drawCircle(
-                  color = Color.Red,
+                  color = Color.White,
                  radius = 5f,
                  center = Offset(x, y)
              )
    	

以上是关于Kotlin 圆上找p点的主要内容,如果未能解决你的问题,请参考以下文章

Kotlin 圆上找p点

Kotlin 圆上找p点

Kotlin 圆上找p点

TopCoder SRM 559 Div 1 - Problem 900 CircusTents

HDU 6097 Mindis (计算几何)

最短路径-3