Skip to content

Instantly share code, notes, and snippets.

@lahdekorpi
Last active October 20, 2022 10:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lahdekorpi/11bea4a92baada09bd48689d89ce2d4a to your computer and use it in GitHub Desktop.
Save lahdekorpi/11bea4a92baada09bd48689d89ce2d4a to your computer and use it in GitHub Desktop.
fov
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