For focusing the image of a telescope, one can use a Bahtinov mask. How does this mask work, and how did Mr Bahtinov get the idea to cut such a peculiar shape? Is it possible for me to design my own focusing masks?
The idea is to create a specific diffraction pattern so that you know if you image is in focus. The pattern is so that you end up with 3 lines crossing the source.
The mask consists of three separate grids, positioned in such a way that the grids produce three angled diffraction spikes at the focal plane of the instrument for each bright image element (star). As the instrument's focus is changed the central spike appears to move from one side of the star to the other. In reality, all three spikes move but the central spike moves in the opposite direction to the two spikes forming the 'X'. Optimum focus is achieved when the middle spike is centered on the star and symmetrically positioned between the other two spikes. Small deviations from optimal focus are easily visible.
You can construct a mask with some materials:
There is also a Hartmann Mask that splits the object into multiple when not in focus. This seems a little easier to construct.