2
votes

How can I tell if these points are connected counter-clockwise or clockwise? I have this code in my GameScene.m:

CGFloat radius = (self.frame.size.width - 6) / 2;
CGFloat a = radius * sqrt((CGFloat)3.0) / 2;
CGFloat b = radius / 2;

UIBezierPath *pathFirstTrigon = [UIBezierPath bezierPath];

[pathFirstTrigon moveToPoint:CGPointMake(0, -radius)];
[pathFirstTrigon addLineToPoint:CGPointMake(a, b)];
[pathFirstTrigon addLineToPoint:CGPointMake(-a, b)];
[pathFirstTrigon closePath];
2

2 Answers

0
votes

The orientation can be deduced from the signed area. You can calculate the signed area from the sum of cross products of consecutive points:

2 * area = (0, -radius) x (a, b) + (a, b) ⨯ (-a, b) + (-a, b) ⨯ (0, -radius)

With the definition of the 2D cross product:

(a, b) ⨯ (c, d) = a * d - b * c

This gets you:

area = a * radius + a * b

Use the sign of the area to determine if the path is clockwise or counter-clockwise (which one refers to what sign depends on your coordinate system).

0
votes

What you have is something similar to :

           Y
(-a,b)     ^    (a,b)
   +       |      +
           |
           |
           |
           | 
   --------+---------> X
           |
           + (0,r)
           |

So it is counter-clockwise on standard coordinates system.