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.)
 
(2 intermediate revisions by 2 users not shown)
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.
 
== javascript ==
 
can we have a webpage version of the code?
:I just added an online link for a transpiled version of Phix (am currently doing that sort of thing to lots of pages), not exactly what you asked for I know, but you could use that as a starting point: rip out my p2js.js, make X=0 and Y=1, replace $subse() with plain e[X] etc, kill off all those ugly "sequence", a few "[," ==> "[", and lastly you'll need a replacement for my print(). HTH. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 21:04, 29 December 2021 (UTC) PS Please in future sign your posts using <nowiki>--~~~~</nowiki> (without the nowiki bits).
7,794

edits