Anonymous user
Talk:Find the intersection of two lines: Difference between revisions
Talk:Find the intersection of two lines (view source)
Revision as of 23:08, 16 August 2017
, 6 years ago→a REXX version of a REXX version: included comments that were added to REXX version 2, added more comments.
Walterpachl (talk | contribs) m (well, waiting for other opinions) |
m (→a REXX version of a REXX version: included comments that were added to REXX version 2, added more comments.) |
||
Line 19:
{{trans|REXX (version 2)}}
<lang rexx>/*REXX program finds (possibly) the intersection of two lines (with diagnostic errors).*/
say iSect( 4 0 6 10 0 3 10 7 )
say iSect( 0 0 0 10 0 3 10 7 )
say iSect( 0 0 0 10 0 3 10 7 )
say iSect( 0 0 0 1 1 0 1 7 )
say iSect( 0 0 0 0 0 3 10 7 )
say iSect( 0 0 3 3 0 0 6 6 )
say iSect( 0 0 3 3 0 1 6 7 )
say iSect( 0 0 3 3 8 8 8 8 )
exit /* ═══a═══ ═══b═══ ═══c═══ ═══c═══
/*──────────────────────────────────────────────────────────────────────────────────────*/
iSect: procedure; parse arg xa ya xb yb xc yc xd yd
@ident= 'lines AB and CD are identical' /*literal to help shorten a line*/
@paral= 'lines AB and CD are parallel'
$=. /*the
if xa=xb then do /*is AB a vertical line? */
k1=. /*the slope is infinite. */
x1=xa /*the X's intersection is XA */
if ya=yb then $= 'points A and B are identical'
end
else do /*AB isn't a vertical line. */
k1=(yb-ya) / (xb-xa) /*compute the slope of AB */
d1=ya - k1 * xa /*calc. intersection with Y axis*/
end
if xc=xd then do /*is CD a vertical line? */
k2=. /*the slope is infinite. */
x2=xc /*the C's intersection is XC */
if yc=yd then $= 'points C and D are identical'
end
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*/
end
if $=. then do /*no special case so far ··· */
if k1=.
end
end
if $=. then $= 'intersection is at (' || x","y')' /*$ ¬defined?*/
info=left( 'a=('xa","ya')', 12) left( 'b=('xb","yb')
return left(info, max(51, length(info) ) ) ' ───► ' $ /*return str.*/</lang>
{{out|output|text= when using the default
<pre>
a=(4,0) b=(6,10) c=(0,3) d=(10,7)
a=(0,0) b=(0,10) c=(0,3) d=(10,7)
a=(0,0) b=(0,10) c=(0,3) d=(10,7)
a=(0,0) b=(0,1) c=(1,0) d=(1,7)
a=(0,0) b=(0,0) c=(0,3) d=(10,7)
a=(0,0) b=(3,3) c=(0,0) d=(6,6)
a=(0,0) b=(3,3) c=(0,1) d=(6,7)
a=(0,0) b=(3,3) c=(8,8) d=(8,8)
</pre>
==============================================================================================
: If I were to translate many of the Rexx programs of GS to my liking I'd be busy for months.
Line 94 ⟶ 96:
-----
::: There is no reason to take it personally. It wasn't meant as a criticism, it is just another version in a different style, albeit a fair number of (style) differences. <u>Everybody's</u> code can be improved (as least, the style can be changed). In this case, I elided a few superfluous statements, which, in my opinion, didn't add anything to the REXX program or make it easier to understand/peruse. I didn't appreciate your style of capitalization, misaligned DO-END statements (and the intervening/encapsulating REXX statements), split IF-THEN clauses, and much more. But, that's only my opinion and preferences, I merely added a version that I found easier to read and understand (and I hoped others will appreciate this version), and I also removed superfluous DO-END blocks and such. Note that this re-written REXX version was added in the ''
-----
|