Vectors with Circles Physics -java
- by Joe Hearty
This is a problem I've been having, When making a set number of filled circles at
random locations on a JPanel and applying a gravity (a negative change in the y),
each of the circles collide. I want them to have collision detection and push in the opposite direction using vectors but i don't know how to apply that to my scenario could someone help?
public void drawballs(Graphics g){
g.setColor (Color.white);
//displays circles
for(int i = 0; i<xlocationofcircles.length-1; i++){
g.fillOval( (int) xlocationofcircles[i], (int) (ylocationofcircles[i]) ,16 ,16 );
ylocationofcircles[i]+=.2; //gravity
if(ylocationofcircles[i] > 550) //stops gravity at bottom of screen
ylocationofcircles[i]-=.2;
//Check distance between circles(i think..)
float distance =(xlocationofcircles[i+1]-xlocationofcircles[i]) + (ylocationofcircles[i+1]-xlocationofcircles[i]) ;
if( Math.sqrt(distance) <16)