Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

61 wiersze
1.5 KiB

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