Determine angle clockwise with loops for path geometry

154 views Asked by At

I'm creating path tool programmaticaly and im stucked in one point. I need to add loops to connections with acute angle. I have all data but still dont know how to determine when set CW or CCW angle direction for loop arc. Result below for fixed CW.

enter image description here

1

There are 1 answers

0
J Trana On

So if you're just trying to go for clockwise or counterclockwise, it may be easiest to think of it as just left or right. To think about it that way, suppose you have the points a, b, and c in your example above. As you have guessed, that vector with p that you have in there makes a difference; basically if you average b and c to find their mid point, that will always be left or right of a which gives you your answer. So, average b and c, and check to see if the x coordinate is bigger than a's x coordinate. Hope that makes sense.

Note that this simple model will likely break down in ways you don't want for edge cases with things like near vertical angles - I'm not sure how you've chosen to handle those but ultimately you may want a more robust model.