0

I have a class that has been entitled as Ball. Within said class I have an instance of java.awt.Rectangle.

 package com.ncagle.angles;

 import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Rectangle;

public class Ball {

public Rectangle rect;

public Ball() {
    rect = new Rectangle(10, 10, 16, 16);
}

public void tick() {

}

public void draw(Graphics g) {
    g.setColor(Color.WHITE);
    g.fillRect(rect.x, rect.y, rect.width, rect.height);
}

}

What I'm wishing to accomplish is to have said Rectangle move at a specific angle (ex: 35°). I haven't tried anything because I have no idea how I would go at this. I'm in 8th Grade. I just learned what Pythagorean Theorem is about two weeks ago. If anybody could show me how this would be done, that would be great. Thank you.

Noah Cagle
  • 146
  • 1
  • 4
  • 15
  • You have some basic problems you need to solve, first, based on a start point, you need to be able to calculate the end point which, if you drew a line between them, would be the desired angle. This represents a "find the point on a circle based on a given angle" problem. Next, you need to calculate the point along the line you're at, at any given time – MadProgrammer Apr 14 '16 at 23:20
  • [Point on circle at angle example](http://stackoverflow.com/questions/25923480/simple-circle-rotation-simulate-motion/25923780#25923780) – MadProgrammer Apr 14 '16 at 23:21
  • [Moving alone line example](http://stackoverflow.com/questions/28961352/java-image-move-along-points-in-list-and-use-linear-interpolation/29000066#29000066) and [example](http://stackoverflow.com/questions/31041991/moving-a-square-from-a-starting-point-to-the-position-of-a-mouse-click-at-a-fixe/31042775#31042775) – MadProgrammer Apr 14 '16 at 23:23
  • Before you ask, I don't understand the maths either, I just know how to use it – MadProgrammer Apr 14 '16 at 23:25

0 Answers0