How to do collision detection between two lines?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: How to do collision detection between two lines?
Karai17, you are right, good suggestion
Re: How to do collision detection between two lines?
Unfortunately, CPML does not detect any intersection when the segments are collinear. This code:
prints 'false'.
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
Re: How to do collision detection between two lines?
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é
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
Re: How to do collision detection between two lines?
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.
Who is online
Users browsing this forum: GoldenTCat, Semrush [Bot] and 5 guests