Esempio n. 1
0
def place_turbines():
    q = Polygon([
        Point(424386., 6147543.),
        Point(423974., 6151447.),
        Point(429014., 6151447.),
        Point(429431., 6147543.)
    ])

    r = Polygon(
        [Point(0., 0.),
         Point(0., 100.),
         Point(100., 100.),
         Point(100., 0.)])

    # Test 1: Point inside of polygon
    # p1 = Point(90, 118)
    # print q.contains(p1)

    nvert = 4
    vertx = [424386., 423974, 429014., 429431.]
    verty = [6147543., 6151447., 6151447., 6147543.]

    inside = []
    # plot_data = open("data.dat", "w")
    for i in range(423974, 429431, 80):
        for j in range(6147543, 6151447, 80):
            # a = q.contains(Point(i, j))
            if pnpoly(nvert, vertx, verty, i, j):
                inside.append((i, j))

    # for i in range(19, 151):
    #     for j in range(9, 126):
    #         a = q.contains(Point(i, j))
    #         if a:
    #             inside.append((i, j))

    k = len(inside)
    h = randint(0, k - 1)
    points = [inside[h]]
    # plot_data.write("{0:d}\t{1:d}\t{2:d}\n".format(points[-1][0], points[-1][1], 0))

    for nt in range(1, 80):
        dist = []
        i = 0
        for item in inside:
            min_distance = 999999999999999999
            for point in points:
                distance = abs(item[0] - point[0]) + abs(item[1] - point[1])
                if distance < min_distance:
                    min_distance = distance
            dist.append((min_distance, i))
            i += 1

        next = inside[max(dist)[1]]
        # plot_data.write("{0:d}\t{1:d}\t{2:d}\n".format(next[0], next[1], nt))
        points.append(next)
        inside.remove(next)

    return points
Esempio n. 2
0
    for i in range(nvert):
        if ((verty[i] > testy) != (verty[j] > testy)) and (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]):
            c = not c
        j = i
    return c

# print pnpoly(4, [0., 0., 100., 100.], [0., 100., 100., 0.], 0., 10.)

if __name__ == "__main__":

    nvert = 4
    vertx = [20., 50., 125., 150.]
    verty = [10., 125., 90., 10.]

    q = Polygon([Point(20., 10.),
                 Point(50., 125.),
                 Point(125., 90.),
                 Point(150., 10.)])

    output = open("inside_short.dat", "w")
    start = time()
    for i in range(160):
        for j in range(135):
            output.write("{0:d}\t{1:d}\t{2:d}\t{3:d}\n".format(i, j, pnpoly(nvert, vertx, verty, i, j), q.contains(Point(i, j))))
    output.close()
    print "short"
    print time() - start

    plot_data = open("inside_long.dat", "w")
    start2 = time()
    for i in range(160):
        for j in range(135):
Esempio n. 3
0
def place_turbines():
    q = Polygon([
        Point(424386., 6147543.),
        Point(423974., 6151447.),
        Point(429014., 6151447.),
        Point(429431., 6147543.)
    ])
    # 484178.55, 5732482.8], [500129.9, 5737534.4], [497318.1, 5731880.24], [491858.00, 5725044.75]], [[491858.00, 5725044.75], [497318.1, 5731880.24], [503163.37, 5729155.3], [501266.5, 5715990.05
    r = Polygon([
        Point(484178.55, 5732482.8),
        Point(500129.9, 5737534.4),
        Point(497318.1, 5731880.24),
        Point(503163.37, 5729155.3),
        Point(501266.5, 5715990.05)
    ])

    # Test 1: Point inside of polygon
    # p1 = Point(90, 118)
    # print q.contains(p1)

    nvert = 5
    vertx = [484178.55, 500129.9, 497318.1, 503163.37, 501266.5]
    verty = [5732482.8, 5737534.4, 5731880.24, 5729155.3, 5715990.05]

    inside = []
    plot_data = open("data.dat", "w")
    for i in range(int(floor(min(vertx))), int(ceil(max(vertx))), 10):
        for j in range(int(floor(min(verty))), int(ceil(max(verty))), 10):
            # a = q.contains(Point(i, j))
            if pnpoly(nvert, vertx, verty, i, j):
                inside.append((i, j))

    # for i in range(19, 151):
    #     for j in range(9, 126):
    #         a = q.contains(Point(i, j))
    #         if a:
    #             inside.append((i, j))

    k = len(inside)
    h = randint(0, k - 1)
    points = [inside[h]]
    # plot_data.write("{0:d}\t{1:d}\t{2:d}\n".format(points[-1][0], points[-1][1], 0))

    for nt in range(1, 74):
        dist = []
        i = 0
        for item in inside:
            min_distance = 999999999999999999
            for point in points:
                distance = abs(item[0] - point[0]) + abs(item[1] - point[1])
                if distance < min_distance:
                    min_distance = distance
            dist.append((min_distance, i))
            i += 1

        next = inside[max(dist)[1]]
        plot_data.write("{0}\t{1}\t{2}\n".format(next[0], next[1], nt))
        points.append(next)
        inside.remove(next)

    return points
