Check if two polygons overlap: Difference between revisions
→{{header|jq}}: def AB:
(→{{header|jq}}: 2D convex polygons) |
(→{{header|jq}}: def AB:) |
||
Line 242:
=={{header|jq}}==
'''Adapted from [[#Wren|
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''
Line 251:
* a projection is represented by a JSON object {min, max}
<syntaxhighlight lang="jq">
# Input: [$A, $B] where $A and $B are points
# Output: the vector $B - $A
def AB:
. as [$A, $B]
| [ $B[0] - $A[0], $B[1] - $A[1]];
# Input: a vector
# Output: perpendicular
Line 265 ⟶ 271:
$poly[$i] as $vertex1
| $poly[if $i+1 == ($poly|length) then 0 else $i+1 end] as $vertex2
| . + [ [$vertex1
# emit {min, max}
|