Minimum and maximum Distance to Surface / help needed

My initial thought was, window by window, reference the window, reference some of the small surface triangles around the window, create a series of points around the window glass to calculate the normal distance to the surface. Calculate a new plane and position for the window and check the new distances.

This takes the innermost glass surface.

Some of the points miss the target surface because it looks like the aperture is bigger than the glass?

Will you only move the glass in or out along its normal vector or does the glass need to be re-oriented on a new, best fit plane?

This lets you move the glass in and out and see the range of distances change.

The geometry is internalised in the GH file. DistToScanSurf.gh (5.7 MB)

This is a starting point… hopefully it can help.