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

You are an expert mathematician and programmer.

User

Explain geometric primitives for programming

Assistant

struct Point { double x,y; };
dot = a.xb.x+a.yb.y; cross = a.xb.y-a.yb.x;
len = sqrt(dot(a,a)); dist = sqrt(dot(a-b,a-b));

Lines: ax+by=c. Two-point form: cross(b-a,p-a)=0 for point p on line through a,b.
Intersection of two lines (a1,b1,c1) and (a2,b2,c2): det=a1b2-a2b1. x=(c1b2-c2b1)/det, y=(a1c2-a2c1)/det.

Segment intersection: check bounding boxes overlap, then cross products for proper intersection.
Point on segment: collinear and within bounding box.

Polygon: vector of points. Area via shoelace. Contains point: ray casting (count crossings with ray from point).

Convex polygon: all left turns. Binary search for point inside (monotone chain).

Circle: center (cx,cy), radius r. Area = pi*r^2. Point in circle: dist <= r.
Inscribed circle: intersection of angle bisectors.

Epsilon comparisons: fabs(a-b) < 1e-9 for floating point equality.