I've got what I thought was a simple question, yet the solution eludes me. The premise of the problem is simple: I have a view (call it a point) with center vx, vy that I want to rotate around a bigger circle cx, cy. I've looked into using sin, cos, radians, atan2, all that jazz, yet for some reason when I rotate my views, it looks as if it's rotating in an oval and not a circle. The math for this eludes me.
What I have so far:
public void update(double matrixAngle)
double angleInDegs = Math.toDegrees(mAngle);
double newAngle = (matrixAngle > 0) ? angleInDegs + matrixAngle : angleInDegs - matrixAngle;
double angleInRads = Math.toRadians(newAngle);
float dx = itemCircle.getCenterX() - getCenterX();
float dy = itemCircle.getCenterY() - getCenterY();
double radius = Math.sqrt(dx * dx + dy * dy);
float x = (float) (getCenterX() + radius * Math.cos(angleInRads));
float y = (float) (getCenterY() - radius * Math.sin(angleInRads));
itemCircle.setCenterX(x);
itemCircle.setCenterY(y);
For some clarification:
matrixAngle
parameter of the method is the matrix angle used to rotate the entire view. It ranges from 0-180, then from -180 to 0, where 0 is opening from the right-side of the circle.
mAngle
is the original angle that the view was drawn at. It ranges from 0 to 360.
itemCircle
is the circle representing the view's bounds. It is a circle (an extended FloatingActionButton, to be exact).
getCenterX(), getCenterY()
are the coords of the bigger circle that I want to rotate around.
I'd really appreciate some help here. This problem has been bugging me for a day now.
itemCircle
) because I need to have them respond to click events and fire my click listener. – Miles Peele