This was bugging me so I tried to work on it myself and then looked around the internet for a better solution. I happened on an example in some open source code and wrote a Processing version.
Quote:float angleOne, angleTwo;
boolean increase;
void setup() {
size(400,400);
noFill();
float cx = width/2;
float cy = height/2;
angleOne = atan2(random(height)-cy, random(width)-cx);
angleTwo = atan2(random(height)-cy, random(width)-cx);
if(sin(angleTwo-angleOne)>0) {
increase = true;
}
if(sin(angleTwo-angleOne)<0) {
increase = false;
}
}
void draw() {
background(196);
stroke(255,0,0);
pushMatrix();
translate(width/2,height/2);
rotate(angleOne);
line(0,0,50,0);
popMatrix();
stroke(0,255,0);
pushMatrix();
translate(width/2,height/2);
rotate(angleTwo);
line(0,0,50,0);
popMatrix();
// if(abs(angleTwo-angleOne)>.2) {
// if(increase) {
// angleOne += .01;
// } else {
// angleOne -= .01;
// }
// }
stroke(0);
if(increase) {
arc(width/2,height/2,25,25,angleOne,angleTwo);
} else {
arc(width/2,height/2,25,25,angleTwo,angleOne);
}
}
void mouseClicked() {
setup();
}
The critical part is in
setup. The
sin(angleTwo-angleOne) determines direction. The arc is drawn on the shortest angle. You could also add to
angleOne (red) if increase is true (subtract if its false of course) to turn the shortest way towards
angleTwo (green). My commented code wouldn't work to stop the turn when they were close for some reason though. Click for a new set of angles.
I guess its not a whole lot less complex than knutEinar's last example, but I was glad I found it anyway.