Advertisement
cardel

20DeEneroDistanciaFDP

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