This article shows how angles to curved lines and arcs tangent to circles can be used to take Refraction into account. It also shows that the difference in the measured Mountain Height using Flat Earth or Globe Earth inclusive Refraction is negligible.
AlBirunis Formula to measure the size of the earth did not take atmospheric refraction into account. [1] I will show that taking refraction into account is possible, but can be neglegted if the dip angle can not be measured very accurately.
Atmospheric Refraction bends light down in an arc and according to flat earthers it is impossible to measure angles to curved lines and having curves (light) tangent to a circle (earth). So according to flat earthers, observing the apparent horizon, i.e. having only a dip angle from horizontal down to an apparent horizon and the observer height, it is impossible to calculate the geometric radius of the earth, not even if we know the amount of Refraction, i.e. how light bends.
I will show that it is possible to calculate the bending of light (Refraction) from atmospheric parameters and take Refraction into account by means of a geometric proof. We can measure angles to curved lines and we can construct tangents to arcs and arcs tangent to circles, which is nessesary to solve the problem with Refraction.
AlBiruni measured the size of the earth using the following method: [2] He went up a mountain of know height and measured the dip angle from horizontal down to the horizon using an Astrolabe. From the observer height and the dip angle using trigonometry he calculated the size of the earth using the following formula he derived:
(1) 
 
