Talk:Find the intersection of two lines: Difference between revisions
Content added Content deleted
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: | Line 1: | ||
==a REXX version of a REXX version== |
==a REXX version of a REXX version== |
||
This REXX version is a re-write of version 2 of the REXX entry, with: |
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 |
::* 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) |
::* aligned indentation for all '''do-end''' blocks (and encapsulated statements) |
||
::* elided superfluous |
::* elided distracting superfluous zeros in integers |
||
::* |
::* elided superfluous decimal points in integers |
||
::* elides the superfluous and distracting use of concatenation ('''││''') |
|||
::* a unique symbol instead of a null literal for a special case |
::* a unique symbol instead of a null literal for a special case |
||
::* aligns the data points and results in the output |
::* aligns the data points and results in the output |
||
::* adds whitespace to make arithmetic computations more perusable |
::* adds whitespace to make arithmetic computations more perusable |
||
::* eschews title-case |
::* eschews title-case capitalizations |
||
::* maintains the same line for the '''then''' clause and the '''if''' clause (no split statements) |
::* maintains the same line for the '''then''' clause and the '''if''' clause (no split statements) |
||
::* uses indentations for all REXX statements in the function |
::* uses indentations for all REXX statements in the function |
||
Line 15: | Line 16: | ||
::* REXX variables to hold long literals that would otherwise cause excessive wide REXX statements |
::* 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. |
::* 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 |
::* elides superfluous '''do-end''' block structures; less clutter, easier to read |
||
::* |
::* added more whitespace within some REXX statements and the REXX program's output |
||
::* tests all data possibilities (for showing all the tested non-intersecting conditions) |
::* 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)}} |
{{trans|REXX (version 2)}} |
||
<lang rexx>/*REXX program finds (possibly) the intersection of two lines (with diagnostic errors).*/ |
<lang rexx>/*REXX program finds (possibly) the intersection of two lines (with diagnostic errors).*/ |
||
Line 28: | Line 31: | ||
say iSect( 0 0 3 3 0 1 6 7 ) |
say iSect( 0 0 3 3 0 1 6 7 ) |
||
say iSect( 0 0 3 3 8 8 8 8 ) |
say iSect( 0 0 3 3 8 8 8 8 ) |
||
exit /* ═══a═══ ═══b═══ ═══c═══ |
exit /* ═══a═══ ═══b═══ ═══c═══ ═══c═══ stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
iSect: procedure; |
iSect: procedure; parse arg xa ya xb yb xc yc xd yd /*optain args from invocation. */ |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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*/ |
@ident= 'lines AB and CD are identical' /*literal to help shorten a line*/ |
||
@paral= 'lines AB and CD are parallel' /* " " " " " " */ |
@paral= 'lines AB and CD are parallel' /* " " " " " " */ |
||
/* [↓] no special case so far···*/ |
|||
if |
if $=. then if k1=. then if k2=. then if x1=x2 then $=@ident /*identical. */ |
||
else $=@paral /*parallel. */ |
|||
else do; x=x1 /*use X1 */ |
|||
y=k2 * x + d2 /*Y from CD */ |
|||
end |
end |
||
else if k2=. then do; x=x2 /*X from CD */ |
|||
y=k1 * x + d1 /*Y from AB */ |
|||
end |
|||
else if k1=k2 then if d1=d2 then $= @ident |
|||
⚫ | |||
else do; x=(d2-d1) / (k1-k2) |
|||
y=k1 * x + d1 |
|||
end /* [↑] normal*/ |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
if k1=. then if k2=. then if x1=x2 then $=@ident /*identical. */ |
|||
⚫ | |||
⚫ | |||
x=x1 /*use X1 */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
x=x2 /*X from CD */ |
|||
y=k1 * x + d1 /*Y from AB */ |
|||
⚫ | |||
else if k1=k2 then if d1=d2 then $= @ident |
|||
⚫ | |||
else do /*normal.*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
if $=. then $= 'intersection is at (' || x","y')' /*$ ¬defined?*/ |
if $=. then $= 'intersection is at (' || x","y')' /*$ ¬defined?*/ |
||
@ = left( 'a=('xa","ya')', 12) left( 'b=('xb","yb')', 12), /*whitespace.*/ |
|||
left( 'c=('xc","yc')', 12) left( 'd=('xd","yd')', 12) /* " */ |
|||
return left( |
return left(@, max(51, length(@) ) ) ' ───► ' $ /*return str.*/</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |