fdevant wrote on Jan 6th, 2010, 12:40pm:If you use radians instead of degrees and use atan2() to solve them, you'll probably not get those problems anymore.
I did use radians and atan2, but still could not figure it out. I have it working now, but I had to use a bunch of if/elses as I suspected. Not sure if I can do it any other way.
Here is the code I used. I know it can be simplifid, I just wanted to type everything out, to make it clearer to myself
void checkAngles(){
v2ang += TWO_PI;
v2ang %= TWO_PI;
//
fill(0, 102, 153);
textFont(font,20);
text("v2ang = "+v2ang, 15, 30);
text("v1ang = "+v1ang, 15, 50);
if (v2ang > v1ang){
// ok, this means that v1ang is closer to 0 degrees, than v2ang, but it does not say anything about which quadrant they are ...
// then ...
if( v2ang - v1ang > PI){
// if the difference is more than PI, i.e. a half circle, then the angle is obtuse,
// and the fastest way to get closer to the other angle is to increase it ...
v2ang += TWO_PI/200;
}
else {
v2ang -= TWO_PI/200;
}
}
else if (v2ang < v1ang){
// this means that v1ang is closer to TWO_PI than v2ang is ...
// subtract the smaller from the bigger ...
if( v1ang - v2ang > PI){
// again: if the difference is more than PI, i.e. a half circle, then the angle is obtuse,
// and the fastest way to get closer to the other angle is to increase it ...
v2ang -= TWO_PI/200;
}
else {
v2ang += TWO_PI/200;
}
}
}