File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/main/java/com/thealgorithms/physics Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .thealgorithms .physics ;
2+
3+ /**
4+ * Calculates refraction angle using Snell's Law:
5+ * n1 * sin(theta1) = n2 * sin(theta2)
6+ */
7+ public class SnellLaw {
8+
9+ /**
10+ * Computes the refracted angle (theta2) in radians.
11+ *
12+ * @param n1 index of refraction of medium 1
13+ * @param n2 index of refraction of medium 2
14+ * @param theta1 incident angle in radians
15+ * @return refracted angle (theta2) in radians
16+ * @throws IllegalArgumentException if total internal reflection occurs
17+ */
18+ public static double refractedAngle (double n1 , double n2 , double theta1 ) {
19+ double ratio = n1 / n2 ;
20+ double sinTheta2 = ratio * Math .sin (theta1 );
21+
22+ if (Math .abs (sinTheta2 ) > 1.0 ) {
23+ throw new IllegalArgumentException ("Total internal reflection: no refraction possible." );
24+ }
25+
26+ return Math .asin (sinTheta2 );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments