summaryrefslogtreecommitdiff
path: root/src/odutils/oif.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/odutils/oif.c')
-rw-r--r--src/odutils/oif.c42
1 files changed, 42 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+
+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;
+}
Back to https://optics-design.com