All problems‎ > ‎

Line segment intersection

In geometry, a common problem is to determine whether two lines defined from points A to B and C to D respectively, intersects.

Using Test-Driven Development, develop a Line2d class with the following functionality:
  • Constructed given points A=(x1,y1) and B=(x2,y2)
  • A line L1 can answer the question "Do you intersect with line L2?"
This problem illustrates some problems associated with geometric algorithms specifically, and floating-point/numerical algorithms in general; we have to decide what to do with round-off errors.
Comments