当前位置: 首页>>代码示例>>Python>>正文


Python geometry.intersection函数代码示例

本文整理汇总了Python中sympy.geometry.intersection函数的典型用法代码示例。如果您正苦于以下问题:Python intersection函数的具体用法?Python intersection怎么用?Python intersection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了intersection函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_windows

    def get_windows(self, building):
        p_obs = symg.Point(self.x, self.y)

        # collect the segments of the building
        sides = []
        for i in range(0, len(building.nodes)-1):
            node1 = building.nodes[i]
            node2 = building.nodes[i+1]
            p1 = symg.Point(node1.x, node1.y)
            p2 = symg.Point(node2.x, node2.y)
            sides.append(symg.Segment(p1, p2))

        # collect windows that sit on the segments
        for s in sides:
            perp_line = s.perpendicular_line(p_obs)
            p_list = symg.intersection(perp_line, s)
            if p_list:
                p_window = p_list[0]
                phi = get_angle_from_south(p_obs, p_window)
                distance = float(p_obs.distance(p_window))
                w = Window(
                    x=float(p_window.x), 
                    y=float(p_window.y), 
                    phi=phi, 
                    distance=distance)
                self.windows.append(w)

        # find the closest window
        self.closest_window = min(self.windows, key=lambda w: w.distance)
开发者ID:peterkomar-hu,项目名称:SunnyMinutes,代码行数:29,代码来源:observer.py

示例2: auw

def auw(T):
	""" 
	Area under water
	Triangle: T
	Waterlevel assumed to be at 0
	o = Point(-1, -1)
	p = Point(1, -1)
	q = Point(0, 1)
	T = Triangle(o, p, q)
	vuw(T)
	r = Point(-1, 1)
	s = Point(1, 1)
	t = Point(0, 2)
	V = Triangle(r, s, t)
	vuw(V)
	auw(V)
	from wpr import _pp
	figure()
	_pp(T)
	_pp(auw(T), color='g')
	"""
	v = vuw(T)
	if len(v) > 0:
		return Polygon(*(v + intersection(T, Line(Point(-10, 0), Point(10, 0)))))
	return None 
开发者ID:bmnn,项目名称:evrythg,代码行数:25,代码来源:cg.py

示例3: telemetry

def telemetry(T,boxelist):
    a = radians(T.heading())
    P1,P2 = Point(T.xcor(),T.ycor()) , Point(T.xcor()+cos(a),T.ycor()+sin(a))
    P12 = P2 - P1
    intr = [N(P12.dot(p-P1)) for r in boxelist for p in intersection(Line(P1,P2),r) ]
    intr = [d for d in intr if d >= 0]
    #print intr
    return None if intr==[] else (min(intr)+np.random.normal(0,10))
开发者ID:brahimrafik,项目名称:info2robotique,代码行数:8,代码来源:TurtleTelemeter.py

示例4: test_intersection

def test_intersection():
    assert intersection(Point(0, 0)) == []
    raises(TypeError, lambda: intersection(Point(0, 0), 3))
    assert intersection(
            Segment((0, 0), (2, 0)),
            Segment((-1, 0), (1, 0)),
            Line((0, 0), (0, 1)), pairwise=True) == [
        Point(0, 0), Segment((0, 0), (1, 0))]
    assert intersection(
            Line((0, 0), (0, 1)),
            Segment((0, 0), (2, 0)),
            Segment((-1, 0), (1, 0)), pairwise=True) == [
        Point(0, 0), Segment((0, 0), (1, 0))]
    assert intersection(
            Line((0, 0), (0, 1)),
            Segment((0, 0), (2, 0)),
            Segment((-1, 0), (1, 0)),
            Line((0, 0), slope=1), pairwise=True) == [
        Point(0, 0), Segment((0, 0), (1, 0))]
开发者ID:asmeurer,项目名称:sympy,代码行数:19,代码来源:test_util.py

示例5: incircle

def incircle( p,a,b,c):
    p = points[p]
    a = points[a]
    b = points[b]
    c = points[c]
    t = Triangle(a,b,c)

    if hasattr(t, "circumcircle") and t.circumcircle.encloses_point( p ):
        return 1
    if  hasattr(t, "circumcircle") and intersection(t.circumcenter,p): #and t.circumcenter.distance(p) == t.circumradius:
        return 0
    return -1
开发者ID:BinbinTang,项目名称:Geomagicians,代码行数:12,代码来源:test.py

示例6: split

    def split(self, edge, rotate_up):
        """
        :param edge:
        :param rotate_up: 線より上の部分が回転するかどうか
        :return:
        """
        line = sg.Line(edge[0], edge[1])
        points = ConvexHull(self.vertices).vertices
        polygon_points = []
        for i in points:
            polygon_points.append(self.vertices[i])
        polygon = sg.Polygon(*polygon_points)
        new_vertices = sg.intersection(polygon, line)

        up = []
        down = []
        on_line = 0
        for v in self.vertices:
            check = is_up(v, edge)
            if check > 0:
                up.append(v)
            else:
                if check == 0:
                    on_line += 1
                down.append(v)
        if on_line == len(down):
            return None, None
        nv_cnt = 0
        for nv in new_vertices:
            if type(nv) == Segment:
                continue
            up.append(nv)
            down.append(nv)
            nv_cnt += 1
        if nv_cnt != 2:
            return None, None

        if rotate_up:
            up = [get_symmetric_point(p, edge) for p in up]
        else:
            down = [get_symmetric_point(p, edge) for p in down]

        up_polygon = PolygonNode(edge, rotate_up, up, self.node_id)
        down_polygon = PolygonNode(edge, not rotate_up, down, self.node_id)

        # GC
        self.vertices = []

        return up_polygon, down_polygon
