Changes

Jump to: navigation, search

Focal length equivalents between formats

4,908 bytes added, 20:07, 4 November 2018
Code
The table above was generated by the program below.
 
package main
import (
"fmt"
"math"
)
type Medium struct {
h, v float64
name string
}
func (m Medium) AspectRatio() float64 {
return m.h/m.v
}
var (
MediumAPSC = Medium{25.1, 16.7, "APS-C"}
MediumFF = Medium{36, 24, "35mm"}
MediumMFF = Medium{43.8, 32.8, "GFX"}
MediumMFH = Medium{53.7, 40.2, "H5D"}
MediumLF45 = Medium{121, 97, "4x5"}
MediumLF617 = Medium{170, 60, "6x17"}
MediumLF810 = Medium{254, 203, "8x10"}
)
var Mediums = []Medium {
MediumAPSC,
MediumFF,
MediumMFF,
MediumLF45,
MediumLF617,
MediumLF810,
}
type Lens struct {
focal float64
tc float64
mfg string
}
func (l Lens) String() string {
var s string
if l.mfg != "" {
s = l.mfg + " "
}
s += fmt.Sprintf("%.0fmm", l.focal)
if l.tc == 1.0 {
return s
}
return s + fmt.Sprintf(" (%.1f)", l.tc)
}
func (l Lens) Focal() float64 {
return l.focal * l.tc
}
var LensesAPSC = []Lens {
{10, 1.0, ""},
{14, 1.0, ""},
{16, 1.0, ""},
{18, 1.0, ""},
{35, 1.0, ""},
{50, 1.0, ""},
{55, 1.0, ""},
{56, 1.0, ""},
{60, 1.0, ""},
{80, 1.0, ""},
{90, 1.0, ""},
{200, 1.0, ""},
}
var LensesFF = []Lens{
{14, 1.0, ""},
{16, 1.0, ""},
{17, 1.0, ""},
{19, 1.0, ""},
{20, 1.0, ""},
{24, 1.0, ""},
{28, 1.0, ""},
{35, 1.0, ""},
{45, 1.0, ""},
{50, 1.0, ""},
{85, 1.0, ""},
{105, 1.0, ""},
{120, 1.0, ""},
{200, 1.0, ""},
}
var LensesGFX = []Lens{
{23, 1.0, ""},
{32, 1.0, ""},
{45, 1.0, ""},
{50, 1.0, ""},
{63, 1.0, ""},
{100, 1.0, ""},
{110, 1.0, ""},
{200, 1.0, ""},
{250, 1.0, ""},
}
var LensesPentax = []Lens {
{25, 1.0, ""},
{28, 1.0, ""},
{33, 1.0, ""},
{45, 1.0, ""},
{55, 1.0, ""},
{80, 1.0, ""},
{85, 1.0, ""},
{110, 1.0, ""},
{150, 1.0, ""},
{160, 1.0, ""},
{300, 1.0, ""},
}
var LensesHasselblad = []Lens {
{24, 1.0, ""},
{28, 1.0, ""},
{35, 1.0, ""},
{50, 1.0, ""},
{80, 1.0, ""},
{90, 1.0, ""},
{110, 1.0, ""},
{150, 1.0, ""},
{210, 1.0, ""},
{300, 1.0, ""},
}
func init() {
for _, v := range LensesHasselblad {
v1 := v
v1.tc = 1.5
LensesHasselblad = append(LensesHasselblad, v1)
}
}
func init() {
for _, v := range LensesHasselblad {
v1 := v
v1.mfg = "Hasselblad"
LensesGFX = append(LensesGFX, v1)
}
}
var LensesLF = []Lens {
{72, 1.0, ""},
{90, 1.0, ""},
{150, 1.0, ""},
{240, 1.0, ""},
{300, 1.0, ""},
}
var LensesLF810 = []Lens {
{150, 1.0, ""},
{240, 1.0, ""},
{300, 1.0, ""},
{450, 1.0, ""},
{600, 1.0, ""},
}
type System struct {
Medium
Lenses *[]Lens
Name string
}
var (
SystemAPSC = System{MediumAPSC, &LensesAPSC, "APS-C"}
SystemFF = System{MediumFF, &LensesFF, "35mm full frame"}
SystemGFX = System{MediumMFF, &LensesGFX, "Fuji GFX"}
SystemPentax = System{MediumMFF, &LensesPentax, "Pentax 645"}
SystemHasselblad = System{MediumMFH, &LensesHasselblad, "Hasselblad H5D-60"}
SystemLF45 = System{MediumLF45, &LensesLF, "LF (4x5)"}
SystemLF617 = System{MediumLF617, &LensesLF, "LF (6x17)"}
SystemLF810 = System{MediumLF810, &LensesLF810, "LF (8x10)"}
)
var Systems = []System {
SystemAPSC,
SystemFF,
SystemGFX,
SystemPentax,
SystemHasselblad,
SystemLF45,
SystemLF617,
SystemLF810,
}
func fov(ssize, focal float64) float64 {
return 2 * math.Atan(ssize/(2*focal)) * 180 / math.Pi
}
type LensAll struct {
Lens
HFoV float64
VFoV float64
Eq map[Medium]float64
}
func (la LensAll) String() string {
var s string
s = fmt.Sprintf("|%v\n|%.1f\n|%.1f", la.Lens, la.HFoV, la.VFoV)
for _, m := range Mediums {
s += fmt.Sprintf("\n|%.0f", la.Eq[m])
}
return s
}
func Equivalent(l Lens, m Medium, mtarg Medium) float64 {
if m.AspectRatio() <= mtarg.AspectRatio() {
return l.Focal() * mtarg.v/m.v
}
return l.Focal() * mtarg.h/m.h
}
type SystemEquiv struct {
System
Lenses []LensAll
}
func (se SystemEquiv) String() string {
s := fmt.Sprintf("=== %s ===\n", se.Name)
s += `{| class="wikitable"` + "\n"
s += "|+"+se.Name + "\n"
s += fmt.Sprintf("|-\n")
s += fmt.Sprintf("|Focal length\n")
s += fmt.Sprintf("|Horizontal FOV\n")
s += fmt.Sprintf("|Vertical FOV\n")
for _, m := range Mediums {
s += fmt.Sprintf("|%s\n", m.name)
}
for _, l := range se.Lenses {
s += fmt.Sprintf("|-\n%s\n", l)
}
s += "|}"
return s
}
func main() {
for _, system := range Systems {
se := SystemEquiv{system, nil}
lenses := []LensAll{}
for _, lens := range *system.Lenses {
la := LensAll{Lens: lens}
la.HFoV = fov(system.Medium.h, lens.Focal())
la.VFoV = fov(system.Medium.v, lens.Focal())
la.Eq = make(map [Medium]float64)
for _, m := range Mediums {
la.Eq[m] = Equivalent(lens, system.Medium, m)
}
lenses = append(lenses, la)
}
se.Lenses = lenses
fmt.Println(se)
}
}

Navigation menu