Find if a point is within a triangle: Difference between revisions

→‎{{header|Haskell}}: added visual test
(→‎{{header|Haskell}}: added Haskell solution)
(→‎{{header|Haskell}}: added visual test)
Line 913:
(s, (x, y)) = toTriangle t p
in case () of
() | s == 0 && (x == 0 &&|| y == 0) -> Boundary
| s == 0 -> Outside
| x > 0 && y > 0 && y < s - x -> Inside
| (x == 0 || y == 0 || y =<= s -&& x ->= Boundary 0) &&
| otherwise (y <= s && y >= 0) -> Outside</lang>&&
(x == 0 || y == 0 || y == s - x) -> Boundary
| otherwise -> Outside</lang>
 
Testing
Line 932 ⟶ 934:
, overlapping t1 <$> is
, overlapping t1 <$> os
, overlapping t2 <$> ps]</lang>
test2 = unlines
[ [case overlapping t (i,j) of
Inside -> '∗'
Boundary -> '+'
Outside -> '·'
| i <- [-10..10] :: [Int] ]
| j <- [-5..5] :: [Int] ]
where t = Triangle (-8,-3) (8,1) (-1,4)</lang>
 
<pre>λ> tests
Line 938 ⟶ 948:
[Inside,Inside,Inside,Inside,Inside]
[Outside,Outside,Outside,Outside]
[Boundary,Boundary,Outside,Outside]</pre>
 
λ> putStrLn test2
·····················
·····················
··+··················
···+∗∗+··············
····+∗∗∗∗∗+··········
·····+∗∗∗∗∗∗∗∗+······
······+∗∗∗∗∗∗∗∗∗∗∗+··
·······+∗∗∗∗∗∗∗+·····
········+∗∗∗+········
·········+···········
·····················</pre>
 
=={{header|Java}}==
Anonymous user