Skip to content

Instantly share code, notes, and snippets.

@LightningStalker
Created November 22, 2023 15:52
Show Gist options
  • Select an option

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

Select an option

Save LightningStalker/b2de6fddfef02f3afa6a6cc79521919b to your computer and use it in GitHub Desktop.
/* Compile with gcc -Wall -o pinh pinh.c -lm
The formulator of the pinhole camera
microscopic probgramme by The Lightning Stalker ©April 11, 2022
It's basically in case I can't remember the formula.'*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char **argv)
{
if (argc == 3)
{
printf ("%fmm\n", 2000 * sqrt(atof(argv[2]) * (atof(argv[1]) / 1e9)));
return (0);
}
else if (argc == 4 && strcmp(argv[1], "-l") == 0)
{
printf ("%fm\n", pow(atof(argv[3]) / 2000, 2) / (atof(argv[2]) / 1e9));
return (0);
}
else // usage text
{
puts ("\
Usage: pinh wavelength(nm) focal_length(m)\n\
Pinhole camera aperture calculator.\n\
Output is pinhole diameter in millimeters\n\
\n\
550nm is good rule of thumb for the visible spectrum.\n\
Example: pinh 413.000 0.95\n\
Output should be: 1.252757mm");
return (1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment