2

I'm new to this so don't blame me. I am trying to develop an android app that would make music. I am trying to make a bar that rotates over a bunch of buttons that are displayed in the form of a circle, and when it does to play the sound represented by every button. However so far I managed to make an image rotate around the middle of the screen by setting x and y coordinates representing the centre of the circle, but when I try to put the formula (x + radius*sin(angle)), (y + radius*cos(angle)), it just moves the image I want to rotate at that point. So basically I am trying to rotate an Image around an circle defined by buttons or coordinates rather then an actual circle image. So I need to rotate an image or imageView around a circle, not just a point.

I have added the code ass well so you could have a look at what I'm doing wrong.

ImageView bara = (ImageView) findViewById(R.id.floating_image);

layoutParams[9] = new RelativeLayout.LayoutParams

(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

        toop = Math.round(size.x/2);      // + 90*Math.sin(ANGLE)); 
        lefft = Math.round(size.y/2);    // + 90*Math.cos(ANGLE)); 
        top = (int) toop;
        left = (int) lefft;
        layoutParams[9].setMargins(top, left, 0, 0);
        bara.setLayoutParams(layoutParams[9]);
        RotateAnimation rAnim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF,  0 , Animation.RELATIVE_TO_SELF, 0);
        rAnim.setRepeatCount(Animation.INFINITE);
        rAnim.setInterpolator(new LinearInterpolator());
        rAnim.setDuration(8000);
        bara.startAnimation(rAnim);

Any help would be really appreciated !!

2 Answers2

1

the code looks like :

    private float mCalcX;//x-coord of object
    private float mCalcY;//y-coord of object
    private double mCenterX;//x-coord of center of circle
    private double mCenterY;//y-coord of center of circle
    private double mRadius;//circle radius
    private double mAngleRadians;//angle of your object to draw in RADs

    // whenever you draw the object, calculate the new X and Y coords
    mCalcX = (float) (mCenterX+(mRadius*Math.cos(mAngleRadians)));
    mCalcY = (float) (mCenterY+(mRadius*Math.sin(mAngleRadians)));

    public void setRadius(double r)
    {
        mRadius = r;
    }

    public void setStartingAngle(double radians)
    {
        mAngleRadians = radians;
    }

    public void setRotationSpeed(double radians)
    {
        mRotationSpeed = radians;
    }

    public void increaseRotationAngle()
    {
        mAngleRadians += mRotationSpeed;
    }

    public void decreaseRotationAngle()
    {
        mAngleRadians -= mRotationSpeed;
    }
Someone Somewhere
  • 23,475
  • 11
  • 118
  • 166
0

x^2 + y^2 = r^2

Reference: http://www.mathwarehouse.com/geometry/circle/equation-of-a-circle.php

You should animate the centre of your object around all the (x,y) that satisfy that equation for your chosen value of r (the radius of the circle).

I'm not a graphics guy, so forgive the terseness of my response.

nucc1
  • 324
  • 2
  • 8
  • I don't really think I know how to do that.. I tried making a loop and make the image rotate 1 degree and move the location at every loop change (360) but didn't work – Lucian Coanda Jan 21 '13 at 23:34