Page 2 of 2

Re: How to do collision detection between two lines?

Posted: Mon Feb 14, 2022 9:21 pm
by Screepy
Karai17, you are right, good suggestion

Re: How to do collision detection between two lines?

Posted: Mon Feb 14, 2022 11:33 pm
by pgimeno
Unfortunately, CPML does not detect any intersection when the segments are collinear. This code:

Code: Select all

local cpml = require 'cpml'

local r, e = cpml.intersect.segment_segment(
  {cpml.vec3.new(1, 0, 0), cpml.vec3.new(3, 0, 0)},
  {cpml.vec3.new(2, 0, 0), cpml.vec3.new(4, 0, 0)}
)

if r then
  print(r[1].x, r[1].y, r[1].z)
  print(r[2].x, r[2].y, r[2].z)
else
  print(r)
end
prints 'false'.

Re: How to do collision detection between two lines?

Posted: Tue Feb 15, 2022 2:47 pm
by Karai17
Notably, CPML is a games-first math library and not a scientific library. Extremely precise or exact circumstances are generally fleeting in games so a contrived example such as perfectly colinear line segments producing a false negative result is arguably within reason. That being said, we'll look to add a special case for detecting colinear line/segment collision, assuming the algorithm currently implemented does not have a subtle bug that would otherwise detect them correctly (such as a > instead of a >=, for example).

Re: How to do collision detection between two lines?

Posted: Wed Feb 16, 2022 12:48 am
by pgimeno
It's just that in my experience, corner cases are the ones that end up biting your ass. Remember that in this case, you're recommending a 3D library for a 2D problem.