I'm creating an application that generates lenses based on a prescription, and places those lenses into frames so that the user can get a feel for how the lenses might look. The problem I'm facing is that I'm unable to consistently place lenses into frames at the correct location/rotation. This is because:
- Each frame has different geometry i.e. some are flatter, some are angled, circular, etc
- Each lens has different geometry, based on the prescription, and then the cut out that's made to fit into the specified frame.
What I have at the moment is a set transformation for each frame that the lenses just copy, which only works for a small range of prescriptions.
Examples:
Lenses are too far back
Not rotated properly
Location is ok, but the curvature causes it to no connect
I'm aware that my lens generation algorithm isn't perfect and makes it harder (can be seen in the last pic) but at the moment I need to focus on the lens placement and consider the generation to be a block box.
Some solutions I've thought of:
- Shrinkwrap the lens onto a preset shape. Would probably look ok but takes away from the whole point of the application by deforming the lens.
- Create a set of anchor points on the frames, a corresponding number of anchor points on the lenses, and then "anchor" the corresponding anchor points on the frame and lens. While I can create the anchor points on the frames beforehand and use it as a present, I'm not sure how I would create the anchor points on the lenses algorithmically. I'm also not sure what a good criterion would be for where I would create the anchor points, nor how many. I'm also not sure how I could ensure that anchoring one pair of points doesn't disconnect a previously anchored pair.
- Go with solution 2, but use a minimizer to find the best rotation/location of the lens relative to the frame. I'd still need to define anchor points, giving me the same problems as number 2, but I'd have a minimizer instead of a weird algorithm trying to match all the points. I feel like this would work the best, but I'm not sure how I would create the minimizer or the anchor points.