Esempio n. 4
0
            c = not c
        j = i
    return c


# print pnpoly(4, [0., 0., 100., 100.], [0., 100., 100., 0.], 0., 10.)

if __name__ == "__main__":

    nvert = 4
    vertx = [20., 50., 125., 150.]
    verty = [10., 125., 90., 10.]

    q = Polygon([
        Point(20., 10.),
        Point(50., 125.),
        Point(125., 90.),
        Point(150., 10.)
    ])

    output = open("inside_short.dat", "w")
    start = time()
    for i in range(160):
        for j in range(135):
            output.write("{0:d}\t{1:d}\t{2:d}\t{3:d}\n".format(
                i, j, pnpoly(nvert, vertx, verty, i, j),
                q.contains(Point(i, j))))
    output.close()
    print "short"
    print time() - start

    plot_data = open("inside_long.dat", "w")
Esempio n. 5
0
from random import randint
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
from time import time
from PNPOLY import pnpoly
from math import sqrt

from ray_crossing_polygon_test import Point, Polygon

q = Polygon([
    Point(424386., 6147543.),
    Point(423974., 6151447.),
    Point(429014., 6151447.),
    Point(429431., 6147543.)
])

r = Polygon(
    [Point(0., 0.),
     Point(0., 100.),
     Point(100., 100.),
     Point(100., 0.)])

# Test 1: Point inside of polygon
# p1 = Point(90, 118)
# print q.contains(p1)

nvert = 4
vertx = [424386., 423974, 429014., 429431.]
verty = [6147543., 6151447., 6151447., 6147543.]
Esempio n. 6
0
from random import randint
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches


from math import sqrt

from ray_crossing_polygon_test import Point, Polygon

# q = Polygon([Point(20., 10.),
#              Point(50., 125.),
#              Point(125., 90.),
#              Point(150., 10.)])

r = Polygon([Point(0., 100.),
             Point(0., 0.),
             Point(100., 100.),
             Point(100., 0.)])
Esempio n. 7
0
            testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]
        ):
            c = not c
        j = i
    return c


# print pnpoly(4, [0., 0., 100., 100.], [0., 100., 100., 0.], 0., 10.)

if __name__ == "__main__":

    nvert = 4
    vertx = [20.0, 50.0, 125.0, 150.0]
    verty = [10.0, 125.0, 90.0, 10.0]

    q = Polygon([Point(20.0, 10.0), Point(50.0, 125.0), Point(125.0, 90.0), Point(150.0, 10.0)])

    output = open("inside_short.dat", "w")
    start = time()
    for i in range(160):
        for j in range(135):
            output.write(
                "{0:d}\t{1:d}\t{2:d}\t{3:d}\n".format(i, j, pnpoly(nvert, vertx, verty, i, j), q.contains(Point(i, j)))
            )
    output.close()
    print "short"
    print time() - start

    # plot_data = open("inside_long.dat", "w")
    # start2 = time()
    # for i in range(160):