Topic: Photography Methods

Any comments, corrections, refactorings or suggestions would be fantastic, thanks.
Hopefully we might have some photography nuts out there too smile

# camera related
def frame_diagonal(frame_horizontal, frame_vertical)
    @frame_diagonal = Math.sqrt((frame_horizontal**2) + (frame_vertical**2))
end

def focal_length_multiplier(frame_diagonal_1, frame_diagonal_2)
    @focal_length_multiplier = frame_diagonal_1 / frame_diagonal_2
end

def circle_of_confusion(frame_diagonal)
    @circle_of_confusion = frame_diagonal / 1730
end

# lens related
def hyperfocal_distance(focal_length, f_number, circle_of_confusion)
    @hyperfocal_distance = ((focal_length**2) / (f_number * circle_of_confusion)) + focal_length
end

def near_distance(focus_distance, hyperfocal_distance, focal_length)
    @near_distance = (focus_distance * (hyperfocal_distance - focal_length)) / (hyperfocal_distance + focus_distance - 2 * focal_length)
end

def far_distance(focus_distance, hyperfocal_distance, focal_length)
    @far_distance = (focus_distance * (hyperfocal_distance - focal_length)) / (hyperfocal_distance - focus_distance)
end

def total_distance(near_distance, far_distance)
    @total_distance = far_distance - near_distance
end

def magnification(focal_length, focus_distance)
    @magnification = focal_length/(focus_distance - focal_length)
end

def fov_rectilinear_horizontal(frame_horizontal, focal_length, magnification)
    @fov_rectilinear = 2 * Math.arctan(frame_horizontal/(focal_length * 2 * (magnification+1)))
end

def fov_rectilinear_vertical(frame_vertical, focal_length, magnification)
    @fov_rectilinear = 2 * Math.arctan(frame_vertical/(focal_length * 2 * (magnification+1)))
end

def fov_rectilinear_diagonal(frame_diagonal, focal_length, magnification)
    @fov_rectilinear = 2 * Math.arctan(frame_diagonal/(focal_length * 2 * (magnification+1)))
end

def f_number_to_aperture_diameter(focal_length, f_number)
    @aperture_diameter = focal_length / f_number
end

# exposure related
def exposure_value(f_number, shutter_speed)
    @exposure_value = Math.logn(2, (f_number**2 / shutter_speed))
end

# math related
def Math.logn(x, n)
    Math.log(x) / Math.log(n)
end

def Math.arctan(x)
    Math.atan2(x, 1.0)
end

Re: Photography Methods

As I don't know what all is going on, I can't help much.  But there are a couple of repeated equation pieces that could be pulled into methods of their own.

def distance_helper(focus_distance, hyperfocal_distance, focal_length)
  focus_distance * (hyperfocal_distance - focal_length)
end

def fav_rectilinear_helper(specific_frame, focal_length, magnification)
  2 * Math.arctan(specific_frame/(focal_length * 2 * (magnification+1)))
end


Beyond that, there are some items that confuse me.  You have a method named magnification that takes arguments.  Then you have references in other methods to what looks to be a variable named magnification.  Similarly, circle_of_confusion.  Is that a reference to @circle_of_confusion?  Clearly expressive code is cleaner code.