batoulapps / Adhan

High precision prayer time library
MIT License
331 stars 63 forks source link

Qibla direction? #41

Closed mmahalwy closed 7 years ago

mmahalwy commented 7 years ago

Might be interesting to include

z3bi commented 7 years ago

Good idea, should be easy enough to add in.

mmahalwy commented 7 years ago

If you can tell me where I can find the code for it, I can add it to JS

z3bi commented 7 years ago

Most qibla direction websites/apps (even Guidance) use the equation for the azimuth of two points on a sphere. Despite the Earth not being spherical, this is done for simplicity and most people would consider it acceptable as the margin of error is less than a degree.

However there are algorithms for calculating the azimuth of an ellipsoid that can give values of much higher accuracy.

It would be sufficient to provide the spherical equation, but in keeping with the high accuracy intent of this library I think it would be preferable (and more interesting) to do the full ellipsoid calculation.

Ellipsoid algorithms: https://en.wikipedia.org/wiki/Vincenty%27s_formulae http://link.springer.com/article/10.1007%2Fs00190-012-0578-z http://geographiclib.sourceforge.net/

Thoughts?

cc @ahmedre

ahmedre commented 7 years ago

perhaps start with the spherical equation, and, if we can do the ellipsoid later on, we can insha'Allah and people can choose which to use

mmahalwy commented 7 years ago

Sounds good! I'd love to help!

basememara commented 7 years ago

Here's one written in Swift: https://github.com/ethemozcan/QiblaDirection

I use this in a production app and works great, perhaps we can borrow some logic.

z3bi commented 7 years ago

We can go ahead and simply implement the basic azimuth equation. I'll add it in Swift and then if you want to do the JS @mmahalwy that would be great. I had intended to find an academic source for the equation so that it could be appropriately cited and then got distracted. I will look again for a citable reference.

mmahalwy commented 7 years ago

okay, that'd be great!

z3bi commented 7 years ago

@mmahalwy the swift version has been implemented, you can see the equation here #50

mmahalwy commented 7 years ago

@z3bi heads up, I don't have write permission for repo!

basememara commented 7 years ago

Salaam @mmahalwy, correct me if I'm wrong, but you'll have to fork the repo and create a pull request against the master branch.

mmahalwy commented 7 years ago

@basememara yep, that's what I ended up doing: https://github.com/batoulapps/Adhan/pull/51