Both the “intake” kind like 35mm snapshot cameras, and slide projectors. How the heck would the machine know, especially when it’s projecting?
The camera sends an infrared beam. It bounces off the subject and back to the camera, which can determine the distance by how the beam changes.
There are two kinds of autofocus: active (which is what RealityChuck describes) and passive. The passive system, which is what more expensive cameras and slide projectors use, analyzes the picture itself. How Stuff Works has a good description of the two.
There’s more than two kinds. Another kind, popular on some cheap Polaroid camers, has an ultrasonic transducer on the front (it’s golden and the size of a quarter, under a perforated metal cover). This sends out a beep and times how long it takes to hear the echo, like sonar.
Some of the kinds that analyze the image try measuring its contrast as they change the lens focus. The contrast, or the variability in brightness between a number of measurement points, is maximized when the lens passes through the best focus setting. At least some of the cameras with infrared sources just use the source to guarantee enough illumination for this scheme.
I used to be a photo major and also worked at a camera store for a few years in high school so I will take a shot at this. I believe the disposable or really cheap “auto-focus” cameras achieve this feat by having a really high ‘aperture’. This ‘aperture’ is the opening in the lense that allows light in. In most cameras this can open and close (kinda like the human eye during changes in brightness). The lower the aperture the bigger the opening is and vice-versa.
Functionally, the difference between a high aperture (small opening) and a low aperture(large opening) is that the higher the aperture is the more dimensional the resulting image appears. For example, if you had your lense opened all the way(aperture of f1.8 or so) the object that has been focused on will appear sharp and clear while anything in front of or behind that object will appear blurred out. This effect is often used for portraits to accentuate the person.
On the other hand, the highest aperture (f22 I believe) will have an extremely small pin-like opening in the lense. The result of this is that everything (mostly) that the camera can see will appear in focus. This effect is often used for posters and landscapes. The aperture also affects the overall sharpness of the picture (depending on how stable the camera is) because a smaller opening will take a longer time to expose the film, thus increasing the likelihood of shaking. Using this same principle you would probably be better off setting as low of an aperture as possible in low-light situations so that you can get as much light as possible.
For more expensive cameras there is an infrared metering sensor, as already mentioned) which detects the distance to the object being focused on(which with most cameras is the object in center). It has been a while since I was really into photography but IIRC this should be how it works.
This is a fixed-focus camera, not auto-focus. Fixed focus camera are generally the cheapest of the non-focusing cameras, and generally have the poorest picture quality, although it can be very acceptable in the right circumstances.
In the system you describe, the focus never actually changes, you just have a lens with a fairly small aperture set at the hyper-focal setting (the setting that gives you the greatest depth of field, and where the depth of field extends essentially to infinity). Since everything from about three or four feet out to infinity is (mostly) in focus all the time, there is no need focus, either manually or automatically.
True auto-focus cameras (as mentioned by others) use several different techniques. Some actually measure the distance to the main subject using infrared beams or ultrasonic sound, some analyze the picture itself. These generally give superior sharpness across a wider range of distances and situations.
Auto-focus slide projectors are (or least were) a little different. Since the distance from the projector to the screen is generally fixed while showing a group of slides, once the image is focused, the only thing that can change the focus is the distance from the slide to the lens. Since the slides can move a round a little, this distance can change a little. An auto-focus projector measures this distance by bouncing a little light off the surface of the slide at an angle, and uses little servo-motors to adjust the lens by small amounts as this distance changes. But you still have to focus the projector once by hand. After that, the auto-focus keeps you from having to play with the focus for every slide. At least this is the way it was ten or so years ago when I bought my last auto-focus projector.
Ugly