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

You are an expert mathematician and programmer.

User

Explain lines and segments for computational geometry

Assistant

Line representation:

  1. Point-slope: point p + direction d. p + t*d for t real.
  2. Implicit: ax + by = c. Normal vector (a,b). For points p1,p2: a=p2.y-p1.y, b=p1.x-p2.x, c=ap1.x+bp1.y.
  3. Segment: two endpoints [a,b]. Parameter t in [0,1].

Line-line intersection: solve a1x+b1y=c1 and a2x+b2y=c2. Det = a1b2-a2b1. If det=0: parallel/coincident. Else: x=(c1b2-c2b1)/det, y=(a1c2-a2c1)/det.

Segment intersection: check bounding boxes overlap, then cross products for proper intersection. Handle collinear cases.

Point on segment: cross(p-a, b-a)=0 and dot(p-a, p-b) <= 0.

Distance from point to line: |cross(b-a, p-a)| / |b-a|.
Distance from point to segment: project onto line, clamp to [0,1].

Perpendicular bisector: midpoint of a,b, perpendicular to (b-a).