Segment Intersection

medium · geometry, orientation, line-segment

Segment Intersection

Given two line segments, determine if they intersect (including endpoints). Each segment is represented as [x1, y1, x2, y2].

Function signature

func SegmentsIntersect(a []int, b []int) bool

Example

a = [0,0,3,3]
b = [0,3,3,0]
output = true

Constraints

  • a and b each have length 4
  • -1_000_000_000 <= coordinates <= 1_000_000_000

Notes

  • Use orientation and on-segment checks.
Run tests to see results
No issues detected