From e284872a96c3a7d712803040321bd7e6650c0cf9 Mon Sep 17 00:00:00 2001 From: Feyzu Date: Mon, 15 Aug 2022 17:06:13 +0200 Subject: [PATCH] Pendel Logic READY Pendelsession information save in profile in progress new fragment "fragment_start_pendulum" finished Measured results saved in UpdateFragment Recyclerview based und User Id successfully --- .idea/deploymentTargetDropDown.xml | 17 ------ .../acapendulum20/canvas/CanvasPendulum.kt | 52 ++++++++----------- 2 files changed, 23 insertions(+), 46 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index 82a483a..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt b/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt index 2aeb786..00d8c1b 100644 --- a/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt +++ b/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt @@ -26,7 +26,6 @@ class CanvasPendulum @JvmOverloads constructor( this.canvas = it } - //println("ONDRAW") //draw line mPendulum.startPosition.x = (width / 2).toFloat() paint.isAntiAlias = true @@ -48,7 +47,7 @@ class CanvasPendulum @JvmOverloads constructor( canvas?.drawCircle( mPendulum.stopPosition.x, mPendulum.stopPosition.y, - mPendulum.ballr, + mPendulum.ballRadius, paint ) @@ -57,7 +56,7 @@ class CanvasPendulum @JvmOverloads constructor( paint.strokeWidth = 1f paint.color = Color.RED if (mPendulum.angleVelocity > 0) { - if (mPendulum.stopPosition.x < (width / 3) - 30f && mPendulum.stopPosition.x + 30 > (width / 3) - 30f - mPendulum.ballr) { + if (mPendulum.stopPosition.x < (width / 3) - 30f && mPendulum.stopPosition.x + 30 > (width / 3) - 30f - mPendulum.ballRadius) { paint.style = Paint.Style.FILL_AND_STROKE paint.strokeWidth = 10f paint.color = Color.GREEN @@ -70,7 +69,7 @@ class CanvasPendulum @JvmOverloads constructor( paint.strokeWidth = 1f paint.color = Color.RED if (mPendulum.angleVelocity < 0) { - if (mPendulum.stopPosition.x > (width / 1.5) - 30f && mPendulum.stopPosition.x + 30 < (width / 1.5) + 30f + mPendulum.ballr) { + if (mPendulum.stopPosition.x > (width / 1.5) - 30f && mPendulum.stopPosition.x + 30 < (width / 1.5) + 30f + mPendulum.ballRadius) { paint.style = Paint.Style.FILL_AND_STROKE paint.strokeWidth = 10f paint.color = Color.GREEN @@ -86,45 +85,39 @@ class CanvasPendulum @JvmOverloads constructor( if (mPendulum.magneticField) { - var gravity = 0.981f - var damping = 0.996f - if (mPendulum.stopPosition.x > canvas.width / 4f && mPendulum.stopPosition.x <= canvas.width * 0.75f) { - gravity = 1.981f + mPendulum.gravity = 1.981f if (mPendulum.stopPosition.x > canvas.width / 3.toFloat() && mPendulum.stopPosition.x <= canvas.width / 1.5.toFloat()) { - gravity = 2.981f + mPendulum.gravity = 2.981f if (mPendulum.stopPosition.x >= canvas.width / 2.toFloat() - 3 && mPendulum.stopPosition.x <= canvas.width / 2.toFloat() + 3) { - damping = 0.3f + mPendulum.damping = 0.3f } } } - mPendulum.angleAcceleration = - ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() + mPendulum.angleAcceleration = ((-1 * mPendulum.gravity / mPendulum.stringLength) * (mPendulum.startAngle)).toFloat() mPendulum.angleVelocity += mPendulum.angleAcceleration - mPendulum.angleVelocity *= damping - mPendulum.angle += mPendulum.angleVelocity + mPendulum.angleVelocity *= mPendulum.damping + mPendulum.startAngle += mPendulum.angleVelocity //Polar to cartesian conversion - mPendulum.stopPosition.x = mPendulum.r * (sin(mPendulum.angle)).toFloat() - mPendulum.stopPosition.y = mPendulum.r * (cos(mPendulum.angle)).toFloat() + mPendulum.stopPosition.x = mPendulum.stringLength * (sin(mPendulum.startAngle)).toFloat() + mPendulum.stopPosition.y = mPendulum.stringLength * (cos(mPendulum.startAngle)).toFloat() //Origin transition mPendulum.stopPosition.x += mPendulum.startPosition.x } if (!mPendulum.magneticField) { - val gravity = 0.981f - val damping = 0.996f - mPendulum.angleAcceleration = - ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() + + mPendulum.angleAcceleration = ((-1 * mPendulum.gravity / mPendulum.stringLength) * (mPendulum.startAngle)).toFloat() mPendulum.angleVelocity += mPendulum.angleAcceleration - mPendulum.angleVelocity *= damping - mPendulum.angle += mPendulum.angleVelocity + mPendulum.angleVelocity *= mPendulum.damping + mPendulum.startAngle += mPendulum.angleVelocity //Polar to cartesian conversion - mPendulum.stopPosition.x = mPendulum.r * (sin(mPendulum.angle)).toFloat() - mPendulum.stopPosition.y = mPendulum.r * (cos(mPendulum.angle)).toFloat() + mPendulum.stopPosition.x = mPendulum.stringLength * (sin(mPendulum.startAngle)).toFloat() + mPendulum.stopPosition.y = mPendulum.stringLength * (cos(mPendulum.startAngle)).toFloat() //Origin transition mPendulum.stopPosition.x += mPendulum.startPosition.x } @@ -154,13 +147,14 @@ class Pendulum { var startPosition: Position = Position(0f, 0f) var stopPosition: Position = Position(0f, 0f) - var r = 800f + var stringLength = 900f - //PI/6 Max ausschwingen - var angle: Double = Math.PI / 12 + //start angle + var startAngle: Double = Math.PI / 12 var angleVelocity: Float = 0.0f // var angleAcceleration: Float = 0.0f // - var ballr: Float = 70.0f // - + var ballRadius: Float = 70.0f // var magneticField: Boolean = false + var gravity = 0.981f + var damping = 0.996f } \ No newline at end of file