How to do collision detection between two lines?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Screepy
Prole
Posts: 3
Joined: Tue Dec 07, 2021 8:35 am
Location: United States
Contact:

Re: How to do collision detection between two lines?

Post by Screepy »

Karai17, you are right, good suggestion
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to do collision detection between two lines?

Post 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'.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: How to do collision detection between two lines?

Post 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).
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to do collision detection between two lines?

Post 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.
Post Reply

Who is online

Users browsing this forum: GoldenTCat, Semrush [Bot] and 5 guests