Verilen Polygon Noktalarıyla Çevriliyken seçilen rastgele noktalar alanın içinde mi dışında mı

01-labKampus
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]:
[[0, 0, 0], [100, 0, 0], [200, 50, 0], [50, 100, 0], [0, 75, 0]]
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]:
[(0, 1),
 (1, 2),
 (2, 3),
 (3, 4),
 (4, 5),
 (5, 6),
 (6, 7),
 (7, 8),
 (8, 9),
 (9, 10)]
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]:
[0, 0, 4]
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)
0 1 [0, 0, 0] [100, 0, 0] [100, 0, 0] [50, 300, 0] 30000
1 2 [100, 0, 0] [200, 50, 0] [100, 50, 0] [-50, 300, 0] 32500
2 3 [200, 50, 0] [50, 100, 0] [-150, 50, 0] [-150, 250, 0] -30000*******outside******
3 4 [50, 100, 0] [0, 75, 0] [-50, -25, 0] [0, 200, 0] -10000*******outside******
4 5 [0, 75, 0] [0, 0, 0] [0, -75, 0] [50, 225, 0] 3750
Out[10]:
False
In [ ]:
 
In [ ]:
 

Yorumlar

Bu blogdaki popüler yayınlar

Python'da Liste İçin Varyans, Standart Sapma, Ortalama, Minimum bulma, Maksimum bulma

Veritabanı Yönetim Sistemleri

Python'da Görüntü İşleme - Resmi Siyah Beyaz Yapma