-
-
Save douglastaquary/8ae1013d8cc9a3faaaf6a223f7b993bf to your computer and use it in GitHub Desktop.
diferença de angulos objective-c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define RADIANOS_PARA_GRAUS(radians) ((radians) * (180.0 / M_PI)) | |
| -(float)anguloEntreCoordenadas:(CLLocationCoordinate2D)primeiraCoordenada | |
| toCoordinate:(CLLocationCoordinate2D)segundaCoordenada { | |
| float deltaLongitude = segundaCoordenada.longitude - primeiraCoordenada.longitude; | |
| float deltaLatitude = segundaCoordenada.latitude - primeiraCoordenada.latitude; | |
| // lembrando que M_PI * .5f = pi / 2 | |
| float angulo = (M_PI * .5f) - atan(deltaLatitude / deltaLongitude); | |
| //Aqui comparamos os deltas para descobrir se a inclinaçaão foi para direita ou para esquerda | |
| //Lembrando que nossa Longitude é o eixo Y | |
| //Latitude eixo X | |
| //Se variou em Y, em sentido horário pegamos o angulo calculado | |
| if (deltaLongitude > 0) return RADIANOS_PARA_GRAUS(angulo); | |
| //Se variou em Y, em sentido anti-horaário precisamos pegar o angulo e somar PI para achar a inclinação | |
| else if (deltaLongitude < 0) return RADIANOS_PARA_GRAUS(angulo + M_PI); | |
| //Se não variou em Y, provavelmente ou nosso carrinho rotacionou ou andou em linha reta na horizontal. | |
| else if (deltaLatitude < 0) return RADIANOS_PARA_GRAUS(M_PI); | |
| // Se os pontos forem iguais, naão há diferença. | |
| return 0.0f; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment