Lines intersection bug

https://jsfiddle.net/agprhq4L/

Hi! Just use:

    const raycaster = new THREE.Raycaster();
    raycaster.params.Line.threshold=0.1;


Edit fiddle - JSFiddle - Code Playground

When the camera is in a specific position, the bug will still appear

Your camera placed into line. Move it

    camera.position.set(
    0.004478507586958502,
  9.22983851329365,
  -0.015975643909931822
  );

image
And set near=0.05 to see near pixels of line
camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 0.05, 1000);

1 Like

Edit fiddle - JSFiddle - Code Playground


fat line same conditions


Edit fiddle - JSFiddle - Code Playground
line

This is more an artifact of the current implementation rather than a bug but I agree it’s unexpected. The way line raycasting works is it tests how far the ray is from each line segment in world coordinates and if it’s within the raycaster.params.Line.threshold value it’s considered a hit. The threshold defaults to 1 meaning when the line gets close to the camera basically the entire near camera plan is encompassed by this “hit” volume.

I think the way fat line intersections is more intuitive in that it’s a pixel-perfect value so no matter how far or close to the line you are the threshold is consistent. Line could be implemented this way but it would require having access to the camera in order to function.

I’d recommend making an issue in three.js repo if you’d like different behavior to see what the maintainers think.

1 Like