/** * 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; }