开发者ID:kenkoooo,项目名称:icfpc2016,代码行数:49,代码来源:ConvexSolver.py

示例7: check_intersect

    def check_intersect(self, ellipses):
        """
        Check if one ellipse either intersects with another ellipse, or is contained within it.
        Returns true if they intersect or one is within the other.
        Returns false if the ellipses do not touch
        """
        
        ellipse1 = Ellipse.__GenerateSymPyEllipse(self)

        for ellipse in ellipses:
            ellipse2 = Ellipse.__GenerateSymPyEllipse(ellipse)

            if len(intersection(ellipse1, ellipse2)) != 0 or ellipse1.encloses(ellipse2) or ellipse2.encloses(ellipse1): 
                return True

        return False
开发者ID:Solid-Mechanics,项目名称:AbaqusScripts,代码行数:16,代码来源:Shapes.py

示例8: findcross

def findcross(one_line, second_line):
    """Линии состоят из [[x1,y1],[x2,y2]] для поиска пересечений,
    исключая крайние точки. Если пересечения нет, на выходе """
    x1, y1, x2, y2 = one_line[0][0], one_line[0][1], one_line[1][0], one_line[1][1]
    x3, y3, x4, y4 = second_line[0][0], second_line[0][1], second_line[1][0], second_line[1][1]
    p1, p2, p3, p4 = symg.Point(x1, y1), symg.Point(x2, y2), symg.Point(x3, y3), symg.Point(x4, y4)
    l1, l2 = symg.Segment(p1, p2), symg.Segment(p3, p4)
    pointxy = symg.intersection(l1, l2)

    if pointxy:
        pointxy = [pointxy[0].x, pointxy[0].y]
    """ кажется, что if работает быстрее
    try:
        pointxy = [pointxy[0].x, pointxy[0].y]
    except IndexError:
        return pointxy
    """
    return pointxy
开发者ID:aloneal,项目名称:Cross-line-test-myself-,代码行数:18,代码来源:find_cross_line.py

示例9: test_ellipse

def test_ellipse():
    p1 = Point(0, 0)
    p2 = Point(1, 1)
    p3 = Point(x1, x2)
    p4 = Point(0, 1)
    p5 = Point(-1, 0)

    e1 = Ellipse(p1, 1, 1)
    e2 = Ellipse(p2, half, 1)
    e3 = Ellipse(p1, y1, y1)
    c1 = Circle(p1, 1)
    c2 = Circle(p2,1)
    c3 = Circle(Point(sqrt(2),sqrt(2)),1)

    # Test creation with three points
    cen,rad = Point(3*half, 2), 5*half
    assert Circle(Point(0,0), Point(3,0), Point(0,4)) == Circle(cen, rad)
    raises(GeometryError, "Circle(Point(0,0), Point(1,1), Point(2,2))")

    # Basic Stuff
    assert e1 == c1
    assert e1 != e2
    assert p4 in e1
    assert p2 not in e2
    assert e1.area == pi
    assert e2.area == pi/2
    assert e3.area == pi*(y1**2)
    assert c1.area == e1.area
    assert c1.circumference == e1.circumference
    assert e3.circumference == 2*pi*y1

    a = Symbol('a')
    b = Symbol('b')
    e5 = Ellipse(p1, a, b)
    assert e5.circumference == 4*a*C.Integral(((1 - x**2*Abs(b**2 - a**2)/a**2)/(1 - x**2))**(S(1)/2),\
                                            (x, 0, 1))

    assert e2.arbitrary_point() in e2

    # Foci
    f1,f2 = Point(sqrt(12), 0), Point(-sqrt(12), 0)
    ef = Ellipse(Point(0, 0), 4, 2)
    assert ef.foci in [(f1, f2), (f2, f1)]

    # Tangents
    v = sqrt(2) / 2
    p1_1 = Point(v, v)
    p1_2 = p2 + Point(half, 0)
    p1_3 = p2 + Point(0, 1)
    assert e1.tangent_line(p4) == c1.tangent_line(p4)
    assert e2.tangent_line(p1_2) == Line(p1_2, p2 + Point(half, 1))
    assert e2.tangent_line(p1_3) == Line(p1_3, p2 + Point(half, 1))
    assert c1.tangent_line(p1_1) == Line(p1_1, Point(0, sqrt(2)))
    assert e2.is_tangent(Line(p1_2, p2 + Point(half, 1)))
    assert e2.is_tangent(Line(p1_3, p2 + Point(half, 1)))
    assert c1.is_tangent(Line(p1_1, Point(0, sqrt(2))))
    assert e1.is_tangent(Line(Point(0, 0), Point(1, 1))) == False

    # Intersection
    l1 = Line(Point(1, -5), Point(1, 5))
    l2 = Line(Point(-5, -1), Point(5, -1))
    l3 = Line(Point(-1, -1), Point(1, 1))
    l4 = Line(Point(-10, 0), Point(0, 10))
    pts_c1_l3 = [Point(sqrt(2)/2, sqrt(2)/2), Point(-sqrt(2)/2, -sqrt(2)/2)]

    assert intersection(e2, l4) == []
    assert intersection(c1, Point(1, 0)) == [Point(1, 0)]
    assert intersection(c1, l1) == [Point(1, 0)]
    assert intersection(c1, l2) == [Point(0, -1)]
    assert intersection(c1, l3) in [pts_c1_l3, [pts_c1_l3[1], pts_c1_l3[0]]]
    assert intersection(c1, c2) in [[(1,0), (0,1)],[(0,1),(1,0)]]
    assert intersection(c1, c3) == [(sqrt(2)/2, sqrt(2)/2)]

    # some special case intersections
    csmall = Circle(p1, 3)
    cbig = Circle(p1, 5)
    cout = Circle(Point(5, 5), 1)
    # one circle inside of another
    assert csmall.intersection(cbig) == []
    # separate circles
    assert csmall.intersection(cout) == []
    # coincident circles
    assert csmall.intersection(csmall) == csmall

    v = sqrt(2)
    t1 = Triangle(Point(0, v), Point(0, -v), Point(v, 0))
    points = intersection(t1, c1)
    assert len(points) == 4
    assert Point(0, 1) in points
    assert Point(0, -1) in points
    assert Point(v/2, v/2) in points
    assert Point(v/2, -v/2) in points

    e1 = Circle(Point(0, 0), 5)
    e2 = Ellipse(Point(0, 0), 5, 20)
    assert intersection(e1, e2) in \
        [[Point(5, 0), Point(-5, 0)], [Point(-5, 0), Point(5, 0)]]

    # FAILING ELLIPSE INTERSECTION GOES HERE

