summaryrefslogtreecommitdiff
path: root/src/odutils/oif.c
blob: b5ef22f13339cf7c32e9a9801cc8bf1d56e10742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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