aardvark-platform / aardvark.base

Aardvark.Base is the foundation of the open-source Aardvark Platform for visual computing, real-time graphics, and visualization.
https://aardvarkians.com/
Apache License 2.0
154 stars 9 forks source link

Plane2d.Interesects(Ray2d, out V2d hit) numerical issues and overcomplicated #44

Closed luithefirst closed 3 years ago

luithefirst commented 4 years ago

The method Plane2d.Interesects(Ray2d, out V2d hit) uses the IsOrthogonalTo check as early exit (same as method without V2d hit output argument) to return false if there is no hit. Still, the method occasionally throws ArgumentException("singular matrix") in LuFactorize after passing the early exit test.

  1. I don't think the intersection calculation should require a LU-factorization
  2. Using PositiveTinyValue for the early exist test is most likely too tiny in practice as the calculated intersection would be too imprecise. Note: If changed make sure this is consistent with other methods like Plane2d.Interesects(Ray2d)

Example:

var plane = new Plane2d(new V2d(-3.6701585479226354E-16, 1), 1.5236516412689705);
var ray = new Ray2d(new V2d(1.8373474556174547, 1.5236516412689713), new V2d(1.8299999713048472, -2.2204460492503131E-16));
plane.Intersects(ray, out var hit);
hyazinthh commented 3 years ago

Fixed in https://github.com/aardvark-platform/aardvark.base/commit/d57f7f378e2384056d1dac527059ee36745a826c

Simply replaced the implementation with the one from the Ray3d - Plane3d implementation. This one now returns PositiveInfinity instead of NaN in case there is no intersection (consistent with 3d case behavior)