Created with <3 with dartpad.dev.
Last active
October 20, 2022 10:38
-
-
Save lahdekorpi/11bea4a92baada09bd48689d89ce2d4a to your computer and use it in GitHub Desktop.
fov
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "dart:math"; | |
void main() async { | |
print(cropFov(1.2299335238804041, 1920, 240)); | |
print(radianToDegree(cropFov(1.2299335238804041, 1920, 240))); | |
} | |
double cropFov( | |
double fov, // Field of view of the camera | |
int y, // Full height of the image in pixels | |
int crop_y // How many pixels have been cropped from the top of the image (the bottom must match but just enter one value, not the sum of both) | |
) { | |
// all angles in radians | |
var fov_yh = fov / 2; | |
print("fov_y: $fov"); | |
print("fov_yh: $fov_yh"); | |
print("y: $y"); | |
print("crop_y: $crop_y"); | |
final fov_y_crop = atan((tan(fov_yh) * (y / 2 - crop_y)) / (y / 2)) * 2; | |
return fov_y_crop; | |
} | |
double degreeToRadian(double degree) { | |
return degree * pi / 180; | |
} | |
double radianToDegree(double radian) { | |
return radian * 180 / pi; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment