Talk:Find the intersection of two lines: Difference between revisions

m (→‎a REXX version of a REXX version: added/changed wording in the REXX section header, formatted the REXX program logic to be able to be viewed on a single screen.)
Line 98:
:::: But let's agree that our taste as far as formatting is concerned is vastly different.
:::: And I added commentary to my version. --[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 09:29, 19 May 2017 (UTC)
 
== Clojure version does not handle edge case case of undefined slope (vertical line) ==
 
The part that calculates m (slope) fails if `(- x2 x1)` is zero.
(defn compute-line [pt1 pt2]
(let [[x1 y1] pt1
[x2 y2] pt2
m (/ (- y2 y1) (- x2 x1))]
{:slope m
:offset (- y1 (* m x1))}))
 
 
 
Should the clojure version do something other than throw an exception if the compute-line fn receives a vertical line like [0 0] [0 6], but also all cases like [X Y] [X Z], I would suspect.
 
Currently it just throws on divide by zero, which means you can not find the intersection if the both x-coords points of one line are the same.
Anonymous user