def check_visibility(a, b, ida, idb, dx, dy, obstructing_trees, network):

    # if distance over horizon then just return because they won't see anyway
    if compute_distance(a, b, 2) > horizon:
        return network
    # creating 2D line passing between the two individuals
    line = Segment(Point(a[0], a[1]), Point(b[0], b[1]))

    # creating filter for individuals boundaries
    x_max = obstructing_trees['centroid_x'] <= max(a[0], b[0])
    x_min = obstructing_trees['centroid_x'] >= min(a[0], b[0])
    y_max = obstructing_trees['centroid_y'] <= max(a[1], b[1])
    y_min = obstructing_trees['centroid_y'] >= min(a[1], b[1])

    # performing orientation analysis
    if a[0] >= b[0] and a[1] >= b[1] and dx >= 0 and dy >= 0 or \
       a[0] <= b[0] and a[1] <= b[1] and dx <= 0 and dy <= 0 or \
       a[0] >= b[0] and a[1] <= b[1] and dx >= 0 and dy <= 0 or \
       a[0] <= b[0] and a[1] >= b[1] and dx <= 0 and dy >= 0:
        check = False
    else:
        check = True
    # if check is still true then perform lines of sight analysis
    if check:
        # scanning all trees with visual obstruction potential in range of the two individuals
        for index, tree in obstructing_trees[x_max & x_min & y_max
                                             & y_min].iterrows():
            # if tree is lower than both individuals than skip it
            if tree['height'] < a[2] and tree['height'] < b[2]:
                continue
            # creating ellipse to approximate the tree shape
            tree_ellipse = Ellipse(
                Point(tree['centroid_x'], tree['centroid_y']),
                tree['delta_x'] / 2, tree['delta_y'] / 2)
            # checking if the ellipse intersects the line among individuals, if yes draw an edge
            if tree_ellipse.intersection(line):
                return network
        network.add_edge(ida, idb)
    return network
def check_visibility(a, b, ida, idb, dx, dy, obstructing_trees, network):

    # if distance over horizon then just return because they won't see anyway
    if compute_distance(a, b, 2) > horizon:
        return network
    # creating 2D line passing between the two individuals
    line = Segment(Point(a[0], a[1]), Point(b[0], b[1]))

    # creating filter for individuals boundaries
    x_max = obstructing_trees['centroid_x'] <= max(a[0], b[0])
    x_min = obstructing_trees['centroid_x'] >= min(a[0], b[0])
    y_max = obstructing_trees['centroid_y'] <= max(a[1], b[1])
    y_min = obstructing_trees['centroid_y'] >= min(a[1], b[1])

    # performing orientation analysis
    if a[0] >= b[0] and a[1] >= b[1] and dx >= 0 and dy >= 0 or \
       a[0] <= b[0] and a[1] <= b[1] and dx <= 0 and dy <= 0 or \
       a[0] >= b[0] and a[1] <= b[1] and dx >= 0 and dy <= 0 or \
       a[0] <= b[0] and a[1] >= b[1] and dx <= 0 and dy >= 0:
        check = False
    else:
        check = True
    # if check is still true then perform lines of sight analysis
    if check:
        # scanning all trees with visual obstruction potential in range of the two individuals
        for index, tree in obstructing_trees[x_max & x_min & y_max & y_min].iterrows():
            # if tree is lower than both individuals than skip it
            if tree['height'] < a[2] and tree['height'] < b[2]:
                continue
            # creating ellipse to approximate the tree shape
            tree_ellipse = Ellipse(Point(tree['centroid_x'], tree['centroid_y']),
                                   tree['delta_x']/2, tree['delta_y']/2)
            # checking if the ellipse intersects the line among individuals, if yes draw an edge
            if tree_ellipse.intersection(line):
                return network
        network.add_edge(ida, idb)
    return network
コード例 #3
0
VISUALISE = True  # Display plot after running
SAVE_PLOT = False  # Will take priority over VISUALISE

# circle
cx, cy = (10, 20)
r = 15
# ellipse
ecx, ecy = (20, 20)
a = 20  # h_radius
b = 10  # v_radius

c = Circle(Point(cx, cy), r)
e = Ellipse(Point(ecx, ecy), a, b)

if USE_SYMPY_INTERSECTION:
    i = e.intersection(c)

c_eq = c.arbitrary_point()
e_eq = e.arbitrary_point()

if VISUALISE or SAVE_PLOT:
    import matplotlib.pyplot as plt
    from math import sin, cos, radians as rad

    fig = plt.figure()
    ax = plt.subplot()
    ax.set_aspect(1.0)
    plt.axis([0, 40, 40, 0])
    ax.set_title("Ellipse intersects a unit circle", size=22)
    ax.set_xlabel("x", size=14)
    ax.set_ylabel("y", size=14)
