Checking the point if internal among three points with python
                                            
                                                
                                                
                                                
                                                
                                                
                                                 10478 단어  Python
                    
import matplotlib.pyplot as plt
import numpy as np
import sys
import random
pa=[random.randint(-10,10),random.randint(-10,10)]
pb=[random.randint(-10,10),random.randint(-10,10)]
pc=[random.randint(-10,10),random.randint(-10,10)]
x=float(sys.argv[1])
y=float(sys.argv[2])
def contains(g, p): 
  n = len(g)
  x = False
  for i in range(n):
    a = np.array(g[i]) - np.array(p)
    b = g[(i+1)%n] - p 
    if (np.linalg.norm(np.cross(a,b)) < np.finfo(np.float).eps \
        and np.dot(a,b) < np.finfo(np.float).eps):
        return 1
    if (a[1] > b[1]):
        b,a = a,b 
    if (a[1] < np.finfo(np.float).eps and np.finfo(np.float).eps < b[1] \
        and np.cross(a,b) > np.finfo(np.float).eps):
        x = not(x)
  if (x):
      return 2
  return 0
print(pa,pb,pc)
print(contains(np.array([pa,pb,pc]),np.array([x,y])))
left = np.array([pa[0],pb[0],pc[0],pa[0]])
height = np.array([pa[1],pb[1],pc[1],pa[1]])
plt.plot(left, height)
plt.plot(x,y,'bo')
plt.show()
 
 Refs. 
https://qiita.com/adad/items/b6842af8778ddff10d77 
http://www.geisya.or.jp/~mwm48961/koukou/area1.htm 
https://note.nkmk.me/python-random-randrange-randint/
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(Checking the point if internal among three points with python), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/adad/items/99b71a507f937985c41e
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Reference
이 문제에 관하여(Checking the point if internal among three points with python), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/adad/items/99b71a507f937985c41e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)