'percent of the photo at different focal lengths

So I am trying to solve this given problem, it is based on a picture of a tower that is 221 feet tall taken from 7 miles away (36960 feet) with a focal length of 200mm. At this distance, the tower takes up 1/10th (10%) of the height of the photo. I need to write a Matlab program that plots what percent of the photo the tower will take up given that the range for the focal length is between 200mm to 2000mm. I am given the equation that solves for the angle of the view, alpha = d/2f where d is the camera sensor used and f is the focal length. I need to make one graph that plots one line for when d = 24mm and another for when d = 36mm. I have what the graph should look like but I can't seem to get either the equation to work correctly or my values are not in the right places.The y axis is for the percent, x axis is for f ranging from 200 to 2000mm. The blue line represents the 36mm, and the red line represents the 24mm sensor

clear;
close all;
clc;
f = 200:2000; %set focal length
d = 24; %set sensor size
angle = atan(d./(2*f)); %given equation
percent = (angle*36960); %multiply the range and angle 
plot(f,percent)
grid on
xlabel('Focal Length');
xlim([1,2000]); %how far the range is
ylabel('Percent') %label the axes
ylim([0,100])

This is what I was trying to use so I believe it is something to do with my equations I believe there is someway that I need to compare the fact that the tower took up 1/10 of the photo at 200mm but I am not sure how to get that into code and how to plot both at the same time



Solution 1:[1]

You have the classic percent problem. Percent is the ratio of two values. Here you should calculate ration of view and actual height. To plot two plots in one figure

plot(x,y1,x,y2)

To fix your code:

clear;
close;
clc;
distance = 36960;
originalHeight = 221;

f = 200:2000;
d = 24;
angle = atan(d./(2*f));
viewHeight = (angle*distance);
ratio = viewHeight./originalHeight;
percent24 = 100./ratio;

d = 36;
angle = atan(d./(2*f));
viewHeight = (angle*distance);
ratio = viewHeight./originalHeight;
percent36 = 100./ratio;

plot(f,percent36,f,percent24)
grid on
xlabel('Focal Length');
xlim([200,2000]); %how far the range is
ylabel('Percent') %label the axes
ylim([0,100])

Output:

Matlab Plot

One thing bother me most is the mismatch between units. Some of them are in mm and others are in feet. I would convert them all in one.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 im_vutu