#.........这里部分代码省略.........
开发者ID:pernici,项目名称:sympy,代码行数:101,代码来源:test_geometry.py

示例10: test_polygon


#.........这里部分代码省略.........
    assert feq(angles[Point(4, 4)].evalf(), Float("1.2490457723982544"))
    assert feq(angles[Point(5, 2)].evalf(), Float("1.8925468811915388"))
    assert feq(angles[Point(3, 0)].evalf(), Float("2.3561944901923449"))

    angles = p3.angles
    assert feq(angles[Point(0, 0)].evalf(), Float("0.7853981633974483"))
    assert feq(angles[Point(4, 4)].evalf(), Float("1.2490457723982544"))
    assert feq(angles[Point(5, 2)].evalf(), Float("1.8925468811915388"))
    assert feq(angles[Point(3, 0)].evalf(), Float("2.3561944901923449"))

    #
    # Triangle
    #
    p1 = Point(0, 0)
    p2 = Point(5, 0)
    p3 = Point(0, 5)
    t1 = Triangle(p1, p2, p3)
    t2 = Triangle(p1, p2, Point(Rational(5,2), sqrt(Rational(75,4))))
    t3 = Triangle(p1, Point(x1, 0), Point(0, x1))
    s1 = t1.sides
    assert Triangle(p1, p2, p1) == Polygon(p1, p2, p1) == Segment(p1, p2)
    raises(GeometryError, 'Triangle(Point(0, 0))')

    # Basic stuff
    assert Triangle(p1, p1, p1) == p1
    assert Triangle(p2, p2*2, p2*3) == Segment(p2, p2*3)
    assert t1.area == Rational(25,2)
    assert t1.is_right()
    assert t2.is_right() == False
    assert t3.is_right()
    assert p1 in t1
    assert t1.sides[0] in t1
    assert Segment((0, 0), (1, 0)) in t1
    assert Point(5, 5) not in t2
    assert t1.is_convex()
    assert feq(t1.angles[p1].evalf(), pi.evalf()/2)

    assert t1.is_equilateral() == False
    assert t2.is_equilateral()
    assert t3.is_equilateral() == False
    assert are_similar(t1, t2) == False
    assert are_similar(t1, t3)
    assert are_similar(t2, t3) == False
    assert t1.is_similar(Point(0, 0)) == False

    # Bisectors
    bisectors = t1.bisectors()
    assert bisectors[p1] == Segment(p1, Point(Rational(5,2), Rational(5,2)))
    ic = (250 - 125*sqrt(2)) / 50
    assert t1.incenter == Point(ic, ic)

    # Inradius
    assert t1.inradius == t1.incircle.radius == 5 - 5*sqrt(2)/2
    assert t2.inradius == t2.incircle.radius == 5*sqrt(3)/6
    assert t3.inradius == t3.incircle.radius == x1**2/((2 + sqrt(2))*Abs(x1))

    # Circumcircle
    assert t1.circumcircle.center == Point(2.5, 2.5)

    # Medians + Centroid
    m = t1.medians
    assert t1.centroid == Point(Rational(5,3), Rational(5,3))
    assert m[p1] == Segment(p1, Point(Rational(5,2), Rational(5,2)))
    assert t3.medians[p1] == Segment(p1, Point(x1/2, x1/2))
    assert intersection(m[p1], m[p2], m[p3]) == [t1.centroid]
    assert t1.medial == Triangle(Point(2.5, 0), Point(0, 2.5), Point(2.5, 2.5))

    # Perpendicular
    altitudes = t1.altitudes
    assert altitudes[p1] == Segment(p1, Point(Rational(5,2), Rational(5,2)))
    assert altitudes[p2] == s1[0]
    assert altitudes[p3] == s1[2]
    assert t1.orthocenter == p1

    # Ensure
    assert len(intersection(*bisectors.values())) == 1
    assert len(intersection(*altitudes.values())) == 1
    assert len(intersection(*m.values())) == 1

    # Distance
    p1 = Polygon(
        Point(0, 0), Point(1, 0),
        Point(1, 1), Point(0, 1))
    p2 = Polygon(
        Point(0, Rational(5)/4), Point(1, Rational(5)/4),
        Point(1, Rational(9)/4), Point(0,  Rational(9)/4))
    p3 = Polygon(
        Point(1, 2), Point(2, 2),
        Point(2, 1))
    p4 = Polygon(
        Point(1, 1), Point(Rational(6)/5, 1),
        Point(1, Rational(6)/5))
    pt1 = Point(half, half)
    pt2 = Point(1, 1)

    '''Polygon to Point'''
    assert p1.distance(pt1) == half
    assert p1.distance(pt2) == 0
    assert p2.distance(pt1) == Rational(3)/4
    assert p3.distance(pt2) == sqrt(2)/2
