Skip to content

Commit 913f683

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 893daf0 commit 913f683

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

physics/Bragg_angle.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
"""
22
Find the Bragg angle of a crystal given the wavelength of radiation, distane between the planes of crystal and the order of diffraction.
33
4-
In many areas of science, Bragg's law, Wulff–Bragg's condition, or Laue–Bragg interference are a special case of Laue diffraction,
5-
giving the angles for coherent scattering of waves from a large crystal lattice.
6-
It describes how the superposition of wave fronts scattered by lattice planes leads to a strict relation between the wavelength and scattering angle.
7-
This law was initially formulated for X-rays, but it also applies to all types of matter waves including neutron and electron waves if there are a large number of atoms,
8-
as well as visible light with artificial periodic microscale lattices.
9-
4+
In many areas of science, Bragg's law, Wulff–Bragg's condition, or Laue–Bragg interference are a special case of Laue diffraction,
5+
giving the angles for coherent scattering of waves from a large crystal lattice.
6+
It describes how the superposition of wave fronts scattered by lattice planes leads to a strict relation between the wavelength and scattering angle.
7+
This law was initially formulated for X-rays, but it also applies to all types of matter waves including neutron and electron waves if there are a large number of atoms,
8+
as well as visible light with artificial periodic microscale lattices.
9+
1010
Reference: https://en.wikipedia.org/wiki/Bragg%27s_law
1111
1212
"""
1313

14-
15-
1614
import math
1715

16+
1817
def bragg_angle(distance: float, n: int, wavelength: float) -> float:
1918
"""
2019
Calculate the Bragg diffraction angle in degrees.
2120
2221
The Bragg diffraction angle is given by
2322
sin(θ) = (n * λ) / (2 * d)
24-
23+
2524
Parameters:
2625
distance (float): Distance between crystal planes (in meters).
2726
n (int): Order of reflection.
2827
wavelength (float): Wavelength of the radiation (in meters).
29-
28+
3029
Returns:
3130
float: The Bragg diffraction angle θ in degrees.
32-
31+
3332
Example:
3433
>>> bragg_angle(2.2e-10, 1, 2.2e-10)
3534
30.0
@@ -46,19 +45,20 @@ def bragg_angle(distance: float, n: int, wavelength: float) -> float:
4645
...
4746
ValueError: The calculated sine value is out of the valid range.
4847
"""
49-
48+
5049
sine_theta = (n * wavelength) / (2 * distance)
51-
50+
5251
if sine_theta > 1 or sine_theta < -1:
5352
raise ValueError("The calculated sine value is out of the valid range.")
54-
53+
5554
theta_radians = math.asin(sine_theta)
56-
55+
5756
theta_degrees = math.degrees(theta_radians)
58-
57+
5958
return round(theta_degrees, 1)
6059

6160

6261
if __name__ == "__main__":
6362
import doctest
63+
6464
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)