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

57 строки
1.3 KiB

  1. (import "oo.slime")
  2. (define-class (vector3 x y z)
  3. (define (set-x new-x) (mutate! x new-x))
  4. (define (set-y new-y) (mutate! y new-y))
  5. (define (set-z new-z) (mutate! z new-z))
  6. (define (length)
  7. (** (+ (* x x) (* y y) (* z z)) 0.5))
  8. (define (scale fac)
  9. (mutate! x (* fac x))
  10. (mutate! y (* fac y))
  11. (mutate! z (* fac z))
  12. fac)
  13. (define (add other)
  14. (make-vector3
  15. (+ (-> other x) x)
  16. (+ (-> other y) y)
  17. (+ (-> other z) z)))
  18. (define (subtract other)
  19. (make-vector3
  20. (- (-> other x) x)
  21. (- (-> other y) y)
  22. (- (-> other z) z)))
  23. (define (equal? other)
  24. (and (= (-> other x) x)
  25. (= (-> other y) y)
  26. (= (-> other z) z)))
  27. (define (scalar-product other)
  28. (+ (* (-> other x) x)
  29. (* (-> other y) y)
  30. (* (-> other z) z)))
  31. (define (cross-product other)
  32. (make-vector3
  33. (- (* (-> other z) y) (* (-> other y) z))
  34. (- (* (-> other x) z) (* (-> other z) x))
  35. (- (* (-> other y) x) (* (-> other x) y))))
  36. (define (print)
  37. (printf :sep " " "[vector3] (" x y z ")"))
  38. )
  39. (define v1 (make-vector3 1 2 3))
  40. (define v2 (make-vector3 3 2 1))
  41. (assert (= (type v1) (type v2) :vector3))
  42. (assert (= (v1 'scalar-product v2) 10))
  43. (assert (-> (-> v1 cross-product v2)
  44. equal?
  45. (make-vector3 -4 8 -4)))