开发者ID:Misbah6317,项目名称:sympy,代码行数:101,代码来源:test_geometry.py

示例11: test_polygon


#.........这里部分代码省略.........
    s2 = t2.sides
    s3 = t3.sides

    # Basic stuff
    assert Triangle(p1, p1, p1) == p1
    assert Triangle(p2, p2 * 2, p2 * 3) == Segment(p2, p2 * 3)
    assert t1.area == Rational(25, 2)
    assert t1.is_right()
    assert t2.is_right() == False
    assert t3.is_right()
    assert p1 in t1
    assert Point(5, 5) not in t2
    assert t1.is_convex()
    assert feq(t1.angles[p1].evalf(), pi.evalf() / 2)

    assert t1.is_equilateral() == False
    assert t2.is_equilateral()
    assert t3.is_equilateral() == False
    assert are_similar(t1, t2) == False
    assert are_similar(t1, t3)
    assert are_similar(t2, t3) == False

    # Bisectors
    bisectors = t1.bisectors()
    assert bisectors[p1] == Segment(p1, Point(Rational(5, 2), Rational(5, 2)))
    ic = (250 - 125 * sqrt(2)) / 50
    assert t1.incenter == Point(ic, ic)

    # Inradius
    assert t1.inradius == 5 - 5 * sqrt(2) / 2
    assert t2.inradius == 5 * sqrt(3) / 6
    assert t3.inradius == x1 ** 2 / ((2 + sqrt(2)) * Abs(x1))

    # Medians + Centroid
    m = t1.medians
    assert t1.centroid == Point(Rational(5, 3), Rational(5, 3))
    assert m[p1] == Segment(p1, Point(Rational(5, 2), Rational(5, 2)))
    assert t3.medians[p1] == Segment(p1, Point(x1 / 2, x1 / 2))
    assert intersection(m[p1], m[p2], m[p3]) == [t1.centroid]

    # Perpendicular
    altitudes = t1.altitudes
    assert altitudes[p1] == Segment(p1, Point(Rational(5, 2), Rational(5, 2)))
    assert altitudes[p2] == s1[0]
    assert altitudes[p3] == s1[2]

    # Ensure
    assert len(intersection(*bisectors.values())) == 1
    assert len(intersection(*altitudes.values())) == 1
    assert len(intersection(*m.values())) == 1

    # Distance
    p1 = Polygon(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1))
    p2 = Polygon(
        Point(0, Rational(5) / 4), Point(1, Rational(5) / 4), Point(1, Rational(9) / 4), Point(0, Rational(9) / 4)
    )
    p3 = Polygon(Point(1, 2), Point(2, 2), Point(2, 1))
    p4 = Polygon(Point(1, 1), Point(Rational(6) / 5, 1), Point(1, Rational(6) / 5))
    p5 = Polygon(
        Point(half, 3 ** (half) / 2),
        Point(-half, 3 ** (half) / 2),
        Point(-1, 0),
        Point(-half, -(3) ** (half) / 2),
        Point(half, -(3) ** (half) / 2),
        Point(1, 0),
    )
    p6 = Polygon(
        Point(2, Rational(3) / 10),
        Point(Rational(17) / 10, 0),
        Point(2, -Rational(3) / 10),
        Point(Rational(23) / 10, 0),
    )
    pt1 = Point(half, half)
    pt2 = Point(1, 1)

    """Polygon to Point"""
    assert p1.distance(pt1) == half
    assert p1.distance(pt2) == 0
    assert p2.distance(pt1) == Rational(3) / 4
    assert p3.distance(pt2) == sqrt(2) / 2

    """Polygon to Polygon"""
    import warnings

    # p1.distance(p2) emits a warning
    # First, test the warning
    warnings.filterwarnings("error", "Polygons may intersect producing erroneous output")
    raises(UserWarning, "p1.distance(p2)")
    # now test the actual output
    warnings.filterwarnings("ignore", "Polygons may intersect producing erroneous output")
    assert p1.distance(p2) == half / 2
    # Keep testing reasonably thread safe, so reset the warning
    warnings.filterwarnings("default", "Polygons may intersect producing erroneous output")
    # Note, in Python 2.6+, this can be done more nicely using the
    # warnings.catch_warnings context manager.
    # See http://docs.python.org/library/warnings#testing-warnings.

    assert p1.distance(p3) == sqrt(2) / 2
    assert p3.distance(p4) == (sqrt(2) / 2 - sqrt(Rational(2) / 25) / 2)
    assert p5.distance(p6) == Rational(7) / 10
