Right now, Muslims all over the world are celebrating Ramadan, a month of fasting and prayer. As you probably know, Muslim prayers have a geographic angle not found in other religious traditions. The holiest site in Islam is the Kaaba, a mosque in Mecca, and observant Muslims perform their daily prayers literally facing that spot. But figuring out which way to pray isn’t quite as simple as it seems—especially in the very odd case of Tematangi, a remote atoll in French Polynesia.

View Tematangi in a larger map

In the Qur’an, the direction that Muslims are instructed to face when they pray is called the qibla, which means “direction” in Arabic. The need to calculate the qibla correctly was one factor that led to the development of sophisticated math and geography in the Arab world during the so-called “Islamic Golden Age,” between the 8th and 13th centuries.

On a flat Earth, calculating the qibla would be easy: You would use a “rhumb line,” a line of standard bearing that crossed all meridians of longitude at the same angle. If you were praying in Anchorage, Alaska, for example, you’d face Mecca by facing roughly west-southwest. But here’s the problem: The Earth is round. Most scholars of Islam, from the Middle Ages up to today, have recommended that believers pray using a so-called “great circle” to find the path of least distance to Mecca. By this math, a Muslim in Anchorage would actually face almost due north to pray! (Check a globe if you don’t believe me on this.)

Qibla math gets even trickier when you’re not on Earth. Nine Muslims have been to space, on a series of American and Russian missions, and when a Muslim astronaut is in low Earth orbit, the position of Mecca can shift nearly 180 degrees before he or she can finish a prayer. A 2007 survey of Muslim scientists commissioned by Malaysia’s space agency recommended that spacegoing Muslims do the best they can “based on what is possible.” Sometimes, said the scholars, just facing roughly in the qibla of Earth is all one can do.