Advertisement
UrQuan

LISP04 Vjezbe

Nov 3rd, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.74 KB | None | 0 0
  1. ;Vjezbe 4 - 3.11.
  2.  
  3. (defun duplanje (l)
  4.     (mapcar #'(lambda (x) (list x x)) l)
  5. )
  6.  
  7. ;Posljednji zadatak
  8.  
  9. (defstruct pt
  10.     x
  11.     y
  12. )
  13.  
  14. (defstruct ln
  15.     pt1
  16.     pt2
  17. )
  18.  
  19. (defun udaljenost (p1 p2)
  20.     (sqrt (+ (expt (- (pt-x p1) (pt-x p2)) 2) (expt (- (pt-y p1) (pt-y p2)) 2)))
  21. )
  22.  
  23. (defun srida (l1)
  24.     (make-pt :x (/ (+ (pt-x (ln-pt1 l1)) (pt-x (ln-pt2 l1))) 2) :y (/ (+ (pt-y (ln-pt1 l1)) (pt-y (ln-pt2 l1))) 2))
  25. )
  26.  
  27. (setq points (list (make-pt :x 4 :y 4) (make-pt :x 6 :y 6) (make-pt :x 8 :y 8)))
  28.  
  29. (setq lines (list (make-ln :pt1 (nth 0 points) :pt2 (nth 1 points)) (make-ln :pt1 (nth 1 points) :pt2 (nth 2 points))))
  30.  
  31. (udaljenost (nth 0 points) (nth 1 points))
  32. (udaljenost (nth 0 points) (nth 2 points))
  33.  
  34. (srida (nth 0 lines))
  35. (srida (nth 1 lines))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement