Skip to content

Instantly share code, notes, and snippets.

@LightningStalker
Last active August 25, 2017 21:49
Show Gist options
  • Select an option

  • Save LightningStalker/54629cec3b329652c7b7d1d3ef58bc11 to your computer and use it in GitHub Desktop.

Select an option

Save LightningStalker/54629cec3b329652c7b7d1d3ef58bc11 to your computer and use it in GitHub Desktop.
Computes wavelength of incident light
/*
* Computes wavelength of incident light
* Formulas used:
* Arctangent - atan(c / a) - thanks Cyparagon
* Diffraction grating formula - nλ = d sin(ϴ)
* Pythagorean theorem - a² + b² = c²
* The Lightning Stalker 2013
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
float a, c, d, wl;
if (argc == 4)
{
a = atof(argv[1]);
c = atof(argv[2]);
d = atof(argv[3]);
wl = d * sin(atan(c / a));
printf("Wavelength is %1.1fnm\n", wl);
}
else
{
puts("gridcalc is a diffraction grating wavelength calculator.\n");
puts("Usage: gridcalc a c d");
puts("a = Distance from grating to target in mm");
puts("c = Distance from center to first order spectrum line of interest in mm");
puts("d = Distance between diffraction grid elements in nm");
puts("Example: gridcalc 100 88 1000");
puts("Output should be 660.6nm");
return(1);
}
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment