Advertisement
Sabrebar

Untitled

Mar 26th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. def pt_in(pt, poly):                                                                                              
  2.     testX, testY = pt                                                                                                    
  3.     last = poly[-1]                                                                                                      
  4.     answer = False                                                                                                      
  5.     for now in poly:                                                                                                    
  6.         nowX, nowY = now                                                                                                
  7.         lastX, lastY = last                                                                                              
  8.         if (nowY > testY) != (lastY > testY) and (testX < (lastX - nowX) * (testY - nowY)/(lastY - nowY) + nowX):        
  9.             answer = not answer                                                                                          
  10.         last = now                                                                                                      
  11.     return answer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement