Initial commit.
This commit is contained in:
commit
31367c8208
406
.Rhistory
Normal file
406
.Rhistory
Normal file
@ -0,0 +1,406 @@
|
||||
renv::status()
|
||||
renv::install()
|
||||
install.packages("tidyverse")
|
||||
install.packages("gt")
|
||||
renv::install()
|
||||
renv::hydrate()
|
||||
install.packages("tidyverse")
|
||||
install.packages(c("tidyverse", "gt", "rmarkdown"))
|
||||
install.packages("tidyverse")
|
||||
install.packages("tidyverse")
|
||||
available.packages()
|
||||
available.packages() |> filter(package == "tidyverse")
|
||||
available.packages() |> glimpse()
|
||||
available.packages() |> view()
|
||||
available.packages() |> View()
|
||||
install.packages("tidyverse")
|
||||
install.packages("tidyverse")
|
||||
#| label: setup
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
coc_fx <- 0.025
|
||||
coc_dx <- 0.020
|
||||
# Source of equations: https://www.nikonians.org/reviews/dof-and-hyperfocal-distance-tables-and-calculator/p/5
|
||||
# Returns the hyperfocal distance in millimeters given a focal length in mm,
|
||||
# an aperture, and a circle of confucion (CoC)
|
||||
hyperfocal_distance <- function(focal_length, aperture, circle_of_confusion) {
|
||||
focal_length^2 / (aperture * circle_of_confusion)
|
||||
}
|
||||
# Returns the near focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
near_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance * distance) / (hyperfocal_distance + distance - focal_length)
|
||||
}
|
||||
# Returns the far focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
far_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance * distance) / (hyperfocal_distance - distance - focal_length)
|
||||
}
|
||||
depth_of_field <- function(focal_length, aperture, distance, circle_of_confusion) {
|
||||
h <- hyperfocal_distance(focal_length, aperture, circle_of_confusion)
|
||||
}
|
||||
#| label: setup
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
coc_fx <- 0.025
|
||||
coc_dx <- 0.020
|
||||
# Source of equations: https://www.nikonians.org/reviews/dof-and-hyperfocal-distance-tables-and-calculator/p/5
|
||||
# Returns the hyperfocal distance in millimeters given a focal length in mm,
|
||||
# an aperture, and a circle of confucion (CoC)
|
||||
hyperfocal_distance <- function(focal_length, aperture, circle_of_confusion) {
|
||||
focal_length^2 / (aperture * circle_of_confusion)
|
||||
}
|
||||
# Returns the near focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
near_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance * distance) / (hyperfocal_distance + distance - focal_length)
|
||||
}
|
||||
# Returns the far focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
far_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance * distance) / (hyperfocal_distance - distance - focal_length)
|
||||
}
|
||||
# Returns the depth of field in millimeters given a focal length of the lens,
|
||||
# an aperture, a distance of the focused object, and a circle of confusion.
|
||||
# All distances in millimeters.
|
||||
depth_of_field <- function(focal_length, aperture, distance, circle_of_confusion) {
|
||||
h <- hyperfocal_distance(focal_length, aperture, circle_of_confusion)
|
||||
ff <- far_focus(focal_length, distance, h)
|
||||
nf <- near_focus(focal_length, distance, h)
|
||||
ff - nf
|
||||
}
|
||||
depth_of_field(150, 2.8, 2000, coc_fx)
|
||||
depth_of_field(150, 2.8, 2000, coc_dx)
|
||||
#| label: setup
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
coc_fx <- 0.025
|
||||
coc_dx <- 0.020
|
||||
apertures <- c(2.0, 2.8, 4, 5.6, 8)
|
||||
distances <- c(2, 4, 6, 8, 10) # meters
|
||||
# Source of equations: https://www.nikonians.org/reviews/dof-and-hyperfocal-distance-tables-and-calculator/p/5
|
||||
# Returns the hyperfocal distance in millimeters given a focal length in mm,
|
||||
# an aperture, and a circle of confucion (CoC)
|
||||
hyperfocal_distance <- function(focal_length, aperture, circle_of_confusion) {
|
||||
focal_length^2 / (aperture * circle_of_confusion)
|
||||
}
|
||||
# Returns the near focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
near_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance * distance) / (hyperfocal_distance + distance - focal_length)
|
||||
}
|
||||
# Returns the far focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
far_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance * distance) / (hyperfocal_distance - distance - focal_length)
|
||||
}
|
||||
# Returns the depth of field in millimeters given a focal length of the lens,
|
||||
# an aperture, a distance of the focused object, and a circle of confusion.
|
||||
# All distances in millimeters.
|
||||
depth_of_field <- function(focal_length, aperture, distance, circle_of_confusion) {
|
||||
h <- hyperfocal_distance(focal_length, aperture, circle_of_confusion)
|
||||
ff <- far_focus(focal_length, distance, h)
|
||||
nf <- near_focus(focal_length, distance, h)
|
||||
ff - nf
|
||||
}
|
||||
#| label: tele_far
|
||||
apertures |>
|
||||
cross_join(distances)
|
||||
#| label: tele_far
|
||||
expand_grid(apertures, distances)
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = depth_of_field(150, aperture, distance, coc_fx))
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = depth_of_field(150, aperture, distance * 1000, coc_fx))
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx)))
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx))) |>
|
||||
pivot_wider(names_from = distance, values_from = dof)
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx))) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt()
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt()
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10), 1) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt()
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt()
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture)
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label("f/")
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "f/")
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F")
|
||||
#| label: tele_far
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 150 mm focal length"
|
||||
)
|
||||
#| label: wide_angle
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(20, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 20 mm focal length"
|
||||
)
|
||||
#| label: setup
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
coc_fx <- 0.025
|
||||
coc_dx <- 0.020
|
||||
apertures <- c(2.0, 2.8, 4, 5.6, 8)
|
||||
distances <- c(2, 4, 6, 8, 10) # meters
|
||||
# Source of equations: https://dofmaster.com/equations.html
|
||||
# Returns the hyperfocal distance in millimeters given a focal length in mm,
|
||||
# an aperture, and a circle of confucion (CoC)
|
||||
hyperfocal_distance <- function(focal_length, aperture, circle_of_confusion) {
|
||||
focal_length^2 / (aperture * circle_of_confusion) + focal_length
|
||||
}
|
||||
# Returns the near focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
near_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance + distance - 2 * focal_length)
|
||||
}
|
||||
# Returns the far focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
far_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance - distance)
|
||||
}
|
||||
# Returns the depth of field in millimeters given a focal length of the lens,
|
||||
# an aperture, a distance of the focused object, and a circle of confusion.
|
||||
# All distances in millimeters.
|
||||
depth_of_field <- function(focal_length, aperture, distance, circle_of_confusion) {
|
||||
h <- hyperfocal_distance(focal_length, aperture, circle_of_confusion)
|
||||
ff <- far_focus(focal_length, distance, h)
|
||||
nf <- near_focus(focal_length, distance, h)
|
||||
ff - nf
|
||||
}
|
||||
#| label: tele_lens
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 150 mm focal length"
|
||||
)
|
||||
#| label: wide_angle
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(20, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 20 mm focal length"
|
||||
)
|
||||
#| label: setup
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
coc_fx <- 0.025
|
||||
coc_dx <- 0.020
|
||||
apertures <- c(2.0, 2.8, 4, 5.6, 8)
|
||||
distances <- c(2, 4, 6, 8, 10) # meters
|
||||
# Source of equations: https://dofmaster.com/equations.html
|
||||
# Returns the hyperfocal distance in millimeters given a focal length in mm,
|
||||
# an aperture, and a circle of confucion (CoC)
|
||||
hyperfocal_distance <- function(focal_length, aperture, circle_of_confusion) {
|
||||
focal_length^2 / (aperture * circle_of_confusion) + focal_length
|
||||
}
|
||||
# Returns the near focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
near_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance + distance - 2 * focal_length)
|
||||
}
|
||||
# Returns the far focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
far_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance - distance)
|
||||
}
|
||||
# Returns the depth of field in millimeters given a focal length of the lens,
|
||||
# an aperture, a distance of the focused object, and a circle of confusion.
|
||||
# All distances in millimeters.
|
||||
depth_of_field <- function(focal_length, aperture, distance, circle_of_confusion) {
|
||||
h <- hyperfocal_distance(focal_length, aperture, circle_of_confusion)
|
||||
ff <- far_focus(focal_length, distance, h)
|
||||
nf <- near_focus(focal_length, distance, h)
|
||||
dof <- ff - nf
|
||||
if (dof >= 0) {
|
||||
dof
|
||||
}
|
||||
else {
|
||||
Inf
|
||||
}
|
||||
}
|
||||
#| label: tele_lens
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 150 mm focal length"
|
||||
)
|
||||
#| label: setup
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
coc_fx <- 0.025
|
||||
coc_dx <- 0.020
|
||||
apertures <- c(2.0, 2.8, 4, 5.6, 8)
|
||||
distances <- c(2, 4, 6, 8, 10) # meters
|
||||
# Source of equations: https://dofmaster.com/equations.html
|
||||
# Returns the hyperfocal distance in millimeters given a focal length in mm,
|
||||
# an aperture, and a circle of confucion (CoC)
|
||||
hyperfocal_distance <- function(focal_length, aperture, circle_of_confusion) {
|
||||
focal_length^2 / (aperture * circle_of_confusion) + focal_length
|
||||
}
|
||||
# Returns the near focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
near_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance + distance - 2 * focal_length)
|
||||
}
|
||||
# Returns the far focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
far_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance - distance)
|
||||
}
|
||||
# Returns the depth of field in millimeters given a focal length of the lens,
|
||||
# an aperture, a distance of the focused object, and a circle of confusion.
|
||||
# All distances in millimeters.
|
||||
depth_of_field <- function(focal_length, aperture, distance, circle_of_confusion) {
|
||||
h <- hyperfocal_distance(focal_length, aperture, circle_of_confusion)
|
||||
ff <- far_focus(focal_length, distance, h)
|
||||
nf <- near_focus(focal_length, distance, h)
|
||||
dof <- ff - nf
|
||||
if (dof >= 0) {
|
||||
dof
|
||||
}
|
||||
else {
|
||||
Inf
|
||||
}
|
||||
}
|
||||
#| label: tele_lens
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 150 mm focal length"
|
||||
)
|
||||
#| label: setup
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
coc_fx <- 0.025
|
||||
coc_dx <- 0.020
|
||||
apertures <- c(2.0, 2.8, 4, 5.6, 8)
|
||||
distances <- c(2, 4, 6, 8, 10) # meters
|
||||
# Source of equations: https://dofmaster.com/equations.html
|
||||
# Returns the hyperfocal distance in millimeters given a focal length in mm,
|
||||
# an aperture, and a circle of confucion (CoC)
|
||||
hyperfocal_distance <- function(focal_length, aperture, circle_of_confusion) {
|
||||
focal_length^2 / (aperture * circle_of_confusion) + focal_length
|
||||
}
|
||||
# Returns the near focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
near_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance + distance - 2 * focal_length)
|
||||
}
|
||||
# Returns the far focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
far_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance - distance)
|
||||
}
|
||||
# Returns the depth of field in millimeters given a focal length of the lens,
|
||||
# an aperture, a distance of the focused object, and a circle of confusion.
|
||||
# All distances in millimeters.
|
||||
depth_of_field <- function(focal_length, aperture, distance, circle_of_confusion) {
|
||||
h <- hyperfocal_distance(focal_length, aperture, circle_of_confusion)
|
||||
ff <- far_focus(focal_length, distance, h)
|
||||
nf <- near_focus(focal_length, distance, h)
|
||||
dof <- ff - nf
|
||||
ifelse(dof >= 0, dof, Inf)
|
||||
}
|
||||
#| label: tele_lens
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 150 mm focal length"
|
||||
)
|
||||
#| label: wide_angle
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(20, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 20 mm focal length"
|
||||
)
|
||||
install.packages("shiny")
|
||||
runApp("PhotoCalc")
|
||||
libary(shiny)
|
||||
library(shiny)
|
||||
libary(shiny)
|
||||
runApp("PhotoCalc")
|
||||
runApp('PhotoCalc')
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/.quarto/
|
||||
.Rproj.user
|
28
PhotoCalc/server.R
Normal file
28
PhotoCalc/server.R
Normal file
@ -0,0 +1,28 @@
|
||||
#
|
||||
# This is the server logic of a Shiny web application. You can run the
|
||||
# application by clicking 'Run App' above.
|
||||
#
|
||||
# Find out more about building applications with Shiny here:
|
||||
#
|
||||
# https://shiny.posit.co/
|
||||
#
|
||||
|
||||
library(shiny)
|
||||
|
||||
# Define server logic required to draw a histogram
|
||||
function(input, output, session) {
|
||||
|
||||
output$distPlot <- renderPlot({
|
||||
|
||||
# generate bins based on input$bins from ui.R
|
||||
x <- faithful[, 2]
|
||||
bins <- seq(min(x), max(x), length.out = input$bins + 1)
|
||||
|
||||
# draw the histogram with the specified number of bins
|
||||
hist(x, breaks = bins, col = 'darkgray', border = 'white',
|
||||
xlab = 'Waiting time to next eruption (in mins)',
|
||||
main = 'Histogram of waiting times')
|
||||
|
||||
})
|
||||
|
||||
}
|
33
PhotoCalc/ui.R
Normal file
33
PhotoCalc/ui.R
Normal file
@ -0,0 +1,33 @@
|
||||
#
|
||||
# This is the user-interface definition of a Shiny web application. You can
|
||||
# run the application by clicking 'Run App' above.
|
||||
#
|
||||
# Find out more about building applications with Shiny here:
|
||||
#
|
||||
# https://shiny.posit.co/
|
||||
#
|
||||
|
||||
library(shiny)
|
||||
|
||||
# Define UI for application that draws a histogram
|
||||
fluidPage(
|
||||
|
||||
# Application title
|
||||
titlePanel("Depth of field calculator"),
|
||||
|
||||
# Sidebar with a slider input for number of bins
|
||||
sidebarLayout(
|
||||
sidebarPanel(
|
||||
sliderInput("bins",
|
||||
"Number of bins:",
|
||||
min = 1,
|
||||
max = 50,
|
||||
value = 30)
|
||||
),
|
||||
|
||||
# Show a plot of the generated distribution
|
||||
mainPanel(
|
||||
plotOutput("distPlot")
|
||||
)
|
||||
)
|
||||
)
|
5
_quarto.yml
Normal file
5
_quarto.yml
Normal file
@ -0,0 +1,5 @@
|
||||
project:
|
||||
title: "photography"
|
||||
|
||||
|
||||
|
17
photography.Rproj
Normal file
17
photography.Rproj
Normal file
@ -0,0 +1,17 @@
|
||||
Version: 1.0
|
||||
ProjectId: 181c092c-f7de-48c6-b806-d3c715349e3e
|
||||
|
||||
RestoreWorkspace: Default
|
||||
SaveWorkspace: Default
|
||||
AlwaysSaveHistory: Default
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 2
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: Sweave
|
||||
LaTeX: pdfLaTeX
|
||||
|
||||
AutoAppendNewline: Yes
|
||||
StripTrailingWhitespace: Yes
|
78
photography.qmd
Normal file
78
photography.qmd
Normal file
@ -0,0 +1,78 @@
|
||||
---
|
||||
title: "Photography calculations"
|
||||
---
|
||||
|
||||
|
||||
```{r}
|
||||
#| label: setup
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
|
||||
coc_fx <- 0.025
|
||||
coc_dx <- 0.020
|
||||
apertures <- c(2.0, 2.8, 4, 5.6, 8)
|
||||
distances <- c(2, 4, 6, 8, 10) # meters
|
||||
|
||||
# Source of equations: https://dofmaster.com/equations.html
|
||||
|
||||
# Returns the hyperfocal distance in millimeters given a focal length in mm,
|
||||
# an aperture, and a circle of confucion (CoC)
|
||||
hyperfocal_distance <- function(focal_length, aperture, circle_of_confusion) {
|
||||
focal_length^2 / (aperture * circle_of_confusion) + focal_length
|
||||
}
|
||||
|
||||
# Returns the near focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
near_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance + distance - 2 * focal_length)
|
||||
}
|
||||
|
||||
# Returns the far focus limit in millimeters given a focal length in mm,
|
||||
# a distance in mm, and a hyperfocal distance in mm
|
||||
far_focus <- function(focal_length, distance, hyperfocal_distance) {
|
||||
(hyperfocal_distance - focal_length) * distance / (hyperfocal_distance - distance)
|
||||
}
|
||||
|
||||
# Returns the depth of field in millimeters given a focal length of the lens,
|
||||
# an aperture, a distance of the focused object, and a circle of confusion.
|
||||
# All distances in millimeters.
|
||||
depth_of_field <- function(focal_length, aperture, distance, circle_of_confusion) {
|
||||
h <- hyperfocal_distance(focal_length, aperture, circle_of_confusion)
|
||||
ff <- far_focus(focal_length, distance, h)
|
||||
nf <- near_focus(focal_length, distance, h)
|
||||
dof <- ff - nf
|
||||
ifelse(dof >= 0, dof, Inf)
|
||||
}
|
||||
```
|
||||
|
||||
# Full frame with tele lens 150 mm
|
||||
|
||||
```{r}
|
||||
#| label: tele_lens
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(150, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 150 mm focal length"
|
||||
)
|
||||
```
|
||||
|
||||
# Full frame with wide-angle lens 20 mm
|
||||
|
||||
```{r}
|
||||
#| label: wide_angle
|
||||
expand_grid(aperture = apertures, distance = distances) |>
|
||||
mutate(dof = round(depth_of_field(20, aperture, distance * 1000, coc_fx) / 10, 1)) |>
|
||||
pivot_wider(names_from = distance, values_from = dof) |>
|
||||
gt() |>
|
||||
tab_spanner("Object distance (m)", columns = -aperture) |>
|
||||
cols_label(aperture = "F") |>
|
||||
tab_header(
|
||||
title = "Depth of field in centimeters",
|
||||
subtitle = "full frame, 20 mm focal length"
|
||||
)
|
||||
```
|
7
renv/.gitignore
vendored
Normal file
7
renv/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
library/
|
||||
local/
|
||||
cellar/
|
||||
lock/
|
||||
python/
|
||||
sandbox/
|
||||
staging/
|
1313
renv/activate.R
Normal file
1313
renv/activate.R
Normal file
File diff suppressed because it is too large
Load Diff
19
renv/settings.json
Normal file
19
renv/settings.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"bioconductor.version": null,
|
||||
"external.libraries": [],
|
||||
"ignored.packages": [],
|
||||
"package.dependency.fields": [
|
||||
"Imports",
|
||||
"Depends",
|
||||
"LinkingTo"
|
||||
],
|
||||
"ppm.enabled": null,
|
||||
"ppm.ignored.urls": [],
|
||||
"r.version": null,
|
||||
"snapshot.type": "implicit",
|
||||
"use.cache": true,
|
||||
"vcs.ignore.cellar": true,
|
||||
"vcs.ignore.library": true,
|
||||
"vcs.ignore.local": true,
|
||||
"vcs.manage.ignores": true
|
||||
}
|
Loading…
Reference in New Issue
Block a user