<p><a href="https://i.sstatic.net/fQjfe.png" rel="noreferrer">@PaulHK's answer</a> is correct I'm sure, here's a bit of a check to show that the <code>IOR()</code> function is calculating the reflection coefficients for $s$ and $p$ polarizations then averaging the two assuming unpolarized incident light.</p>

<p>The reflection is for a single interface, and at least at normal incidence the results reduce to the simpler $(n_2-n_1)^2/(n_2+n_1)^2$. With this script you can check against other on-line calculators using non-zero incident angle and nonzero values for $k$.</p>

<p>I cleaned up the python a bit (indents) and added the plot. You can see when exiting from glass to air, the reflectivity goes to 100% at the critical angle for total internal reflection:</p>

<p><a href="https://i.sstatic.net/fQjfe.png" rel="noreferrer"><img src="https://i.sstatic.net/fQjfe.png" alt="enter image description here"></a></p>

<p><a href="https://i.sstatic.net/174bS.png" rel="noreferrer"><img src="https://i.sstatic.net/174bS.png" alt="enter image description here"></a></p>

<pre><code>def IOR(n,k):
    theta_deg = 0

    fresnel = []

    while theta_deg &lt;= 90:
        theta = math.radians(theta_deg)

        a = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 +
                                 ((4 * n**2) * k**2)) + (n**2 - k**2 -
                                            (math.sin(theta))**2))/2)

        b = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 +
                                 ((4 * n**2) * k**2)) - (n**2 - k**2 -
                                            (math.sin(theta))**2))/2)

        Fs = (a**2+b**2-(2 * a * math.cos(theta))+
              (math.cos(theta))**2)/(a**2+b**2 +
                            (2 * a * math.cos(theta))+(math.cos(theta))**2)

        Fp = Fs * ((a**2+b**2 -
                    (2 * a * math.sin(theta) * math.tan(theta)) +
                    (math.sin(theta))**2*(math.tan(theta))**2)/(a**2+b**2 +
                    (2 * a * math.sin(theta) * math.tan(theta)) +
                    (math.sin(theta))**2*(math.tan(theta))**2))

        R = (Fs + Fp)/2

        fresnel.append((R, Fs, Fp))

        theta_deg += 1
    return fresnel

import math
import matplotlib.pyplot as plt

n1, n2  = 1.00, 1.45  # into glass, one side only
n2ovrn1 = n2/n1

Rin, Fsin, Fpin = zip(*IOR(n2ovrn1, 0))

print Rin[0]
print (n2ovrn1-1.0)**2 / (n2ovrn1+1.0)**2  # check

n1, n2  = 1.45, 1.00  # outof glass, one side only
n2ovrn1 = n2/n1

Rout, Fsout, Fpout = zip(*IOR(n2ovrn1, 0))

print Rout[0]
print (n2ovrn1-1.0)**2 / (n2ovrn1+1.0)**2  # check

plt.figure()
plt.plot(range(91), Rin, '-k', linewidth=2)
plt.plot(range(91), Rout, '-k', linewidth=2)
plt.plot(range(91), Fsin, '-k')
plt.plot(range(91), Fsout, '-k')
plt.plot(range(91), Fpin, '--k')
plt.plot(range(91), Fpout, '--k')
plt.show()
</code></pre>

CC BY-SA 3.0
2017-06-11T13:43:43.707Z
2017-06-11T13:43:43.707Z
uhoh
<p>This is the complex number version of refraction, were K is the extinction coefficient. This is commonly used for metals.</p>

<p>You can check the Wikipedia on refraction:  <a href="https://en.wikipedia.org/wiki/Refractive_index#Complex_refractive_index" rel="nofollow noreferrer">Complex refractive index | Wikipedia</a></p>

CC BY-SA 3.0
2017-06-01T15:44:30.417Z
I have red that part of the article, but I fail to see the connection between that equation and the one I showed above. Perhaps my math skills arn't good enough to work that out.
Kristoffer Helander
CC BY-SA 3.0
2017-06-01T09:50:21.427Z
2018-03-07T02:57:52.767Z
2018-03-07T02:57:52.767Z
PaulHK
<p>I've seen a Fresnel equation for calculating the reflection amount at <em>incidence angle</em> with <em>n</em> and <em>k</em> values defined. This formula usually comes up in relation to computer graphics, but I can't find this equation anywhere in a science context. </p>

<p>Here is an example written in Python, taken from the website
<a href="http://therenderblog.com/custom-fresnel-curves-in-maya-part-2/" rel="noreferrer">Fresnel Formula in python</a>:</p>

<pre><code>def IOR(n,k):
theta_deg = 0

n = n
k = k
fresnel = []
  
while theta_deg &lt;= 90:
theta = math.radians(theta_deg)

a = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 + ((4 * n**2) * k**2)) + (n**2 - k**2 - (math.sin(theta))**2))/2)

b = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 + ((4 * n**2) * k**2)) - (n**2 - k**2 - (math.sin(theta))**2))/2)
  
Fs = (a**2+b**2-(2 * a * math.cos(theta))+(math.cos(theta))**2)/(a**2+b**2+(2 * a * math.cos(theta))+(math.cos(theta))**2)
Fp = Fs * ((a**2+b**2-(2 * a * math.sin(theta) * math.tan(theta))+(math.sin(theta))**2*(math.tan(theta))**2)/(a**2+b**2+(2 * a * math.sin(theta) * math.tan(theta))+(math.sin(theta))**2*(math.tan(theta))**2))
R = (Fs + Fp)/2
fresnel.append(R)

theta_deg += 1
return fresnel
</code></pre>

<p>I can't find any references online for this formula, the Wikipedia article on <a href="https://en.wikipedia.org/wiki/Fresnel_equations" rel="noreferrer">Fresnel equations</a> contains completely different formulas, and I can't see the connection between them. I've searched high and low, but can't find any reference to this particular formula, why is that? Can you help me find it, or explain to me why I can't find it online? Or could you show me how to derive it from the Fresnel formulas from the Wikipedia article?</p>

<p>Yes, I realize that I already have the formula right there in the code sample. But I'm baffled over why I can't find this formula anywhere, I would like to have more sources to cite then just this code example.</p>

<reflection><fresnel>
Fresnel equation with incident angle, n and k as input
Kristoffer Helander
# Fresnel equation with incident angle, n and k as input

(Asked by: username_0 on 2017-05-30)

I've seen a Fresnel equation for calculating the reflection amount at *incidence angle* with *n* and *k* values defined. This formula usually comes up in relation to computer graphics, but I can't find this equation anywhere in a science context.

Here is an example written in Python, taken from the website
[Fresnel Formula in python](http://therenderblog.com/custom-fresnel-curves-in-maya-part-2/):

```
def IOR(n,k):
theta_deg = 0

n = n
k = k
fresnel = []
  
while theta_deg <= 90:
theta = math.radians(theta_deg)

a = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 + ((4 * n**2) * k**2)) + (n**2 - k**2 - (math.sin(theta))**2))/2)

b = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 + ((4 * n**2) * k**2)) - (n**2 - k**2 - (math.sin(theta))**2))/2)
  
Fs = (a**2+b**2-(2 * a * math.cos(theta))+(math.cos(theta))**2)/(a**2+b**2+(2 * a * math.cos(theta))+(math.cos(theta))**2)
Fp = Fs * ((a**2+b**2-(2 * a * math.sin(theta) * math.tan(theta))+(math.sin(theta))**2*(math.tan(theta))**2)/(a**2+b**2+(2 * a * math.sin(theta) * math.tan(theta))+(math.sin(theta))**2*(math.tan(theta))**2))
R = (Fs + Fp)/2
fresnel.append(R)

theta_deg += 1
return fresnel

```

I can't find any references online for this formula, the Wikipedia article on [Fresnel equations](https://en.wikipedia.org/wiki/Fresnel_equations) contains completely different formulas, and I can't see the connection between them. I've searched high and low, but can't find any reference to this particular formula, why is that? Can you help me find it, or explain to me why I can't find it online? Or could you show me how to derive it from the Fresnel formulas from the Wikipedia article?

Yes, I realize that I already have the formula right there in the code sample. But I'm baffled over why I can't find this formula anywhere, I would like to have more sources to cite then just this code example.

**Tags:** reflection, fresnel


---

## 2 answers

### Answer by username_1 on 2017-06-11. Score: 6 | Accepted answer

[@username_2's answer](https://i.sstatic.net/fQjfe.png) is correct I'm sure, here's a bit of a check to show that the `IOR()` function is calculating the reflection coefficients for $s$ and $p$ polarizations then averaging the two assuming unpolarized incident light.

The reflection is for a single interface, and at least at normal incidence the results reduce to the simpler $(n\_2-n\_1)^2/(n\_2+n\_1)^2$. With this script you can check against other on-line calculators using non-zero incident angle and nonzero values for $k$.

I cleaned up the python a bit (indents) and added the plot. You can see when exiting from glass to air, the reflectivity goes to 100% at the critical angle for total internal reflection:

[![enter image description here](https://i.sstatic.net/fQjfe.png)](https://i.sstatic.net/fQjfe.png)

[![enter image description here](https://i.sstatic.net/174bS.png)](https://i.sstatic.net/174bS.png)

```
def IOR(n,k):
    theta_deg = 0

    fresnel = []

    while theta_deg <= 90:
        theta = math.radians(theta_deg)

        a = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 +
                                 ((4 * n**2) * k**2)) + (n**2 - k**2 -
                                            (math.sin(theta))**2))/2)

        b = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 +
                                 ((4 * n**2) * k**2)) - (n**2 - k**2 -
                                            (math.sin(theta))**2))/2)

        Fs = (a**2+b**2-(2 * a * math.cos(theta))+
              (math.cos(theta))**2)/(a**2+b**2 +
                            (2 * a * math.cos(theta))+(math.cos(theta))**2)

        Fp = Fs * ((a**2+b**2 -
                    (2 * a * math.sin(theta) * math.tan(theta)) +
                    (math.sin(theta))**2*(math.tan(theta))**2)/(a**2+b**2 +
                    (2 * a * math.sin(theta) * math.tan(theta)) +
                    (math.sin(theta))**2*(math.tan(theta))**2))

        R = (Fs + Fp)/2

        fresnel.append((R, Fs, Fp))

        theta_deg += 1
    return fresnel

import math
import matplotlib.pyplot as plt

n1, n2  = 1.00, 1.45  # into glass, one side only
n2ovrn1 = n2/n1

Rin, Fsin, Fpin = zip(*IOR(n2ovrn1, 0))

print Rin[0]
print (n2ovrn1-1.0)**2 / (n2ovrn1+1.0)**2  # check

n1, n2  = 1.45, 1.00  # outof glass, one side only
n2ovrn1 = n2/n1

Rout, Fsout, Fpout = zip(*IOR(n2ovrn1, 0))

print Rout[0]
print (n2ovrn1-1.0)**2 / (n2ovrn1+1.0)**2  # check

plt.figure()
plt.plot(range(91), Rin, '-k', linewidth=2)
plt.plot(range(91), Rout, '-k', linewidth=2)
plt.plot(range(91), Fsin, '-k')
plt.plot(range(91), Fsout, '-k')
plt.plot(range(91), Fpin, '--k')
plt.plot(range(91), Fpout, '--k')
plt.show()

```


---

### Answer by username_2 on 2017-06-01. Score: 4

This is the complex number version of refraction, were K is the extinction coefficient. This is commonly used for metals.

You can check the Wikipedia on refraction: [Complex refractive index | Wikipedia](https://en.wikipedia.org/wiki/Refractive_index#Complex_refractive_index)

> **Comments:**
> **username_0**: I have red that part of the article, but I fail to see the connection between that equation and the one I showed above. Perhaps my math skills arn't good enough to work that out.  

---