コード例 #4
0
    def sphere_impact_points(self):
        impact_points = getattr(self, '_impact_points', None)

        print round(self.semi_major_axis, 2)
        if impact_points:
            # TODO should include semi minor too
            """Invalid ellipse on change of semi major axis"""
            if round(self.semi_major_axis, 2) != round(self._impact_sma, 2):
                impact_points = None
                print 'invalid!'

        if impact_points is None:
            print 'create!'
            self._impact_sma = self.semi_major_axis

            r = self.equatorial_radius
            a = self.semi_major_axis
            b = self.semi_minor_axis
            c = math.sqrt(a ** 2 - b ** 2)  # linear eccentricity

            elp = Ellipse(Point(c, 0), a, b)
            crc = Circle(Point(0, 0), r)
            self._impact_points = sorted(list(set([(float(point.x), float(point.y)) for point in elp.intersection(crc)])))
        return self._impact_points
コード例 #5
0
ファイル: make_mouse.py プロジェクト: doakey3/Keyboard-SVGs
def make_mouse():
    fill_color = "#d8d8d8"
    stroke_color = "#939393"
    click_color = "#ed6a6a"
    stroke_width = 2

    svg_height = 50
    precision = 1

    origin_x = (svg_height * 0.333) + (stroke_width / 2)
    origin_x = round(origin_x, precision)

    origin_y = (svg_height / 2) + (stroke_width / 2)
    origin_y = round(origin_y, precision)

    radius_x = round(svg_height * 0.333, precision)
    radius_y = round(svg_height / 2, precision)

    ellipse = Ellipse(center=(origin_x, origin_y),
                      hradius=radius_x,
                      vradius=radius_y)

    h_ratio = 0.333

    p1 = Point(0, svg_height * h_ratio)
    p2 = Point(svg_height, svg_height * h_ratio)
    line = Line(p1, p2)

    h_line_x1 = round(eval(str(ellipse.intersection(line)[0].x)), precision)
    h_line_x2 = round(eval(str(ellipse.intersection(line)[1].x)), precision)
    h_width = round(h_line_x2 - h_line_x1, precision)

    wheel_ratio = 0.165

    wheel_origin_x = origin_x + (stroke_width / 2)
    wheel_origin_y = round(svg_height * wheel_ratio, precision)
    wheel_radius_y = round(svg_height / 10, precision)
    wheel_radius_x = round(svg_height / 20, precision)

    red_width = round(wheel_origin_x - (stroke_width / 2), precision)
    red_height = round(svg_height * h_ratio, precision)

    svg = [
        '<svg width="100px" height="100px" xmlns="http://www.w3.org/2000/svg">',
        '    <g transform="translate(10, 10)">',
        '    <ellipse cx="' + str(origin_x) + '" cy="' + str(origin_y) +
        '" rx="' + str(radius_x) + '" ry="' + str(radius_y) + '" fill="' +
        fill_color + '" stroke="' + stroke_color + '" stroke-width="' +
        str(stroke_width) + '"/>',
        '    <rect x="' + str(h_line_x1) + '" y="' +
        str(round(svg_height * h_ratio, precision)) + '" width="' +
        str(h_width) + '" height="' + str(stroke_width) + '" fill="' +
        stroke_color + '"/>',
        '    <rect x="' + str(origin_x) + '" y="' +
        str(round(stroke_width / 2, precision)) + '" width="' +
        str(stroke_width) + '" height="' +
        str(round(svg_height * h_ratio, precision)) + '" fill="' +
        stroke_color + '"/>',
        '    <clipPath id="clickMB">',
        '        <ellipse cx="' + str(origin_x) + '" cy="' + str(origin_y) +
        '" rx="' + str(radius_x - stroke_width / 2) + '" ry="' +
        str(radius_y - stroke_width / 2) + '" fill="#000000"/>',
        '    </clipPath>',
        #'    <rect width="' + str(red_width) + '" height="' + str(red_height) + '" fill="' + click_color + '" clip-path="url(#clickMB)"/>',
        '    <rect x="' + str(red_width + stroke_width) + '" width="' +
        str(red_width) + '" height="' + str(red_height) + '" fill="' +
        click_color + '" clip-path="url(#clickMB)"/>',
        '    <ellipse cx="' + str(wheel_origin_x) + '" cy="' +
        str(wheel_origin_y) + '" rx="' + str(wheel_radius_x) + '" ry="' +
        str(wheel_radius_y) + '" fill="' + stroke_color + '" stroke="' +
        stroke_color + '" stroke-width="' + str(stroke_width) + '"/>',
        '    </g>',
        '</svg>'
    ]

    return '\n'.join(svg)