Formlabs / foxtrot

A fast, experimental STEP file viewer
Apache License 2.0
218 stars 16 forks source link

FIX: Newton's method singularities causing failure to lower points to 2D in NURBS surfaces. #7

Closed tom-ainc closed 1 year ago

tom-ainc commented 1 year ago

Frequently BSpline surfaces failed to lower points to 2D because of the use of try_inverse() to compute the gradient delta_i - this is because using this method, if you arrive at a stationary point, J_i stops being invertible.

The solution here uses the pseudo inverse, which basically resolves to [0 0; 0 0], making delta_i = 0 (as expected), rather than returning None.

Another option would be to simply set delta_i = 0 when try_inverse is None, however the psuedo-inverse is preffered because it sets only the singular values below epsilon (chosen arbitrarily here to 1e-4) of the inverted matrix to 0. This typically results in the 0 matrix, maybe there are times when it doesn't and you'd stop prematurely, I couldn't tell you for certain if that ever happens, can't hurt though...