Compare commits
2 Commits
b0bbb1fcdb
...
37c2786336
| Author | SHA1 | Date | |
|---|---|---|---|
| 37c2786336 | |||
| bcffe4e5bf |
@ -21,27 +21,28 @@
|
||||
last
|
||||
(apply area))
|
||||
|
||||
;; wikipedia maths
|
||||
(defn normalize [x] (min 1 (max -1 x)))
|
||||
(defn orientation
|
||||
"returns a value indicating if point A is to the left or right (or on) BC"
|
||||
"returns a value indicating if point A is to the left, right, or on the line BC"
|
||||
[[ax ay] [bx by] [cx cy]]
|
||||
(normalize (- (* (- by ay) (- cx bx))
|
||||
(* (- bx ax) (- cy by)))))
|
||||
|
||||
(defn intersect? [[ax ay] [bx by]]
|
||||
(let [o1 (orientation ax ay bx)
|
||||
o2 (orientation ax ay by)
|
||||
o3 (orientation bx by ax)
|
||||
o4 (orientation bx by ay)]
|
||||
(defn intersect?
|
||||
"Lines AB and CD intersect if points A and B falls on different sides of CD
|
||||
and if C and D fall on different sides of AB"
|
||||
[[a b] [c d]]
|
||||
(let [o1 (orientation a b c)
|
||||
o2 (orientation a b d)
|
||||
o3 (orientation c d a)
|
||||
o4 (orientation c d b)]
|
||||
(and (not= o1 o2) (not= o3 o4))))
|
||||
|
||||
;; part 2
|
||||
(def line-segments (map vector input (conj (vec (rest input)) (first input))))
|
||||
(->> furthest-points
|
||||
(filter (fn [[a b]]
|
||||
(let [segments (filter (fn [[seg-a seg-b]]
|
||||
(and (not= a seg-a)
|
||||
(let [segments (filter (fn [[seg-a seg-b]] (and (not= a seg-a)
|
||||
(not= a seg-b)
|
||||
(not= b seg-a)
|
||||
(not= b seg-b)))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user