开发者ID:addisonc,项目名称:sympy,代码行数:101,代码来源:test_geometry.py

示例12: test_line

def test_line():
    p1 = Point(0, 0)
    p2 = Point(1, 1)
    p3 = Point(x1, x1)
    p4 = Point(y1, y1)
    p5 = Point(x1, 1 + x1)
    p6 = Point(1, 0)
    p7 = Point(0, 1)
    p8 = Point(2, 0)
    p9 = Point(2, 1)

    l1 = Line(p1, p2)
    l2 = Line(p3, p4)
    l3 = Line(p3, p5)
    l4 = Line(p1, p6)
    l5 = Line(p1, p7)
    l6 = Line(p8, p9)
    l7 = Line(p2, p9)

    # Basic stuff
    assert Line((1, 1), slope=1) == Line((1, 1), (2, 2))
    assert Line((1, 1), slope=oo) == Line((1, 1), (1, 2))
    assert Line((1, 1), slope=-oo) == Line((1, 1), (1, 2))
    raises(ValueError, "Line((1, 1), 1)")
    assert Line(p1, p2) == Line(p2, p1)
    assert l1 == l2
    assert l1 != l3
    assert l1.slope == 1
    assert l3.slope == oo
    assert l4.slope == 0
    assert l4.coefficients == (0, 1, 0)
    assert l4.equation(x=x, y=y) == y
    assert l5.slope == oo
    assert l5.coefficients == (1, 0, 0)
    assert l5.equation() == x
    assert l6.equation() == x - 2
    assert l7.equation() == y - 1
    assert p1 in l1  # is p1 on the line l1?
    assert p1 not in l3

    assert simplify(l1.equation()) in (x - y, y - x)
    assert simplify(l3.equation()) in (x - x1, x1 - x)

    assert l2.arbitrary_point() in l2
    for ind in xrange(0, 5):
        assert l3.random_point() in l3

    # Orthogonality
    p1_1 = Point(-x1, x1)
    l1_1 = Line(p1, p1_1)
    assert l1.perpendicular_line(p1) == l1_1
    assert Line.is_perpendicular(l1, l1_1)
    assert Line.is_perpendicular(l1, l2) == False

    # Parallelity
    p2_1 = Point(-2 * x1, 0)
    l2_1 = Line(p3, p5)
    assert l2.parallel_line(p1_1) == Line(p2_1, p1_1)
    assert l2_1.parallel_line(p1) == Line(p1, Point(0, 2))
    assert Line.is_parallel(l1, l2)
    assert Line.is_parallel(l2, l3) == False
    assert Line.is_parallel(l2, l2.parallel_line(p1_1))
    assert Line.is_parallel(l2_1, l2_1.parallel_line(p1))

    # Intersection
    assert intersection(l1, p1) == [p1]
    assert intersection(l1, p5) == []
    assert intersection(l1, l2) in [[l1], [l2]]
    assert intersection(l1, l1.parallel_line(p5)) == []

    # Concurrency
    l3_1 = Line(Point(5, x1), Point(-Rational(3, 5), x1))
    assert Line.is_concurrent(l1, l3)
    assert Line.is_concurrent(l1, l3, l3_1)
    assert Line.is_concurrent(l1, l1_1, l3) == False

    # Projection
    assert l2.projection(p4) == p4
    assert l1.projection(p1_1) == p1
    assert l3.projection(p2) == Point(x1, 1)

    # Finding angles
    l1_1 = Line(p1, Point(5, 0))
    assert feq(Line.angle_between(l1, l1_1).evalf(), pi.evalf() / 4)

    # Testing Rays and Segments (very similar to Lines)
    assert Ray((1, 1), angle=pi / 4) == Ray((1, 1), (2, 2))
    assert Ray((1, 1), angle=pi / 2) == Ray((1, 1), (1, 2))
    assert Ray((1, 1), angle=-pi / 2) == Ray((1, 1), (1, 0))
    assert Ray((1, 1), angle=-3 * pi / 2) == Ray((1, 1), (1, 2))
    assert Ray((1, 1), angle=5 * pi / 2) == Ray((1, 1), (1, 2))
    assert Ray((1, 1), angle=5.0 * pi / 2) == Ray((1, 1), (1, 2))
    assert Ray((1, 1), angle=pi) == Ray((1, 1), (0, 1))
    assert Ray((1, 1), angle=3.0 * pi) == Ray((1, 1), (0, 1))
    assert Ray((1, 1), angle=4.0 * pi) == Ray((1, 1), (2, 1))
    assert Ray((1, 1), angle=0) == Ray((1, 1), (2, 1))
    # XXX don't know why this fails without str
    assert str(Ray((1, 1), angle=4.2 * pi)) == str(Ray(Point(1, 1), Point(2, 1 + C.tan(0.2 * pi))))
    assert Ray((1, 1), angle=5) == Ray((1, 1), (2, 1 + C.tan(5)))
    raises(ValueError, "Ray((1, 1), 1)")
