Created
June 17, 2015 20:14
-
-
Save jcaiqueoliveira/443fec481a1a08db7f30 to your computer and use it in GitHub Desktop.
This file contains 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
delimiter // | |
CREATE FUNCTION distancia_rota | |
(p_x1 FLOAT, p_y1 FLOAT, p_x2 FLOAT, p_y2 FLOAT) | |
RETURNS FLOAT | |
DETERMINISTIC | |
BEGIN | |
DECLARE v_dist FLOAT; | |
DECLARE A FLOAT; DECLARE B FLOAT; | |
DECLARE C FLOAT; DECLARE D FLOAT; | |
SET v_dist = 0; | |
SET A = p_x1 / 57.29577951; | |
SET B = p_y1 / 57.29577951; | |
SET C = p_x2 / 57.29577951; | |
SET D = p_y2 / 57.29577951; | |
IF (A = C && B = D) THEN | |
SET v_dist = 0; | |
ELSEIF ((sin(A)*sin(C)+cos(A)*cos(C)*cos(B - D)) > 1) THEN | |
SET v_dist = 3959 * acos(1); | |
ELSE | |
SET v_dist = 3959 *acos(sin(A)*sin(C) + cos(A)*cos(C)*cos(B - D)); | |
END IF; | |
SET v_dist = v_dist * 1.609; | |
RETURN v_dist; | |
END; | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment