No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

65 líneas
1.6 KiB

  1. (define-module math
  2. :imports ("oo.slime")
  3. :exports (pi tau abs sqrt make-vector3)
  4. (define pi
  5. "The famous circle constant."
  6. 3.14159265)
  7. (define tau
  8. "The second famous circle constant."
  9. (* 2 pi))
  10. (define (abs x)
  11. "Accepts one argument and returns the absoulte value of it"
  12. (if (> x 0) x (- x)))
  13. (define (sqrt x)
  14. "Accepts one argument and returns the square root of it"
  15. (** x 0.5))
  16. (define-class (vector3 x y z)
  17. (define (set-x new-x) (mutate! x new-x))
  18. (define (set-y new-y) (mutate! y new-y))
  19. (define (set-z new-z) (mutate! z new-z))
  20. (define (length)
  21. (** (+ (* x x) (* y y) (* z z)) 0.5))
  22. (define (scale fac)
  23. (mutate! x (* fac x))
  24. (mutate! y (* fac y))
  25. (mutate! z (* fac z))
  26. fac)
  27. (define (add other)
  28. (make-vector3
  29. (+ (-> other x) x)
  30. (+ (-> other y) y)
  31. (+ (-> other z) z)))
  32. (define (subtract other)
  33. (make-vector3
  34. (- (-> other x) x)
  35. (- (-> other y) y)
  36. (- (-> other z) z)))
  37. (define (equal? other)
  38. (and (= (-> other x) x)
  39. (= (-> other y) y)
  40. (= (-> other z) z)))
  41. (define (scalar-product other)
  42. (+ (* (-> other x) x)
  43. (* (-> other y) y)
  44. (* (-> other z) z)))
  45. (define (cross-product other)
  46. (make-vector3
  47. (- (* (-> other z) y) (* (-> other y) z))
  48. (- (* (-> other x) z) (* (-> other z) x))
  49. (- (* (-> other y) x) (* (-> other x) y))))
  50. (define (print)
  51. (print :sep "" "[vector3] (" x " " y " " z ")"))))