#.........这里部分代码省略.........
开发者ID:addisonc,项目名称:sympy,代码行数:101,代码来源:test_geometry.py

示例13: test_polygon


#.........这里部分代码省略.........
    assert feq(angles[Point(4, 4)].evalf(), Float("1.2490457723982544"))
    assert feq(angles[Point(5, 2)].evalf(), Float("1.8925468811915388"))
    assert feq(angles[Point(3, 0)].evalf(), Float("2.3561944901923449"))

    #
    # Triangle
    #
    p1 = Point(0, 0)
    p2 = Point(5, 0)
    p3 = Point(0, 5)
    t1 = Triangle(p1, p2, p3)
    t2 = Triangle(p1, p2, Point(Rational(5, 2), sqrt(Rational(75, 4))))
    t3 = Triangle(p1, Point(x1, 0), Point(0, x1))
    s1 = t1.sides
    assert Triangle(p1, p2, p1) == Polygon(p1, p2, p1) == Segment(p1, p2)
    raises(GeometryError, lambda: Triangle(Point(0, 0)))

    # Basic stuff
    assert Triangle(p1, p1, p1) == p1
    assert Triangle(p2, p2 * 2, p2 * 3) == Segment(p2, p2 * 3)
    assert t1.area == Rational(25, 2)
    assert t1.is_right()
    assert t2.is_right() == False
    assert t3.is_right()
    assert p1 in t1
    assert t1.sides[0] in t1
    assert Segment((0, 0), (1, 0)) in t1
    assert Point(5, 5) not in t2
    assert t1.is_convex()
    assert feq(t1.angles[p1].evalf(), pi.evalf() / 2)

    assert t1.is_equilateral() == False
    assert t2.is_equilateral()
    assert t3.is_equilateral() == False
    assert are_similar(t1, t2) == False
    assert are_similar(t1, t3)
    assert are_similar(t2, t3) == False
    assert t1.is_similar(Point(0, 0)) == False

    # Bisectors
    bisectors = t1.bisectors()
    assert bisectors[p1] == Segment(p1, Point(Rational(5, 2), Rational(5, 2)))
    ic = (250 - 125 * sqrt(2)) / 50
    assert t1.incenter == Point(ic, ic)

    # Inradius
    assert t1.inradius == t1.incircle.radius == 5 - 5 * sqrt(2) / 2
    assert t2.inradius == t2.incircle.radius == 5 * sqrt(3) / 6
    assert t3.inradius == t3.incircle.radius == x1 ** 2 / ((2 + sqrt(2)) * Abs(x1))

    # Circumcircle
    assert t1.circumcircle.center == Point(2.5, 2.5)

    # Medians + Centroid
    m = t1.medians
    assert t1.centroid == Point(Rational(5, 3), Rational(5, 3))
    assert m[p1] == Segment(p1, Point(Rational(5, 2), Rational(5, 2)))
    assert t3.medians[p1] == Segment(p1, Point(x1 / 2, x1 / 2))
    assert intersection(m[p1], m[p2], m[p3]) == [t1.centroid]
    assert t1.medial == Triangle(Point(2.5, 0), Point(0, 2.5), Point(2.5, 2.5))

    # Perpendicular
    altitudes = t1.altitudes
    assert altitudes[p1] == Segment(p1, Point(Rational(5, 2), Rational(5, 2)))
    assert altitudes[p2] == s1[0]
    assert altitudes[p3] == s1[2]
    assert t1.orthocenter == p1
    t = S(
        """Triangle(
    Point(100080156402737/5000000000000, 79782624633431/500000000000),
    Point(39223884078253/2000000000000, 156345163124289/1000000000000),
    Point(31241359188437/1250000000000, 338338270939941/1000000000000000))"""
    )
    assert t.orthocenter == S(
        """Point(-780660869050599840216997"""
        """79471538701955848721853/80368430960602242240789074233100000000000000,"""
        """20151573611150265741278060334545897615974257/16073686192120448448157"""
        """8148466200000000000)"""
    )

    # Ensure
    assert len(intersection(*bisectors.values())) == 1
    assert len(intersection(*altitudes.values())) == 1
    assert len(intersection(*m.values())) == 1

    # Distance
    p1 = Polygon(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1))
    p2 = Polygon(
        Point(0, Rational(5) / 4), Point(1, Rational(5) / 4), Point(1, Rational(9) / 4), Point(0, Rational(9) / 4)
    )
    p3 = Polygon(Point(1, 2), Point(2, 2), Point(2, 1))
    p4 = Polygon(Point(1, 1), Point(Rational(6) / 5, 1), Point(1, Rational(6) / 5))
    pt1 = Point(half, half)
    pt2 = Point(1, 1)

    """Polygon to Point"""
    assert p1.distance(pt1) == half
    assert p1.distance(pt2) == 0
    assert p2.distance(pt1) == Rational(3) / 4
    assert p3.distance(pt2) == sqrt(2) / 2
