/************************************************************** !* Calculate angle of refraction for an incident ray using * !* Snell's Law * !* ---------------------------------------------------------- * !* SAMPLE RUN: * !* * !* Give indices for incident and refracting medium: 1.0 1.5 * !* * !* What is the angle of incidence? 30 * !* * !* Refracted angle = 19.471221 * !* * !* ---------------------------------------------------------- * !* Ref.: "Problem Solving with Fortran 90 By David R. Brooks, * !* Springer-Verlag New York, 1997". * !* * !* C++ Release By J-P Moreau, Paris. * * (www.jpmoreau.fr) * !************************************************************** ! Explanations: ! ------------ \ i! ! incident \ ! ! beam \! ! --------------------------- ! !* ! ! * refracted ! !r * beam ! ! ! Snell's Law: n sin(i) = n sin(r) ! i r ! -1 ! or r = sin [(n / n ) sin(i)] ! i r ! !-------------------------------------------------------------*/ #include #include void main() { double ni, nr; //indices of refraction (dimensionless) double incident,refracted; //angles from perpendicular (deg) double DegToRad; //required for trig functions const double pi = 3.1415926537; DegToRad = pi/180.0; printf("\n Give indices for incident and refracting medium: "); scanf("%lf %lf", &ni, &nr); printf("\n What is the angle of incidence? "); scanf("%lf", &incident); // Convert refracted angle to degrees before displaying its value refracted = asin(ni/nr*sin(incident*DegToRad)); printf("\n Refracted angle = %f\n\n", refracted/DegToRad); } // end of file refract.cpp