September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
17
Task/Ray-casting-algorithm/Zkl/ray-casting-algorithm-1.zkl
Normal file
17
Task/Ray-casting-algorithm/Zkl/ray-casting-algorithm-1.zkl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
const E = 0.0001;
|
||||
|
||||
fcn rayHitsSeg([(Px,Py)],[(Ax,Ay)],[(Bx,By)]){ // --> Bool
|
||||
if(Py==Ay or Py==By) Py+=E;
|
||||
if(Py<Ay or Py>By or Px>Ax.max(Bx)) False
|
||||
else if(Px<Ax.min(Bx)) True
|
||||
else try{ ( (Py - Ay)/(Px - Ax) )>=( (By - Ay)/(Bx - Ax) ) } //blue>=red
|
||||
catch(MathError){ Px==Ax } // divide by zero == ∞, only blue?
|
||||
}
|
||||
|
||||
fcn pointInPoly(point, polygon){ // --> Bool, polygon is ( (a,b),(c,d).. )
|
||||
polygon.filter('wrap([(ab,cd)]){ a,b:=ab; c,d:=cd;
|
||||
if(b<=d) rayHitsSeg(point,ab,cd); // left point has smallest y coordinate
|
||||
else rayHitsSeg(point,cd,ab);
|
||||
})
|
||||
.len().isOdd; // True if crossed an odd number of borders ie inside polygon
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue