Lidar, sonar, and radar all work generally the same:
- Emit a pulse. For radar, this means briefly energizing an antenna. For sonar, it means briefly energizing a sound transducer/speaker. For lider, this is means briefly flashing a light (typically a laser).
- As you emit the pulse, start a timer.
- Wait for a reflection to return. For radar, this means an electrical pulse in your antenna. For sonar, it's an acoustic pulse at a microphone. For lidar, it's a light flash at a photosensor.
- When you detect the reflection, stop the timer.
- Calculate the distance traveled by your reflected pulse by dividing the speed of transmission by the elapsed time. For radar and lidar it's the speed of light, for sonar it's the speed of sound. These speeds will vary depending on the medium through which your pulses are propagating. For the speed of light, the variation may not be big enough to matter, but for sonar it will definitely matter. For underwater sonar things like salinity, temperature, etc. is enough to make a big impact.
- The distance calculated in step 5 above determines how far the pulse traveled. Assuming the pulse transmitter and the receiver are co-located, this would be twice the distance to the obstacle because the pulse has to travel out to the object and then back to the receiver.
- Associate the distance to the obstacle with the direction the transmitter was pointed. This should now give you a distance and heading of the object with respect to your transmitter's base frame. This is how scan data from a laser scanner is typically returned - as a distance and angle (i.e., polar coordinates).
- Finally, once steps 1-7 are completed, the emitter is pointed in a new direction and the process repeats. For lidar systems, typically a laser points down at a mirror that is angled at 45 degrees. The mirror spins about the vertical axis and, in doing so, continuously re-aims the output of the laser. Radar systems use motors to spin the antenna/dish. Sonar systems (especially underwater sonar) actually tend to be constantly oriented and are towed/pulled along.
These are the essentials of how all of the detection and ranging systems work. Here are some finer points that were difficult for me to understand when I was trying to learn more about radar systems. These seemed to be points that were clearly understood by most authors, but nobody laid any of these points out in any singular text that I ever read:
- You don't get any information about the width of the object that causes the return. Usually, for radar and sonar systems, it's assumed that the object that causes the reflection occupies the entire beam width at whatever the calculated distance is. This can cause smearing and poor resolution if the beam isn't narrow enough. For lidar systems the returns are generally treated as a single point in the center of the beam.
- Following on the above, it's possible that the object doing the reflecting only occupies a portion of the "illuminated" or pulsed area, and it is possible (read:likely) to get a subsequent return from whatever is behind the first object. For lidar systems, rain, dust, etc. will frequently cause this. Whether or not you get the data about subsequent returns is generally referred to as whether or not the device has "multi echo" capability.
- Also following on points 1 and 2, it's not possible to discriminate against a portion of the pulse that weren't intending to listen for. No device has perfect edges to the transmission beam, but highly reflective objects that are outside of the design beamwidth may be reflective enough to generate a detectable echo with the low-energy portion of the pulse. This creates a star- or plus-shaped "dazzling" pattern in the return data, like you can see below.
- It is entirely possible for the device to receive signals that it did not generate and to treat those as valid returning pulses. This is known as "jamming" and happens if there is some external emitter that is (coincidentally or intentionally) transmitting a similar enough signal to be accepted by the receiver.
- Following kind of on point 4 above, there are generally times when the receiver won't detect anything at all. For systems like radar and sonar, the aperture that generates the pulse is the same object that will do the detection and so there is some switching time where the residual motion/charge that is in the aperture needs to be adequately dissipated until the receiver can "listen" for the return. For lidar systems there may be a need to change the optical return path to change from the emitter->lens to lens->receiver. These switching times will determine the minimum range for the system.
Finally, regarding your question about 2D versus 3D, this generally refers to whether or not the device is detecting points along a single line (a single scan plane) or along multiple lines (multiple scan "planes" which, for non-zero "plane" angles, actually create scan cones).
:EDIT:
Forgot - here's a good picture from a synthetic aperture radar system showing some highly reflective objects - they make the + patterns in the data where they're creating a detectable reflection even though the radar isn't pointed directly at it. It's kind of like a lens flare, but not exactly the same mechanism.