Exemplo n.º 1
0
def test_parabola_intersection():
    l1 = Line(Point(1, -2), Point(-1, -2))
    l2 = Line(Point(1, 2), Point(-1, 2))
    l3 = Line(Point(1, 0), Point(-1, 0))

    p1 = Point(0, 0)
    p2 = Point(0, -2)
    p3 = Point(120, -12)
    parabola1 = Parabola(p1, l1)

    # parabola with parabola
    assert parabola1.intersection(parabola1) == [parabola1]
    assert parabola1.intersection(Parabola(
        p1, l2)) == [Point2D(-2, 0), Point2D(2, 0)]
    assert parabola1.intersection(Parabola(p2, l3)) == [Point2D(0, -1)]
    assert parabola1.intersection(Parabola(Point(16, 0),
                                           l1)) == [Point2D(8, 15)]
    assert parabola1.intersection(Parabola(Point(
        0, 16), l1)) == [Point2D(-6, 8), Point2D(6, 8)]
    assert parabola1.intersection(Parabola(p3, l3)) == []
    # parabola with point
    assert parabola1.intersection(p1) == []
    assert parabola1.intersection(Point2D(0, -1)) == [Point2D(0, -1)]
    assert parabola1.intersection(Point2D(4, 3)) == [Point2D(4, 3)]
    # parabola with line
    assert parabola1.intersection(Line(Point2D(-7, 3), Point(
        12, 3))) == [Point2D(-4, 3), Point2D(4, 3)]
    assert parabola1.intersection(Line(Point(-4, -1),
                                       Point(4, -1))) == [Point(0, -1)]
    assert parabola1.intersection(Line(Point(2, 0),
                                       Point(0, -2))) == [Point2D(2, 0)]
    raises(
        TypeError,
        lambda: parabola1.intersection(Line(Point(0, 0, 0), Point(1, 1, 1))))
    # parabola with segment
    assert parabola1.intersection(Segment2D(
        (-4, -5), (4, 3))) == [Point2D(0, -1), Point2D(4, 3)]
    assert parabola1.intersection(Segment2D((0, -5),
                                            (0, 6))) == [Point2D(0, -1)]
    assert parabola1.intersection(Segment2D((-12, -65), (14, -68))) == []
    # parabola with ray
    assert parabola1.intersection(Ray2D(
        (-4, -5), (4, 3))) == [Point2D(0, -1), Point2D(4, 3)]
    assert parabola1.intersection(Ray2D(
        (0, 7), (1, 14))) == [Point2D(14 + 2 * sqrt(57), 105 + 14 * sqrt(57))]
    assert parabola1.intersection(Ray2D((0, 7), (0, 14))) == []
    # parabola with ellipse/circle
    assert parabola1.intersection(Circle(
        p1, 2)) == [Point2D(-2, 0), Point2D(2, 0)]
    assert parabola1.intersection(Circle(
        p2, 1)) == [Point2D(0, -1), Point2D(0, -1)]
    assert parabola1.intersection(Ellipse(
        p2, 2, 1)) == [Point2D(0, -1), Point2D(0, -1)]
    assert parabola1.intersection(Ellipse(Point(0, 19), 5, 7)) == []
    assert parabola1.intersection(Ellipse((0, 3), 12, 4)) == \
           [Point2D(0, -1), Point2D(0, -1), Point2D(-4*sqrt(17)/3, Rational(59, 9)), Point2D(4*sqrt(17)/3, Rational(59, 9))]
    # parabola with unsupported type
    raises(TypeError, lambda: parabola1.intersection(2))
Exemplo n.º 2
0
 def draw_3d_ellipse(self, n_cycles):
     a = 1
     b = 2
     x = self.x_range['max']
     z = self.x_range['min']
     ls = np.linspace(0, 2 * np.pi, num=50)
     for n in range(n_cycles):
         for i in ls:
             e1 = Ellipse(SympyPoint(0, 0), a, b)
             p = e1.arbitrary_point()
             #  print('x='+str(cos(i)) + '  y= '+str(2*sin(i)))
             x = cos(i) / 2
             z = 3 * sin(i) / 10
             try:
                 self.service_caller(x=x, y=0.1+n*0.1, z=z, qx=0, qy=0, qz=0, qw=1, \
                     execution_time=0.01, interpolation_type=self.interpolation_type)
             except rospy.ServiceException as exc:
                 pass
     return True
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
Exemplo n.º 5
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
Exemplo n.º 6
0
# we first solve the equations symbolically and then plug in the values when
# needed

# intersection line - circle
x, y, m, c, r = sp.symbols('x y m c r', real=True)
# solving for x
eq_line_circle_x = sp.Eq((m * x + c)**2, (r**2 - x**2))
expr_line_circle_x = sp.solve(eq_line_circle_x, x)
# solving for y
eq_line_circle_y = sp.Eq(((y - c) / m)**2, (r**2 - y**2))
expr_line_circle_y = sp.solve(eq_line_circle_y, y)

# Define the objects as sympy ellipses and circles
# Warning: this can lead to an error with sympy versions < 1.1.
ellip1 = Circle(Point(0., 0.), 0.0525)
ellip2 = Ellipse(Point(0., 0.), 0.0525, 0.065445)
ellip3 = Ellipse(Point(0., 0.), 0.0525, 0.0785)


def get_contact_annotation(source_dir, out_dir, num_jobs=10, debug=True,
                           criteria=['a=0']):
    if not os.path.exists(out_dir):
            os.mkdir(out_dir)

    mats = [f for f in os.listdir(source_dir)
            if os.path.isdir(os.path.join(source_dir, f)) if 'delrin' in f]
    for mat in mats:
        objects = [f for f in os.listdir(os.path.join(source_dir, mat))
                   if 'zip' not in f]
        if not os.path.exists(os.path.join(out_dir, mat)):
            os.mkdir(os.path.join(out_dir, mat))
Exemplo n.º 7
0
import numpy as np

USE_SYMPY_INTERSECTION = True
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])
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
if EXPORT_INTERSECTIONS:
    intersection_points = []
    intersection_t = []

# circle
cx, cy = (550, 1000)
r = 225
# ellipse
ecx, ecy = (1000, 1000)
a = 675  # h_radius
b = 275  # v_radius
# N.B.: When comparing to variables in sketch.py that
# h_radius/v_radius there refer to its outer ellipse

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

# if USE_SYMPY_INTERSECTION:
#     i = e.intersection(c)
#
#     intersection_points = [(float(ii.x), float(ii.y)) for ii in i]
#     intersection_t = [
#         (np.arccos((ip[0] - ecx) / a), np.arcsin((ip[1] - ecy) / b))
#         for ip in intersection_points
#     ]

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

    ax = plt.subplot()