Home › Qibla › The qibla maths problem
Qibla, episode 9 · Damascus, Syria · 9 min read
The maths problem nobody had managed to tabulate
Lay a ruler on a map, between your city and Mecca. What you have just drawn is not the shortest path. The gap can reach twenty degrees, and the problem occupied mathematicians across the Muslim world for five centuries. The complete solution was computed by hand, inside a mosque, by a man paid to regulate the hours of prayer.
The trap of the straight line
You have to see first why the question is hard, because it does not look it.
On a standard marine chart, Mercator's, a straight line has a very convenient property: it corresponds to a constant heading. Set your compass once, follow it, arrive. That is exactly why such charts were invented, and it is an enormous service to navigation.
But a constant heading is not the shortest path. On a sphere, the shortest route between two points is an arc of a great circle, and a great-circle arc changes heading continuously. It leaves in one direction, turns all the way along, and arrives in another.
The two answers are not alike. And the gap between them grows with distance.
Two cities, two gaps
We ran the numbers, using the great-circle formula on one side and Mercator's rhumb-line formula on the other. Anyone can repeat them.
From Istanbul, Mecca is 2,406 kilometres away. The shortest path leaves on a heading of 151.6 degrees; the straight line drawn on the map leaves on 154.8. Three degrees apart. Over that distance the difference is barely perceptible.
From Xi'an, in China, Mecca is 6,820 kilometres away. The shortest path leaves on 277.5 degrees; the straight line leaves on 258.1. More than nineteen degrees. And the constant-heading route is a hundred kilometres longer.
There is the rule, and it is simple: the further away, the wider the gap. For a community stretching from al-Andalus to China, this was not a surveyor's quibble.

Five centuries of work
The question is posed very early. As soon as the ninth century in Baghdad, al-Khwarizmi offers approximate procedures and tables giving the direction of Mecca as a function of the differences in longitude and latitude. Approximate: the word matters.
The following centuries bring the exact solution. Al-Battani, Ibn Yunus, al-Biruni, Nasir al-Din al-Tusi, Ibn al-Shatir: the list is long, and the thread running through it never changes. To solve the problem of the sacred direction properly, you had to be able to compute on triangles drawn on the surface of a sphere.
That need was one of the great engines behind the development of this branch of mathematics in the Muslim world. This is not a retrospective reconstruction: the treatises themselves pose the qibla as a problem to be solved, and devote whole chapters to it.
But having the exact formula is not enough. It still has to be applied. And applying it, by hand, city by city, for a world running from the Atlantic to China, is work of a different order.
The man at the Umayyad Mosque
The person who took it on did not work in a court observatory. He worked in a mosque.
Damascus, the Umayyad Mosque, around 1365. A man there holds a real and salaried post: regulating the hours of prayer. That means measuring time by the sun, knowing the altitude of the stars, keeping tables. It is a technical trade, practised within the walls of the building itself.
His name is Shams al-Din al-Khalili.

What he computed
Al-Khalili produced a formidable body of tables. The one that concerns us is the qibla table, and its dimensions are these.
2,880 entries. Every latitude from 10 to 56 degrees, every longitude difference from 1 to 60 degrees. That is: the direction of Mecca for any point in the inhabited world of his time, readable directly, with no calculation left to do.
Now the accuracy. The entries have been recomputed with modern means. The verdict, in the words of the reference study: the vast majority of the 2,880 values are accurately computed, or in error by one or two minutes of arc.
A minute of arc is a sixtieth of a degree. To give a sense of what that means: over the fourteen hundred kilometres between Damascus and Mecca, two minutes of arc amount to less than one kilometre at the far end.
With no machine. With no logarithms, which do not yet exist. With trigonometric tables, a method, and as long as it takes.

A note on that image
The miniature above shows Ottoman astronomers of the sixteenth century, not al-Khalili or his workroom. We have no image of him or of where he worked, and none exists. It is here to show the instruments, the postures, the books, what such a trade could look like in practice. Nothing more.
What became of the tables
They did not sleep in a library. They were used.
Al-Khalili's auxiliary tables were in use for centuries in the three great centres of astronomical timekeeping in the Muslim world: Damascus, Cairo and Istanbul. Three cities, three great mosques, and the same technical office held in each.
This deserves emphasis, because it cuts against a common picture. Medieval science is readily imagined as a matter of patrons and princely courts. Here the chain is different: a liturgical need, a salaried post inside a mosque, a body of computation, and diffusion through the network of mosques themselves.

What this article does not claim
We are not saying al-Khalili "invented" the solution to the problem. The exact formula long predates him, as stated above. What he contributes is of another order: universal tabulation, the move from a method a few scholars can apply to a tool any practitioner can consult.
Nor are we saying that a constant-heading chart is "wrong". It gives a perfectly valid route, simply a longer one. The word "error" has no place here, and we never use it of an older method: a difference in direction is measured between two methods, never between a method and the truth.
Finally, the grid illustrating the table in our video is a diagram. It reproduces neither the manuscript's real layout nor the exact number of cells. Only the total and the bounds are taken from the source.

Our sources, in the open
We give the references with links, so that anyone can check them without going through us.
- The "al-Khalīlī" entry in the Biographical Encyclopedia of Astronomers, written by David A. King, hosted by the Institute of Islamic Studies at McGill University: islamsci.mcgill.ca. This is the source of the 2,880 entries, the latitude and longitude bounds, and the accuracy assessment.
- David A. King, "Qibla Charts, Qibla Maps, and Related Instruments", chapter 9 of The History of Cartography, vol. 2 book 1, University of Chicago Press, open access: press.uchicago.edu. On the ninth-century approximate methods and their diffusion.
- Jan P. Hogendijk, historian of mathematics at Utrecht University, "Methods for finding the qibla in the medieval Islamic tradition" and related work: jphogendijk.nl.
- The headings and distances quoted are computed by us, great-circle formula for the shortest path and Mercator's formula for the constant heading. Coordinates of Mecca: 21.4225 N, 39.8262 E.
Read on
The previous episode told the story of the Isfahan discs, which answer the same problem with an object rather than a table. The episode on Ibn al-Haytham tells of a solution credited to someone else for four centuries. And episode 1 sets out the question that opens the series.