Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;Autor: Carlos A Delgado
- ;;Fecha: 20 de Enero de 2021
- ;;Contrato: calcular-distancia: posn posn -> numero
- ;;Descripción: Esta función recibe dos puntos en un plano cartesiano y nos retorna la distancia entre ellos
- ;;Ejemplo
- ;;(0,0) (4,4) = raiz(16+16) = raiz(32) = raiz(16.2) = 4raiz(2) = 5.6568
- ;;(3,3) (8,7) = raiz(25+16) = raiz(41) = 6.4031
- (define (calcular-distancia p1 p2)
- (sqrt (+ (sqr (- (posn-x p2) (posn-x p1)))
- (sqr (- (posn-y p2) (posn-y p1))))))
- (check-within (calcular-distancia (make-posn 0 0) (make-posn 4 4)) 5.6568 0.001)
- (check-within (calcular-distancia (make-posn 3 3) (make-posn 8 7)) 6.4031 0.001)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement