tinycodinglm / math /math-0171.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
1.23 kB
opencode trace
System You are an expert mathematician and programmer.

You are an expert mathematician and programmer.

User

Explain computational geometry for competitive programming

Assistant

Point/vector: struct with x,y. Operations: +, -, dot (a.xb.x+a.yb.y), cross (a.xb.y-a.yb.x).
Cross product: |a||b|sin(theta). Positive=left turn, negative=right, zero=collinear.
Dot product: |a||b|cos(theta). Zero=perpendicular.

Convex hull: Graham scan O(n log n). Sort by angle, maintain stack, pop on right turn.
Line intersection: solve 2x2 system. Two forms: point-slope or parametric.
Polygon area: shoelace formula. Area = 0.5*|sum(x_i*y_{i+1} - x_{i+1}*y_i)|.
Point in polygon: ray casting or winding number.
Closest pair: divide and conquer O(n log n).
Rotating calipers: diameter, width, min bounding rectangle of convex polygon.
Half-plane intersection: intersect n half-planes, O(n log n).
Circle-circle intersection: up to 2 points.
Line-circle intersection: substitute line into circle equation.