From 4b3b08ecadf8604062c7f801668e641cb024e309 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 25 Apr 2025 21:17:07 +0200 Subject: First Commit --- src/odutils/oif.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/odutils/oif.c (limited to 'src/odutils/oif.c') diff --git a/src/odutils/oif.c b/src/odutils/oif.c new file mode 100644 index 0000000..b5ef22f --- /dev/null +++ b/src/odutils/oif.c @@ -0,0 +1,42 @@ +/** + * oif.c - source file for just testing basic optics-related functions. + * + * Copyright (C) 2025 https://optics-design.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * See the COPYING file for the full license text. + */ +#include +#include + +int main(int argc, char *argv[]) { + if (argc != 4){ + printf("This program calculates relations between object, image and focal length.\nIt requires you to provide two of these and leave the third one as any char in the form of O I F.\nExample: 90 x 50 will output 112.5"); + return 1; + } + char *po, *pi, *pf; + float o,i,f; + + o = strtof(argv[1], &po); + i = strtof(argv[2], &pi); + f = strtof(argv[3], &pf); + if (*po && !*pi && !*pf) { + o = i*f/(i-f); + } + else if (!*po && *pi && !*pf) { + i = o*f/(o-f); + } + else if (!*po && !*pi && *pf) { + f = o*i/(o+i); + } + else { + printf("Wrong usage of the program! Refer to help"); + return 1; + } + printf("Object Distance: %.5f\nImage Distance: %.5f\nFocal Length: %.5f\n",o,i,f); + return 0; +} -- cgit v1.2.3