Acceleration of wheel

54 views Asked by At

I am trying to calculate the acceleration of the rotateable wheel i have implemented.

But i have a hard time figuring out how i would calculate that. So any tips that could help me out is appreciated

The wheel itself is a created on my onDraw() method.

How i rotate the wheel

@Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (rotationEnabled) {
            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_MOVE:
                    double currentAngle = getAngle(motionEvent.getX(), motionEvent.getY());

                    rotateMe((float) (startAngle - currentAngle));
                    startAngle = startAngle - currentAngle;
                    break;
                case MotionEvent.ACTION_UP:
                    break;
            }
        }
        return false;
    }

    private double getAngle(double xTouch, double yTouch) {
        double x = xTouch - (getMeasuredWidth() / 2d);
        double y = getMeasuredHeight() - yTouch - (getMeasuredHeight() / 2d);

        switch (getQuadrant(x, y)) {
            case 1:
                return Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
            case 2:
                return 180 - Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
            case 3:
                return 180 + (-1 * Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI);
            case 4:
                return 360 + Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
            default:
                return 0;
        }
    }

    private static int getQuadrant(double x, double y) {
        if (x >= 0) {
            return y >= 0 ? 1 : 4;
        } else {
            return y >= 0 ? 2 : 3;
        }
    }

    private void rotateMe(float degrees) {
        setRotation(degrees);
    }

Update

The goal is to setup a timer. That goes from minutes to hours. I need the acceleration to jump from minutes to hours faster. All should be depended on how fast the user drags the wheel

So after touch event (When user stops touching the wheel). There should be no velocity attached to it.

0

There are 0 answers