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 & HelpSyntax Questions › Can You Help Please? Rotation
Page Index Toggle Pages: 1
Can You Help Please?? Rotation (Read 487 times)
Can You Help Please?? Rotation
Mar 24th, 2009, 5:03pm
 
Hi! I currently have a circle in the center and two circles around it...I would like the two circles now to rotate around the center point of the program to make it look like they are orbiting the center point. I would also the two circles doing the orbiting to move in opposite directions and progressively move faster. Can you PLEASE PLEASE help me? Thank you!
Re: Can You Help Please?? Rotation
Reply #1 - Mar 24th, 2009, 5:34pm
 
Is it homework What have you tried I know rotating around an arbitrary center isn't trivial in Processing, but you can look at some existing sketches, like Rotating Ellipse for example. The key being the combination of translate() and rotate().
Re: Can You Help Please?? Rotation
Reply #2 - Mar 24th, 2009, 5:58pm
 
I'm guessing this is more of a trigonometry situation.

The positions of your two orbiting circles can be determined with the following formulas:

x = r * cos(theta)
y = r * sin(theta)

"r" is the orbital radius--how far the center of one circle is from the center of the one in the middle.  "theta" is the angular position with respect to zero degrees (or radians, as you like).  Zero degrees/radians is eqivalent to the positive-x direction on the screen.

In your case, you'll want to track two separate theta values, maybe call them theta1 and theta2 or something.  At each time step, you'll increment one of them and decrement the other one.  In that way, one will have a continually increasing angle, while the other has a continually decreasing angle, and thus they will orbit in different directions.

You can also use separate r1 and r2 values, to make each circle orbit at a different distance from the center.
Re: Can You Help Please?? Rotation
Reply #3 - Mar 25th, 2009, 5:49am
 
Thanks guys!!

Yes, it is school work. It is the first time that they have introduced processing in this class, and I have been having a hard time finding help for that reason. A lot of my friends and classmates (including myself) have never heard of processing before. And yes it is the trigonometry that I'm having the most trouble with. The first few assignments were not difficult, but as soon as we were asked to do more than one thing, the code got lengthy and the math complicated for me.

This forum has been GREAT GREAT HELP!! Thanks again!

Re: PhiLho look at this code please?? Rotation
Reply #4 - Mar 25th, 2009, 7:10am
 
PhiLho,

Just hoping you could look at this code and tell me why my circles are not moving/spinning? Can you explain it to me please. Thank you!!


float angle;  

void setup() {
size(355, 355);
smooth();
ellipseMode(CENTER);
}


void draw() {
background(235);
PFont font;
font = loadFont("LucidaSans-42.vlw");
textFont(font);
fill(#5A555D);
text("rotation", 10, 330);
angle += TWO_PI;
//or is it PI/180, is that the same thing?

pushMatrix();
translate(width*0.325, height*0.325);
rotate(angle);
noStroke();
fill(#930483);
ellipse(0, 0, width/2, height/2);
popMatrix();

pushMatrix();
translate(width*0.7, height*0.7);
rotate(-angle);
noStroke();
fill(#D349C3);
ellipse(0, 0, width/2, height/2);
popMatrix();
}
Re: Can You Help Please?? Rotation
Reply #5 - Mar 25th, 2009, 8:14am
 
Good! I am not against helping, even for homework, but tradition (here and in other forums) is to ask for some work first! Wink And trying to push in the right direction instead of doing all the work.

First thing: avoid putting stuff with "load" in draw(): it means the file will be loaded on each frame, a bit too much...
Second thing: angle += TWO_PI; If you do a full revolution on each frame, nothing will seem to move!
Make that angle += 0.1; or if you want "precision" (given number of steps), angle += TWO_PI/100;
Lastly, beside the above issues, your code is correct. The only problem is that you rotate circles around their center. Well, you won't see much... Smiley
Try changing a radius or use rect to see something.
Or, like I like to do, add a some reference point:
Code:
float angle;  

void setup() {
size(355, 355);  
smooth();  
ellipseMode(CENTER);  
PFont font = createFont("Arial", 42);  // Simpler for me
textFont(font);  
}  


void draw() {
background(235);  
fill(#5A555D);
text("rotation", 10, 330);  
angle += TWO_PI/100;

pushMatrix();  
translate(width*0.325, height*0.325);  
rotate(angle);  
noStroke();  
fill(#930483);  
ellipse(0, 0, width/2, height/2);  
fill(0);
ellipse(10, 10, 10, 10);  
popMatrix();  

pushMatrix();  
translate(width*0.7, height*0.7);  
rotate(-angle);  
noStroke();  
fill(#D349C3);  
ellipse(0, 0, width/2, height/2);  
fill(0);
ellipse(10, 10, 10, 10);  
popMatrix();  
}

If you want to rotate around some central point, you have to do an additional translate after the rotate: the first translate position the center of the rotation, the second one will shift the circle of the radius of its revolution.
Re: Can You Help Please?? Rotation
Reply #6 - Mar 25th, 2009, 5:02pm
 
Thank you Smiley
Page Index Toggle Pages: 1