We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Finding collision on a circle
Page Index Toggle Pages: 1
Finding collision on a circle (Read 800 times)
Finding collision on a circle
Mar 26th, 2006, 1:06pm
 
Hi,
I have an an ellipse with a rect rotating around it (like an orbit), but im trying to find a way of moving the ellipse in the opposite direction of where the rect is when the spacebar is pressed (a factor of power will also be needed)

Here is the syntax of how I rotate around the ellipse
Code:
  pushMatrix();
translate (b[15].getXPos(), b[15].getYPos());
translate(xpos,ypos);
rotate (radians(90));
rotate(radians(angle)*-1);
image (cue, -5, -5);
popMatrix();


I have a feeling it will involve the angle variable
Re: Finding collision on a circle
Reply #1 - May 19th, 2006, 5:43pm
 
I think if you are going to develop a two-way relationship between your particles then you might as well throw some trigonometry into the equation. I've written out some code below which demonstrates circumnavigation. You could just add a little translation and rotation to get the effect of a rect rotating around an ellipse. It's not exactly what you're describing but given a form of rotation where you'll know about co-ordinate changes I'm sure you'll be able to figure the rest out.
Code:

Rotator one, two;
void setup(){
size(400, 400);
one = new Rotator(175, 175);
two = new Rotator(225, 225);
}
void draw(){
background(0);
smooth();
one.draw();
two.draw();
if(keyPressed){
one.circumnavigate(two.x, two.y);
} else {
two.circumnavigate(one.x, one.y);
}
}
class Rotator{
float x,y;
Rotator(float x, float y){
this.x = x;
this.y = y;
}
void draw(){
ellipse(x, y, 20, 20);
}
void circumnavigate(float x, float y){
float theta = atan2(this.y - y, this.x - x);
float distance = dist(this.x, this.y, x, y);
theta += 0.05;
this.x = x + cos(theta) * distance;
this.y = y + sin(theta) * distance;
}
}
Page Index Toggle Pages: 1