Anonymous user
Talk:Find the intersection of two lines: Difference between revisions
Talk:Find the intersection of two lines (view source)
Revision as of 05:39, 20 April 2018
, 6 years ago→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.
m (added a missing verb (uses indentatations ...).) |
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 1:
==a REXX version of a REXX version==
This REXX version is a re-write of version 2 of the REXX entry, with:
::* added the required comment so that this REXX version would execute on VM/CMS and MVS/TSO
::* aligned indentation for all '''do-end''' blocks (and encapsulated statements)
::* elided distracting superfluous
::*
::* elides the superfluous and distracting use of concatenation ('''││''')
::* a unique symbol instead of a null literal for a special case
::* aligns the data points and results in the output
::* adds whitespace to make arithmetic computations more perusable
::* eschews title-case
::* maintains the same line for the '''then''' clause and the '''if''' clause (no split statements)
::* uses indentations for all REXX statements in the function
Line 15 ⟶ 16:
::* REXX variables to hold long literals that would otherwise cause excessive wide REXX statements
::* a comma (instead of a slash) to separate the <big> '''x y''' </big> coördinates of the data points.
::* elides superfluous '''do-end''' block structures; less clutter, easier to read
::*
::* tests all data possibilities (for showing all the tested non-intersecting conditions)
::* for viewing the calculation in its entirity, all program logic was kept within single viewable screen
{{trans|REXX (version 2)}}
<lang rexx>/*REXX program finds (possibly) the intersection of two lines (with diagnostic errors).*/
Line 28 ⟶ 31:
say iSect( 0 0 3 3 0 1 6 7 )
say iSect( 0 0 3 3 8 8 8 8 )
exit /* ═══a═══ ═══b═══ ═══c═══
/*──────────────────────────────────────────────────────────────────────────────────────*/
iSect: procedure;
else do; k2=(yd-yc) / (xd-xc) /*compute the slope of CD */
@ident= 'lines AB and CD are identical' /*literal to help shorten a line*/
@paral= 'lines AB and CD are parallel' /* " " " " " " */
if
end
else $= @paral▼
▲ if yc=yd then $= 'points C and D are identical'
▲ else do /*CD isn't a vertical line. */
▲ k2=(yd-yc) / (xd-xc) /*compute the slope of CD */
▲ d2=yc - k2 * xc /*calc. intersection with Y axis*/
▲ if $=. then do /*no special case so far ··· */
▲ else $=@paral /*parallel. */
▲ else do
▲ y=k2 * x + d2 /*Y from CD */
▲ end
▲ else if k2=. then do /*vertical CD*/
▲ end
▲ else $= @paral
▲ x=(d2-d1) / (k1-k2)
▲ y=k1 * x + d1
▲ end /*normal line*/
if $=. then $= 'intersection is at (' || x","y')' /*$ ¬defined?*/
return left(
{{out|output|text= when using the default inputs:}}
<pre>
|