where^{'} 

Due to atmospheric refraction the visible horizon is not identical with the horizon that would be visible without refraction. AlBirunis formula (1) does not take refraction into account, so the calculated value will not be equal the geometric radius of the earth. We know today that the calculated radius of the earth will be about 17% too big at standard refraction conditions.
There is a way to modify AlBirunis formula to include refraction measurements to get the real geometric radius of the earth using AlBirunis method:
Here is what AlBirunis formula (1) looks like when we take atmospheric refraction into account. You can find my Derivation of AlBirunis Formula with Refraction farther down. There is also a simpler Approximation of AlBirunis Formula with Refraction.
(8) 
 
see  
where^{'} 

If we have measured atmospheric parameters like the pressure, temperature and temperature gradient, we can use the following formula to calculate the curvature of light. If we don't have this measurements we can use a standard condition value of c = 2.24 × 10^{−8} m^{−1}, which corresponds to a radius of curvature of light of r = 1/c = 44,600 km.
(9) 
 
see 
Calculating Curvature of Light (Deriving Equations for Atmospheric Refraction)  
where^{'} 

Note: this formula is independent of the shape of the earth. There is no R value in this formula, because atmospheric refraction does not need a curved atmosphere, only a vertical density gradient, caused mainly by the vertical temperature gradient. The formula is derived from Fermats principle, that light takes the path with the shortest time through the variing densities of the atmosphere.
The following calculator can be used not only to calculate the Radius of the Earth from measurements using AlBirunis Formula with Refraction above and AlBirunis Mountain Height Formula, but it also calculates the accuracy depending on the entered measurement tolerances.
For the meaning of Exact, Mean and Accuracies see Accuracy Calculations below.
If you don't know the Temperature Gradient dT/dh you can enter a Coefficient of Refraction k, the Light Curve c or the Light Radius r. The corresponding Temperture Gradient is then calculated from that.
By entering the Observer Height h the Pressure P for this height is calculated using the International Standard Atmosphere model, see Air Pressure (Barometric Formula). You can overwrite the Pressure with current measurements anytime later.
You can use the following calculator to calculate the mountain height from measurements as done by AlBiruni. AlBiruni assumed a flat earth with no refraction for his calculation of the mountain height. The calculator calculates the mountain height assuming a Flat Earth and a Globe Earth with radius R = 6371 km. The globe model takes refraction into account, given by the Coefficient of Refraction k. As we can see, the difference of the mountain heights between the 2 models is negligible.
Refraction k: If you have measurements of Pressure, absolute Temperature and Temperature Gradient you can use the AlBiruni Calculator above to calculate the corresponding Refraction Coefficient k. But by playing with Refraction k you will find out, that its effect on the Mountain Height calculation is negligible.
Exact: is the exact result as calculated by the corresponding formula assuming zero tolerances.
Mean: is the mean of all results calculated by variing all parameters independently by their corresponding tolerances.
Accuracy: is the absolute or relative maximal deviation from the mean result due to variing all the parameters.
To get the accuracy of the results from the measurement tolerances, the following procedure is applied:
Each parameter is varied independently by using it with zero tolerance, then with +tolerance and then with tolerance. So if an formula has n = 2 parameters, 3^{n} = 9 values are calculted. The exact value (all tolerances set to 0) and the mean value are stored. From all calculated values the maximum and minimum values are used to calculate the +/ difference to the mean value and displayed at Accuracy Absolute.
Note: The exact value (zero tolerances) is not equal to the mean value, because the functions are not linear. If you make many measurements, then the results will lie within Mean +/Accuracy, but grouped nearer to the Exact value than the Mean value.
Making many measurements can improve the accuracy. The measurements can be expected to have a Gaussian distribution (Fig. 1) around the exact result. The calculated accuracy limits shown in the Calculator can be interpreted as the boundary (±3σ) of the gaussian distribution. In such a distribution 86% of all results can be expected to lie within half of the calculated accuracy limits (±1.5σ).
So when making many measurements it is save in practice to give a result accuracy of 1/2 of the calculated accuracy limits. For example if the calculated relative accuracy is ±10% of the exact result, then we can expect that 86% of all individual results lie within a range of ±5% accuracy.
The formula (8) above is the exact solution. We can also derive a simpler formula that is accurate enough as long as the observer height is much less than the radius of the earth.
(10) 
 
where^{'} 

The following graphic shows the geometric construction from which AlBirunis Formula with Refraction is derived. Download the AlBiruni Refraction.zip GeoGebra file for the graphic.
Known: observer height Obs h, DipAngle (alpha) and radius of curvature of the light ray r.
Unkown: Radius Earth (R), so that the circle Earth Surface (s) is tangent to the curve Light Ray (r) and passes through the point B.
Lets see what we have: The Light Ray (r) is tangential to the Tangent to Apparent Horizon (t) at the point A and tangent to the circle Earth Surface (s) at the point T. The Tangent to Apparent Horizon (t) is at a DipAngle (alpha) down from the observers Horizontal (e). The point T can be calculated using the following geometry, which proves that we can construct a tangent arc to a circle to calculate the radius of the earth using curved light.
The blue circle Earth Surface (s) has to be tangent to both the horizontal through the point B and the arc Light Ray (r) at the point T. So the center of the earth Z lies on the Perpendicular to (e) at the distance R from point B. We don't know R yet.
The arc Light Ray (r) has to be tangent to both the Tangent to the Apparent Horizon (t) at point A and tangent to Earth Surface (s) at the point T. So the center of the light ray arc Q lies on the perpendicular to the Tangent to Apparent Horizon (t), labeled as Radius Light Ray (r) at a distance r from point A. The center of the earth Z lies on the line QT.
We know r from the refraction measurement r = 1/c. The line QT has the length r, because it is the same length as the line AQ. Both are the radius of the light ray r.
Now lets regard the yellow triangle with the sides AQ, QZ, ZA:
The sides are: AQ = r, QZ = (r−R) and ZA = R+h. It can be shown that the angle ZAQ at A is the same as the DipAngle (alpha). So this triangle only contains one unknown, the radius of the earth R.
Using the Law of cosines on the yellow triangle we get:
(17)  
⇒ 
Expanding the squares gives:
(18) 
The red parts cancel and and after bringing all terms containing R to one side we are left with:
(19) 
Factoring out R yields:
(20) 
Isolating R:
(21) 
Dividing nominator and denominator by 2·r gives:
(22) 
r is the radius of curvature of light rays. The curvature of light rays is c = 1/r. So we can replace the r by 1/c and get:
(23) 
 
where^{'} 

Without refraction (c = 0) the formula (23) should simplify to AlBirunis formula. Lets check:
(24) 
This is indeed AlBirunis original formula (1).
If the dip angle α is zero and we have no refraction, the earth would look flat, i.e. R should be infinite, which can be confirmed by replacing cos(α=0) by 1.
AlBiruni measured the height h of a mountain by measuring the elevation angles from two points A (angle α) and B (angle β) where the distance b between A and B was known. He measured the angle at A by using an astrolabe to sight to the peak. He then moved further away to point B and measured the elevation angle at B. By using trigonometry, he was able to calculate the height of the mountain. [3] [4] [5]
(25) 
 
where^{'} 

This fomula assumes a flat earth with no refraction. The calculated value of h is smaller than the correct height when taking earths curvature and refraction into account.
We have 2 equations for the height of the mountain:
(26)  
(27) 
Now we have 2 equations for the 2 unknowns h and x. Lets first calculate x and later use one of the above equations to calculate h. Setting this 2 equations equal we get rid of h and get one equation with the only unknown x:
(28) 
Bringing all terms with x to the left:
(29) 
Solving for x:
(30) 
Inserting (30) into (26) gives:
(31) 
The correct formula to calculate the mountain height h' taking earths curvature and refraction into account is approximately:
(32) 
 
with 
 
and 
 
where^{'} 

Inserting some example parameters it can be shown that without taking earths curvature and refraction into account (AlBirunis method) the height of the mountain turns out to be smaller than if we take earths curvature and refraction into account:
Assuming refraction k = 0.13, α = 45°, β = 30° and b = 1000 m we get a height according to AlBiruni of h = 1366.0 m. According to the formula above we get h' = 1366.7 m. That is only a difference of 0.05%, which is negligible compared to the other uncertainties.
Assuming refraction k = 0.13, α = 30°, β = 15° and b = 2000 m we get a height according to AlBiruni of h = 1000.0 m. According to the formula above we get h' = 1001.7 m. That is a difference of 0.17%.
We use the same steps as in Derivation Flat Earth no Refraction, but we have to add the blue terms to correct for earth curvature and refraction. It is the drop at the distances x and (x+b) repectively. If we use the refracted radius R' = R / (1−k) instead of R we can include refraction in the curvature calculation:
(33)  
(34) 
Note: the blue correction terms are approximations for h much smaller than R.
Setting both equations equal to get rid of
(35) 
The red terms with x^{2} cancel. So we can bring all terms with x to the left side:
(36) 
Solving for x gives:
(37) 
Inserting x into (33) gives the equations at (32).
Using AlBirunis formula (25) for the mountain height we can calculate the error margin of the mountain height. The formula was derived with the approximation for small angles tan(x) ≈ x.
(38) 
 
Note 
angles in radians  
where^{'} 

For our example of α = 45°, β = 30° and b = 1000 m and if we assume a tolerance in the angle measurements of ±0.5° we get a relative error margin of about 7.3% for the height of the mountain (8.3% in the second example with smaller angles). That is 2 orders of magnitudes greater than the difference between taking earths curvature and refraction into account or not. If we can double the precision of the angle measurements, we can half the error margin.
AlBirunis formula (25) is a good approximation of the formula (32) for the height of the mountain. Earths curvature and refraction can be ignored, because the error margin of the angle measurements is much bigger than the error due to not taking into account earths curvature and refraction.
So in the AlBiruni Calculator we can set for Observer Height a tolerance of 5...10% in AlBirunis measurements. Depending on the accuracy of the Dip Angle measurements (5...10%) this gives an estimated AlBiruni accuracy for earths radius of about 16...32% without taking refraction into account (k = 0).
If AlBiruni underestimated the height of the mountain in the 10% error margin, his result of R could be very close to the mean radius R = 6371 km. This is within the error margin of his measurements.
In AlBirunis book The Determination of the Coordinates of Positions for the Correction of Distances Between Cities he writes about the location of the mountain:
You can purchase a copy of the book at AUB Press; American University of Beirut.
According to Wikipedia he measured a dip angle of α = 34 arc min down to the horizon of the plain. So we can calculate about how much higher the mountain sould be to get this dip angle, assuming a standard refraction coefficient of k = 0.13:
(39) 
From this elevation above the plain the horizon appears at a refracted distance of:
(40) 
According to google earth the elevation of the plain at this distance south of the mountain adjecent to the fort Nandana is about 200 m. So the mountain AlBiruni was taking his measurements from sould have an elevation of about 560 m over mean sea level. There is indeed a mountain west of fort Nandana with a height of over 690 m and a view to the south over the plain: Peer Chambal, Pakistan ( 32°42'10.98"N 73° 6'49.15"E).