tinycodinglm / math /math-0168.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame
1.21 kB
{"type": "session", "harness": "opencode", "id": "math-0168", "name": "Computational Geometry: Lines and Segments"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain lines and segments for computational geometry"}}
{"type": "message", "message": {"role": "assistant", "content": "Line representation:\n1. Point-slope: point p + direction d. p + t*d for t real.\n2. Implicit: ax + by = c. Normal vector (a,b). For points p1,p2: a=p2.y-p1.y, b=p1.x-p2.x, c=a*p1.x+b*p1.y.\n3. Segment: two endpoints [a,b]. Parameter t in [0,1].\n\nLine-line intersection: solve a1*x+b1*y=c1 and a2*x+b2*y=c2. Det = a1*b2-a2*b1. If det=0: parallel/coincident. Else: x=(c1*b2-c2*b1)/det, y=(a1*c2-a2*c1)/det.\n\nSegment intersection: check bounding boxes overlap, then cross products for proper intersection. Handle collinear cases.\n\nPoint on segment: cross(p-a, b-a)=0 and dot(p-a, p-b) <= 0.\n\nDistance from point to line: |cross(b-a, p-a)| / |b-a|.\nDistance from point to segment: project onto line, clamp to [0,1].\n\nPerpendicular bisector: midpoint of a,b, perpendicular to (b-a)."}}