I am a programmer and I am doing a camera simulation, I am stuck in a matter of how to know where does every ray of light incident after traveling through the lens, every point of the object will give infinity number of rays. In my simulation, I will take five random rays from every point from the object, and from one point of the object the rays should also be incident on one point on the film. hHw can I know this specific point from film for each point from the object?
You are effectively asking about the geometric behavior of light...rays extending from points, passing through lenses, being bent, and focusing somewhere. This is a very well understood model of the behavior of light, and there are some excellent resources out there that cover the topic. It is much too involved to cover here, so I'll just quote from a couple of my favorite resources on the topic:
Physical & Geometric Optics
Light propagates in the form of oscillations in an electromagnetic field, which expand from a point light source as evenly spaced and concentric wavefronts. The energy carried in the oscillations is measured in quantum packets known as photons.
The radiation of light through space can be represented in two ways: (1) as actual wavefronts that expand concentrically and radially from the light source (analysis by physical optics), or (2) as imaginary light rays perpendicular to the wavefronts that extend radially from the light source and indicate the direction in which each part of the wavefront is moving (analysis by geometric optics). The basic parameters of optical elements described in this page are developed in terms of geometric optics.
The true nature of light is energy propagating as a wavefront. The Astronomical Optics page is an excellent one, and describes the geometric nature of light and design and behavior of optics quite well without getting too deeply into the theory. It should be sufficient for your purposes.
A richer resource covers the nature of light at a lower level, and describes the true nature of light at a very low level: Wavefronts are diffracted energy, propagating through space via secondary wavelets that disperse photons from the primary wavefront which interfere with each other in such a manner as to maintain the nature and propagation of the wavefront (barring obstructions in the light path.) This is a more complex description, but more mathematically complete and accurate:
Rays, waves and wavefront
Any optical image - and those formed by telescopes are no exception - is made of light: a form of electro-magnetic radiation. More precisely, a telescope image is made by imaging a countless number of light-emitting point-sources from faraway objects. As shown on FIG. 1, light waves emitted by a point-source spread out in a concentric pattern, propagating as an oscillating energy field. It is convenient to present wave oscillation as a cycle, the full cycle being 360 degrees, or 2π radians. Phase of wave oscillation is, for harmonic sinusoidal wave, defined by o=Asin(2πx/λ), where A is the wave amplitude, defined as the maximum value of wave oscillation, x is the length of wave path from the origin, and λ the wavelength of light (FIG. 1, top left).
An imaginary surface connecting wave points of identical oscillatory motion, or phase, is called phasefront. Geometrical approximation of the phasefront, based on the identical ray optical path length (OPL) from the source is called optical wavefront, or simply wavefront. For optical telescopes, phasefront and wavefront are, for all practical purposes, identical as long as the wavefront error remains relatively small. The difference between the two comes from the latter increasing directly with the nominal wavefront deviation, while the former follows the increase nominally, but effectively it oscillates from the maximum constructive interference for wavefront points deviating any whole number of waves - including, of course, zero deviation - decreasing to zero constructive interference from any wavefront point deviating by an odd whole number of half-wave deviations.
Ray, on the other hand, is simply a straight line with the origin at the point-source, that remains perpendicular to the wavefront. While rays are useful in presenting geometrical aspects of optical phenomena, they represent only a tiny fraction of the total energy propagating through the energy field. Furthermore, it is only their geometric properties that are being considered. Therefore, ray (or geometric) optics has no direct relation with the physical properties of the energy field.
Geometry of rays is superficial, but useful concept, not only for approximating image location and size, but for the initial assessment of its quality as well. Since any wavefront deformation results in disturbance of rays, thus scattering the rays around the center point of a perfect reference sphere, it indicates whether an optical system is perfect, or not. To some extent, ray disturbance indicates the severity of wavefront error, which makes it a convenient tool for the initial assessment of wavefront/image quality. Also, it is useful for determining geometric relations between optical elements and images they form. However, for the specifics about actual energy distribution around the focal point we need physical optics.
The wavefront, while itself geometric category, is more directly related to the underlying physics. It identifies the location of in-phase wave sources, making it the basis for calculations determining the properties of wave interactions at and around focal point - i.e. diffraction calculation. Hence, the significance of the wavefront is in that its form directly determines quality of optical imaging in a telescope. Obviously, form of the wavefront and geometric properties of the rays are directly inter-related, but the ray geometry remains only loosely related to the interactions taking place within the energy field. The most striking example is that of a spherical wavefront, whose rays all meet in a single point. At the same time, the actual physical image formed by waves emerging from the wavefront is a bright spot surrounded by a series of fading rings. How is this taking place?
The answer is that light energy does not propagate in straight lines; rather, it propagates according to the Huygens's principle. But first a quick look at how light waves interfere.
The geometric behavior of light is largely sufficient to describe how lenses bend and focus light from a point light source, and should be sufficient for your needs. Should you need to address diffraction, which is the consequence of obstructions in the light path (diffraction does NOT cause light to bend, that is a common misconception and a myth):
As a consequence of the existence of diffracted wave energy, placing obstruction of some form in the light path will result in the "emergence" of this energy in the space behind obstruction. But the obstruction did not change anything in the way the light propagates - it merely took out energy of the blocked out principal waves, with the remaining diffracted field creating some form of intensity distribution in the space behind obstruction - the diffraction pattern.
Similarly, by limiting energy field to an aperture, the portion passing through it is separated from the rest of the field, and its energy - this time consisting from both, aperture-shaped principal waves and diffracted waves from within - will create a pattern of energy distribution behind the aperture. Again, there is no actual change in propagation for the light passing the aperture, including those close to the edge of obstruction (light does not "bend around the edge"); whatever the form of energy distribution behind the aperture, it is caused by the interference of the primary and diffracted waves inherent to the energy field (FIG. 1, middle and bottom). It is due to the missing portion of the field - the one left out of the aperture - that the field after passing it changes, with the diffracted field having a different spatial amplitude distribution than the incident field.
If you need to account for diffraction, the TelescopeOptics.net site is probably the better resource.
Regarding the required math to determine how light dispersed from a point source is refracted by a lens and focused to a point. The first concept is to understand refraction as related to the geometric nature of light, which follows a very simple rule:
Wavefronts of light have a uniform speed c in a vacuum. Light can also propagate through various transparent materials, such as air, water or glass, but each material slows the speed of light by a specific value — in some materials, to almost one third its vacuum speed. The speed of light in a vacuum divided by the speed of light in a refracting material (m) is the refractive index (n) of the material:
n = c/m
This is 1.00029 for air; 1.3333 for water; and anywhere from 1.4 to 2.0 for optical glasses.
The "bending" of light as it crosses from a material of one refractive index to another is not really "real" in the sense we commonly think of it. The bending of light is a consequence of different parts of a wavefront reaching the boundary of the two materials (i.e. where air meets glass) at different times:
As the wavefronts of light AB, traveling across distance BC, encounter a refracting boundary AC, the speed of the wavefronts is slowed so that they now travel a shorter distance AB' in the same time. This bends or refracts the wavefronts in a different direction because adjacent points along each wavefront encounter the boundary at different times (t1 to t5) across its width AB.
Geometric rays are always (by definition) at right angles to the wavefronts they describe, so they create the right triangle ABC before refraction and AB'C after refraction, with side AC in common. Inspection of the diagram shows that the angle of incidence (θ1) is equal to the angle BAC, whose sine is equal to BC/AC; and the angle of refraction (θ2) is equal to the angle B'CA, whose sine is equal to B'A/AC. Since AC is a common denominator, the sines differ in the ratio BC/B'A. The diagram shows that this is the ratio of the speed of light in the two media, which is measured as the index of refraction, and therefore the sine ratio is equal to the inverse refraction ratio n2/n1.
This relationship is summarized as Snell's Law or the Law of Refraction, illustrated in the diagram by the yellow arrows and defined mathematically as:
sine(θ1)/sine(θ2) = n2/n1
sine(θ1)·n1 = sine(θ2)·n2
where n1 and n2 are the refractive indices of the two media that form the refracting boundary, and θ1 and θ2 are the angle of incidence and angle of refraction. These angles are measured from a line normal (perpendicular) to the boundary surface of the two media at the incidence point of a light ray. Both light rays and the line normal must lie in a single plane, and the incident and refracted rays will be on opposite sides of the line normal.
This is what gives rise to the geometric nature of light. There aren't actually any "rays", there is simply the wavefront. However the behavior of that wavefront is such that we can reduce the complexity of having to account for trillions of individual photons propagating through that wavefront, to simply needing three primary "rays":
In the Gaussian analysis, the optical system is assumed to provide a perfect (distortion free and precisely focused) image at the optical axis: analysis is only used to define the location, size and orientation of this perfect image.
The analysis builds on the fact that the behavior of an optical system can be diagrammed in relation to three pairs of cardinal points: the focal points, the principal points and the nodal points. However, the nodal and principal points exactly coincide for lenses or mirrors surrounded by air — the standard situation in astronomical optics — so only the focal and principal points are needed to describe the system optical behavior.
A few basic properties of the optical system are assumed to apply. All optical components are constructed as solids of rotation, which means their refracting surfaces are symmetrical around an axis. The axes of rotation for all surfaces are identical with a single optical axis when light is passed through the optical system. The intersection of a refracting surface with its optical axis is the vertex of the surface (green dots in the diagram).
Lens surfaces are assumed to be (and in most commercial eyepieces and refractor objectives are) manufactured as sections of a sphere, defined by a radius of curvature originating from a center of curvature located on the optical axis. A two sided lens has two centers of curvature (denoted r1 and r2) and two radii measured along the optical axis from the corresponding vertex. If one side of the lens is a flat (plane) surface, the radius of curvature is zero.
Light rays arise from an object or object space (e.g., area on the celestial sphere) intersected by the optical axis and conventionally diagrammed to the left of the lens. These rays pass through the lens from left to right and terminate in an image plane perpendicular to the optical axis and intersecting the optical axis at a focal point located on the right of the lens. (Note that all real optical images are in fact focused onto a surface that is more or less spherical, with its own radius of curvature; the image plane is the paraxial simplification.) The image receptor (observer's eye, CCD chip, photographic film) is therefore diagrammed at the right of the lens oriented toward the left. The object and image points, and the matching rays connected with them, are termed conjugate.
The focal point can be located by means of collimated rays that are parallel to the optical axis and to each other. If a collimated ray from a point on the object is extended through the lens, and the corresponding oblique image ray is extended back from the conjugate image point, they will intersect in a principal plane perpendicular to the optical axis and intersecting the optical axis at a principal point. All object rays and conjugate refracted image rays will intersect in the same principal plane.
Finally, all refracting optical systems are reversible: they can refract light passing through them from left to right or from right to left. This creates a focal point on each side of the lens. In a thick or compound element (consisting of two or more lenses) there are also two principal points and corresponding principal planes (diagram, above). The first principal plane, first principal point and first focal point are assigned to the surface where light enters the lens; the second principal plane, second principal point and second focal point are assigned to the surface where light exits the lens.
The article continues on to describe the key factors involved in describing the geometry of light rays as they emit from a source, pass through and are refracted by a lens, and finally focused into an image. This is called "first order optical analysis" Once these concepts are understood, they can be applied to solve your problem (at least for basic lenses...more complex lenses require more complex mathematics, accounting for aberrations and diffraction increases the complexity):
Image Size & Location (Positive Lens)
In the Gaussian model, the optical effect of a lens can be analyzed through the use of three analysis rays. The diagram below shows this analysis applied with two principal planes, which is done by disregarding the space between them.
If it is acceptable to assume that the optical effect of the lens thickness (the distance between the front and back incidence points of a light ray) is inconsequential to the slope of the exiting image ray, then the lens can be modeled by a single principal plane located at the center of the lens, in what is called a thin lens model of the optics. This directly yields the effective focal length (measured from the single centered principal plane) as:
1/ƒ' = (nL–1)·(c1–c2).
where c = 1/r. Note that c1 is always numerically negative (by the sign conventions) so the term (c1–c2) is never zero; also reversing the lens (direction of light) produces the same focal length but with opposite sign:
1/ƒ = (nL–1)·(c2–c1) = –(1/ƒ')
which becomes 1/ƒ' (positive), again by the sign conventions.