An apparatus and method for measuring optically the position or angle of a variety of objects or arrays of objects, including cantilevers in scanning probe microscopy, micromechanical biological and chemical sensors and the sample or a probe in surface profilometry. The invention involves the use of one or more diffractive optical elements, including diffraction gratings and holograms, combined with conventional optical elements, to form a plurality of light beams, each with a selectable shape and intensity, from a single light source, reflect the beams off mechanical objects and process the reflected beams, all to the end of measuring the position of such objects with a high degree of precision. The invention may also be used to effect mechanical changes in such objects. Devices with these improvements have numerous applications, including molecular force measurements, atomic force microscopy and manipulation technology, lithographic manufacturing, nanometer scale surface profiling and other aspects of nanotechnology.