开发者ID:flacjacket,项目名称:sympy,代码行数:101,代码来源:test_geometry.py

示例14: test_line

def test_line():
    p1 = Point(0, 0)
    p2 = Point(1, 1)
    p3 = Point(x1, x1)
    p4 = Point(y1, y1)
    p5 = Point(x1, 1 + x1)
    p6 = Point(1, 0)
    p7 = Point(0, 1)
    p8 = Point(2, 0)
    p9 = Point(2, 1)

    l1 = Line(p1, p2)
    l2 = Line(p3, p4)
    l3 = Line(p3, p5)
    l4 = Line(p1, p6)
    l5 = Line(p1, p7)
    l6 = Line(p8, p9)
    l7 = Line(p2, p9)
    raises(ValueError, lambda: Line(Point(0, 0), Point(0, 0)))

    # Basic stuff
    assert Line((1, 1), slope=1) == Line((1, 1), (2, 2))
    assert Line((1, 1), slope=oo) == Line((1, 1), (1, 2))
    assert Line((1, 1), slope=-oo) == Line((1, 1), (1, 2))
    raises(ValueError, lambda: Line((1, 1), 1))
    assert Line(p1, p2) == Line(p2, p1)
    assert l1 == l2
    assert l1 != l3
    assert l1.slope == 1
    assert l1.length == oo
    assert l3.slope == oo
    assert l4.slope == 0
    assert l4.coefficients == (0, 1, 0)
    assert l4.equation(x=x, y=y) == y
    assert l5.slope == oo
    assert l5.coefficients == (1, 0, 0)
    assert l5.equation() == x
    assert l6.equation() == x - 2
    assert l7.equation() == y - 1
    assert p1 in l1  # is p1 on the line l1?
    assert p1 not in l3
    assert Line((-x, x), (-x + 1, x - 1)).coefficients == (1, 1, 0)

    assert simplify(l1.equation()) in (x - y, y - x)
    assert simplify(l3.equation()) in (x - x1, x1 - x)

    assert Line(p1, p2).scale(2, 1) == Line(p1, p9)

    assert l2.arbitrary_point() in l2
    for ind in xrange(0, 5):
        assert l3.random_point() in l3

    # Orthogonality
    p1_1 = Point(-x1, x1)
    l1_1 = Line(p1, p1_1)
    assert l1.perpendicular_line(p1) == l1_1
    assert Line.is_perpendicular(l1, l1_1)
    assert Line.is_perpendicular(l1, l2) == False
    p = l1.random_point()
    assert l1.perpendicular_segment(p) == p

    # Parallelity
    p2_1 = Point(-2 * x1, 0)
    l2_1 = Line(p3, p5)
    assert l2.parallel_line(p1_1) == Line(p2_1, p1_1)
    assert l2_1.parallel_line(p1) == Line(p1, Point(0, 2))
    assert Line.is_parallel(l1, l2)
    assert Line.is_parallel(l2, l3) == False
    assert Line.is_parallel(l2, l2.parallel_line(p1_1))
    assert Line.is_parallel(l2_1, l2_1.parallel_line(p1))

    # Intersection
    assert intersection(l1, p1) == [p1]
    assert intersection(l1, p5) == []
    assert intersection(l1, l2) in [[l1], [l2]]
    assert intersection(l1, l1.parallel_line(p5)) == []

    # Concurrency
    l3_1 = Line(Point(5, x1), Point(-Rational(3, 5), x1))
    assert Line.is_concurrent(l1) == False
    assert Line.is_concurrent(l1, l3)
    assert Line.is_concurrent(l1, l3, l3_1)
    assert Line.is_concurrent(l1, l1_1, l3) == False

    # Projection
    assert l2.projection(p4) == p4
    assert l1.projection(p1_1) == p1
    assert l3.projection(p2) == Point(x1, 1)
    raises(GeometryError, lambda: Line(Point(0, 0), Point(1, 0)).projection(Circle(Point(0, 0), 1)))

    # Finding angles
    l1_1 = Line(p1, Point(5, 0))
    assert feq(Line.angle_between(l1, l1_1).evalf(), pi.evalf() / 4)

    # Testing Rays and Segments (very similar to Lines)
    assert Ray((1, 1), angle=pi / 4) == Ray((1, 1), (2, 2))
    assert Ray((1, 1), angle=pi / 2) == Ray((1, 1), (1, 2))
    assert Ray((1, 1), angle=-pi / 2) == Ray((1, 1), (1, 0))
    assert Ray((1, 1), angle=-3 * pi / 2) == Ray((1, 1), (1, 2))
    assert Ray((1, 1), angle=5 * pi / 2) == Ray((1, 1), (1, 2))
#.........这里部分代码省略.........
开发者ID:flacjacket,项目名称:sympy,代码行数:101,代码来源:test_geometry.py

示例15: test_line_geom

def test_line_geom():
    x = Symbol('x', real=True)
    y = Symbol('y', real=True)
    x1 = Symbol('x1', real=True)
    y1 = Symbol('y1', real=True)
    half = Rational(1, 2)
    p1 = Point(0, 0)
    p2 = Point(1, 1)
    p3 = Point(x1, x1)
    p4 = Point(y1, y1)
    p5 = Point(x1, 1 + x1)
    p6 = Point(1, 0)
    p7 = Point(0, 1)
    p8 = Point(2, 0)
    p9 = Point(2, 1)

    l1 = Line(p1, p2)
    l2 = Line(p3, p4)
    l3 = Line(p3, p5)
    l4 = Line(p1, p6)
    l5 = Line(p1, p7)
    l6 = Line(p8, p9)
    l7 = Line(p2, p9)
    raises(ValueError, lambda: Line(Point(0, 0), Point(0, 0)))

    # Basic stuff
    assert Line((1, 1), slope=1) == Line((1, 1), (2, 2))
    assert Line((1, 1), slope=oo) == Line((1, 1), (1, 2))
    assert Line((1, 1), slope=-oo) == Line((1, 1), (1, 2))
    raises(TypeError, lambda: Line((1, 1), 1))
    assert Line(p1, p2) == Line(p1, p2)
    assert Line(p1, p2) != Line(p2, p1)
    assert l1 != l2
    assert l1 != l3
    assert l1.slope == 1
    assert l1.length == oo
    assert l3.slope == oo
    assert l4.slope == 0
    assert l4.coefficients == (0, 1, 0)
    assert l4.equation(x=x, y=y) == y
    assert l5.slope == oo
    assert l5.coefficients == (1, 0, 0)
    assert l5.equation() == x
    assert l6.equation() == x - 2
    assert l7.equation() == y - 1
    assert p1 in l1  # is p1 on the line l1?
    assert p1 not in l3
    assert Line((-x, x), (-x + 1, x - 1)).coefficients == (1, 1, 0)

    assert simplify(l1.equation()) in (x - y, y - x)
    assert simplify(l3.equation()) in (x - x1, x1 - x)

    assert Line(p1, p2).scale(2, 1) == Line(p1, p9)

    assert l2.arbitrary_point() in l2
    for ind in range(0, 5):
        assert l3.random_point() in l3

    # Orthogonality
    p1_1 = Point(-x1, x1)
    l1_1 = Line(p1, p1_1)
    assert l1.perpendicular_line(p1.args).equals( Line(Point(0, 0), Point(1, -1)) )
    assert l1.perpendicular_line(p1).equals( Line(Point(0, 0), Point(1, -1)) )
    assert Line.is_perpendicular(l1, l1_1)
    assert Line.is_perpendicular(l1, l2) is False
    p = l1.random_point()
    assert l1.perpendicular_segment(p) == p

    # Parallelity
    l2_1 = Line(p3, p5)
    assert l2.parallel_line(p1_1).equals( Line(Point(-x1, x1), Point(-y1, 2*x1 - y1)) )
    assert l2_1.parallel_line(p1.args).equals( Line(Point(0, 0), Point(0, -1)) )
    assert l2_1.parallel_line(p1).equals( Line(Point(0, 0), Point(0, -1)) )
    assert Line.is_parallel(l1, l2)
    assert Line.is_parallel(l2, l3) is False
    assert Line.is_parallel(l2, l2.parallel_line(p1_1))
    assert Line.is_parallel(l2_1, l2_1.parallel_line(p1))

    # Intersection
    assert intersection(l1, p1) == [p1]
    assert intersection(l1, p5) == []
    assert intersection(l1, l2) in [[l1], [l2]]
    assert intersection(l1, l1.parallel_line(p5)) == []

    # Concurrency
    l3_1 = Line(Point(5, x1), Point(-Rational(3, 5), x1))
    assert Line.are_concurrent(l1) is False
    assert Line.are_concurrent(l1, l3)
    assert Line.are_concurrent(l1, l1, l1, l3)
    assert Line.are_concurrent(l1, l3, l3_1)
    assert Line.are_concurrent(l1, l1_1, l3) is False

    # Projection
    assert l2.projection(p4) == p4
    assert l1.projection(p1_1) == p1
    assert l3.projection(p2) == Point(x1, 1)
    raises(GeometryError, lambda: Line(Point(0, 0), Point(1, 0))
           .projection(Circle(Point(0, 0), 1)))

    # Finding angles
#.........这里部分代码省略.........
开发者ID:alexako,项目名称:sympy,代码行数:101,代码来源:test_line.py


注:本文中的sympy.geometry.intersection函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。