Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

61 строка
1.4 KiB

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