Determine if two triangles overlap: Difference between revisions
Determine if two triangles overlap (view source)
Revision as of 12:00, 12 January 2017
, 7 years ago→{{header|ooRexx}}: removed the fraction arithmetic (was a false Alarm?)
Walterpachl (talk | contribs) (→{{header|ooRexx}}: fix one bug (found by more testing) |
Walterpachl (talk | contribs) (→{{header|ooRexx}}: removed the fraction arithmetic (was a false Alarm?)) |
||
Line 154:
<lang oorexx>/*--------------------------------------------------------------------
* Determine if two triangles overlap
* Fully (?) tested with integer coordinates of the 6 corners
* This was/is an exercise with ooRexx
* Removed the fraction arithmetic
*-------------------------------------------------------------------*/
Parse Version v
Line 162:
oid='trioo.txt'; 'erase' oid
Call o v
case=0
cc=0
Call trio_test '0 0 4 0 0 4 1 1 2 1 1 2'
Call trio_test '0 0 0 6 8 3 8 0 8 8 0 3'
Call trio_test '0 0 0 2 2 0 0 0 4 0 0 6'
/* The task's specified input */
Call trio_test '0 0 5 0 0 5 0 0 5 0 0 6'
Line 195 ⟶ 199:
Call trio_test '2 0 2 6 1 8 0 1 0 5 8 3'
Call trio_test '0 0 4 0 0 4 1 1 2 1 1 2'
Say case 'cases tested'
Say cc
Exit
trio_test:
Parse Arg tlist
cc+=1
tlist=space(tlist)
tl2=reversex(tlist) ; Call trio_t tl2
tl3=''
tl=tlist
Do While tl<>''
tl3=tl3 y x
tl4=reversex(tl3) ; Call trio_t tl4
tl5=subword(tl4,7) subword(tl4,1,6) ; Call trio_t tl5
tl6=subword(tl5,7) subword(tl5,1,6) ; Call trio_t tl6
trio_t:
Parse Arg tlist
tlist=space(tlist)
Say tlist
case+=1
Parse Arg ax ay bx by cx cy dx dy ex ey fx fy
/*---------------------------------------------------------------------
Line 282 ⟶ 308:
End
Call o '',1
Return
End
Line 292 ⟶ 318:
Call o 'Triangles overlap and touch on' bordl,1
Call o ''
Return
End
Line 385 ⟶ 411:
call o abc 'and' def 'overlap',1
Call o '',1
-- Pull .
End
Return
Line 457 ⟶ 483:
Select
When ka.1='*' Then Do
y2=
y3=
res=between(y2,pp~y,y3)
End
When ka.2='*' Then Do
y2=
res=between(p1~y,y2,p2~y)
End
Otherwise Do
dap=
If ka.3='*' Then
x3=xa.3
Else
x3=
x2=
res=between(x2,pp~x,x3)
End
Line 513 ⟶ 539:
End
Else Do
ka=
da=
xa='*'
End
Line 527 ⟶ 553:
End
Else Do
ey=
res=(ey=p~y)&between(p1~x,p~x,p2~x,'I')
End
Line 554 ⟶ 580:
Else Do
Call o 'kb='kb 'xa='||xa 'db='db
yy=
res=between(q1~y,yy,q2~y)
End
End
When kb='*' Then Do
yy=
res=between(p1~y,yy,p2~y)
End
Line 575 ⟶ 601:
End
Otherwise Do
x=
y=
Call o 'cross:' x y
res=between(p1~x,x,p2~x)
Line 605 ⟶ 631:
Call o a x b 'res='res
Return res
▲::routine divide /* divide two fractions */
Use Arg a,b▼
▲ Parse Var a anom '/' adenom
Return reduce(res)▼
▲::routine add /* add two fractions */
▲ End
▲ Return res
::routine show_g /* show a straight line's forula */
Line 696 ⟶ 672:
::routine draw
Use Arg pixl
Return /* remove to see the triangle corners */
Say 'pixl='pixl
pix.=' '
Line 714 ⟶ 690:
Say ol
End
Return
::routine reversex
n=words(list)
res=word(list,n)
Do i=n-1 to 1 By -1
res=res word(list,i)
End
{{out}}
<pre>Triangle: ABC: (0,0) (5,0) (0,5)
|