in reply to Clockwise or Counter-clockwise
What assumptions can you make about the collection of vertices? Is the geometric figure always convex? Can edges cross?
The vector cross product of a pair of successive edges in the x-y plane will be negative if the lines break right (clockwise), positive if they break left (counterclockwise). Given vertices at ($x1,$y1), ($x2,$y2), and ($x3,$y3),
That is not reliable unless the figure is convex. A banana shaped figure will have different sign at different vertices.my ($dx1, $dy1) = ($x2 - $x1, $y2 - $y1); my ($dx2, $dy2) = ($x3 - $x2, $y3 - $y2); my $cross = $dx1*$dy2 - $dy1*$dx2; print $cross < 0 ? "clockwise" : $cross == 0 ? "collinear" : "counterclockwise";
The numeric tags on those variables look like a shout for arrays, but they are just labels. The natural place to use arrays here is to group x and y for each vertex.
After Compline,
Zaxo
|
|---|