tinycodinglm / math /math-0170.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
1.31 kB
{"type": "session", "harness": "opencode", "id": "math-0170", "name": "Computational Geometry: Polygons"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain polygon algorithms for computational geometry"}}
{"type": "message", "message": {"role": "assistant", "content": "Polygon: list of vertices in order (CW or CCW).\n\nArea (shoelace formula): A = 0.5 * |sum(x_i * y_{i+1} - x_{i+1} * y_i)|. Positive=CCW, negative=CW.\n\nPerimeter: sum of edge lengths.\n\nPoint in polygon:\n- Ray casting: shoot ray from point, count edge crossings. Odd=inside, even=outside.\n- Winding number: count signed angle traversed around point. Non-zero=inside.\n\nConvex hull:\n- Graham scan: sort by angle from lowest point, maintain stack, pop on right turn. O(n log n).\n- Monotone chain: sort by x then y, build upper/lower hull. O(n log n). Simpler.\n- Jarvis march: gift wrapping. O(nh) where h=hull size. Good when h is small.\n\nPolygon triangulation: ear clipping O(n^2). For convex: fan from vertex 0.\n\nRotating calipers: find diameter, width, minimum bounding rectangle of convex polygon in O(n).\n\nMinkowski sum: sum of two convex polygons. O(n+m). Used for collision detection."}}