Verilen Polygon Noktalarıyla Çevriliyken seçilen rastgele noktalar alanın içinde mi dışında mı
In [1]:
def triangle_area(point_1,point_2):
x1=point_1[0]
y1=point_1[1]
z1=point_1[2]
x2=point_2[0]
y2=point_2[1]
z2=point_2[2]
t_1=y1*z2-z1*y2
t_2=-(x1*z2-x2*z1)
t_3=x1*y2-x2*y1
return t_1+t_2+t_3
def terzioglu_kampus():
border=[]
border.append([0,0,0])
border.append([100,0,0])
border.append([200,50,0])
border.append([50,100,0])
border.append([0,75,0])
return border
In [2]:
terzioglu_kampus()
Out[2]:
In [3]:
def get_tuples_for_n(n):
return [(i,i+1) for i in range(n)]
In [4]:
get_tuples_for_n(10)
Out[4]:
In [5]:
def get_diff_for_two_point(p0,p1):
return ([p0[0]-p1[0],p0[1]-p1[1],p0[2]-p1[2]])
In [6]:
p0=[2,3,4]
p1=[2,3,0]
get_diff_for_two_point(p0,p1)
Out[6]:
In [7]:
def test_point_in_polygone(point_set,test_point):
status=True
kampus.append(kampus[0])
for edge_two_indis in get_tuples_for_n(len(kampus)-1):
i=edge_two_indis[0]
j=edge_two_indis[1]
p_0=kampus[i]
p_1=kampus[j]
point_p1_p0=get_diff_for_two_point(p_1,p_0)
point_test_p0=get_diff_for_two_point(test_point,p_0)
area=triangle_area(point_p1_p0,point_test_p0)
if(area<0):
status=False
print(i,j,p_0,p_1,point_p1_p0,point_test_p0,area,end="")
print("*******outside******")
else:
print(i,j,p_0,p_1,point_p1_p0,point_test_p0,area)
return status
In [8]:
kampus=terzioglu_kampus()
In [9]:
point=[50,300,0]
In [10]:
test_point_in_polygone(kampus,point)
Out[10]:
In [ ]:
In [ ]:
Yorumlar
Yorum Gönder