chbergmann / OpticsWorkbench

GNU Lesser General Public License v3.0
80 stars 22 forks source link

Refracted rays are calculated incorrectly #19

Closed JRaacke closed 2 years ago

JRaacke commented 2 years ago

At a lens surface, the refracted ray does not follow snell's law. When constructed manually using snell's law constraint, the ray has a different direction. Please verify, if it's only a missing ^2 in ray.py:

def snellsLaw(self, ray, n1, n2, normal):

print('snell ' + str(n1) + '/' + str(n2))

    root = 1 - **(n1/n2)*(n1/n2)** * normal.cross(ray) * normal.cross(ray)
    if root < 0: # total reflection
        return self.mirror(ray, normal)

    return -n1/n2 * normal.cross( (-normal).cross(ray)) - normal * math.sqrt(root)
chbergmann commented 2 years ago

You are right. I fixed it. Thanks for reporting.