Making Rectangle fly in circles

I’m currently working on some game where I want to throw entities off a cliff.
Now I need to make the entity move in 90 degrees in the arms of the “Thrower”.
I’ve been testing some things but I can’t really get to an idea how to get this entity move smooth.

This is what my Thrower class currently looks like:


package nl.tdegroot.exgj.Justice;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;

public class Thrower {

	private final Vector2f velocity;
	private final Rectangle position;

	private boolean increment = true;
	private float minX = 470f;
	private float minY = 470f;
	private float maxX = 520f;
	private float maxY = 520f;

	private final float friction = 0.55f;
	private float movementSpeed = 5f;

	public Thrower() {
		velocity = new Vector2f();
		position = new Rectangle(500, 500, 50, 50);
	}

	public void update(GameContainer gc, int delta) throws SlickException {
		velocity.x *= friction;
		velocity.y *= friction;

		if (Math.abs(velocity.x) < friction) velocity.x = 0f;
		if (Math.abs(velocity.y) < friction) velocity.y = 0f;

		if (increment) {
			velocity.x += movementSpeed;
			velocity.y -= movementSpeed;
		} else {
			velocity.x -= movementSpeed;
			velocity.y += movementSpeed;
		}

		float newX = position.getX() + velocity.x;
		float newY = position.getY() + velocity.y;

		if (newX <= minX || newY <= minY) {
			increment = true;
		} else if (newX >= maxX || newY >= maxY) {
			increment = false;
		}

		System.out.println("" + newX + ", " + newY);

		if (newX != 0) {
			position.setX(newX);
		}

		if (newY != 0) {
			position.setY(newY);
		}

	}

	public void render(GameContainer gc, Graphics g) {
		g.fillRect(position.getX(), position.getY(), 50, 50);
	}

}


Any help would be highly appreciated!

This should be in the Newbie & Debugging board.

As for your question, you should look into trigonometry; specifically cos, and sin equations.

Here, its not that hard. Just use the rotation matrix:

Do matrix multiplication with the rectangle coordinates, and it should be easy. (You’re going to have to draw the rectangle as individual lines if you use this method).

Or if you prefer, you can use the AffineTransform with Graphics2D to rotate the object.