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 › print when same angle
Page Index Toggle Pages: 1
print when same angle (Read 890 times)
print when same angle
May 9th, 2010, 9:44am
 
Hi,
I have a problem I can't solve.
I need two know when two shapes has the same angle. I have made a small sketch to illustrate the issue:

Code:
float centerAngleO;
float centerAngleT;

float posXcenterLine;
float posYcenterLine;
float posXoutLine;
float posYoutLine;

void setup() {
size(400,400);
frameRate(15);
}

void draw() {

background(255);
translate(width/2,height/2);
centerAngleO += PI/240;
rotate(-centerAngleO);
lineO();

centerAngleT += PI/60;
rotate(-centerAngleT);
lineT();

check();
}

void lineO(){
for(int i=0; i<32; i++){
posXcenterLine=i+40;
posYcenterLine=i+40;
strokeWeight(10);
line(posXcenterLine,posYcenterLine,10,10);}
}

void lineT(){
for(int i=0; i<32; i++){
posXoutLine=i+80;
posYoutLine=i+80;
strokeWeight(10);
line(posXoutLine,posYoutLine,120,120);}
}

void check(){
if(posXcenterLine==posXoutLine){
print("yepa");}

 


any help will be much appreciated!
Re: print when same angle
Reply #1 - May 9th, 2010, 1:04pm
 
How about this?

Code:
int yeswecan;
int angle1,angle2;

void setup() {
 size(400,400);
 smooth();
 frameRate(15);
}

void draw() {
 background(255);
 translate(width/2,height/2);

 angle1 += 1;
 angle2 += 10;

 rotate(-radians(angle1));
 strokeWeight(5);
 stroke(200,0,0);
 line(0,0,75,0);
 rotate(radians(angle1));

 rotate(-radians(angle2));
 strokeWeight(2);
 stroke(0);
 line(75,0,150,0);
 rotate(radians(angle2));

 check();

}

void check(){
 if (angle1 >= 360) {angle1 = 0;}
 if (angle2 >= 360) {angle2 = 0;}

 if(angle1 == angle2){
   fill(200,0,0);
   ellipse(0,0,25,25);
   yeswecan++;
   println("YES WE CAN! (" + yeswecan + ")");
   // proof it's accurate even after 5 or 500 spins :)
   if (yeswecan == 5) {noLoop();}
 }
}
Re: print when same angle
Reply #2 - May 10th, 2010, 2:29am
 
Hi amnonP5,

nice and very simple solution. Seems to work very accurate!
Smiley

Thanks a lot!!!

Page Index Toggle Pages: 1