All Samples(56) | Call(54) | Derive(0) | Import(2)

Finds the intersection between a list GeometryEntity instances. Returns a list of all the intersections, Will raise a NotImplementedError exception if unable to calculate the intersection. Examples: ========= >>> from sympy.geometry import Point, Line, Circle, intersection >>> p1,p2,p3 = Point(0,0), Point(1,1), Point(-1, 5) >>> l1, l2 = Line(p1, p2), Line(p3, p2) >>> c = Circle(p2, 1)(more...)

def intersection(*entities): """ Finds the intersection between a list GeometryEntity instances. Returns a list of all the intersections, Will raise a NotImplementedError exception if unable to calculate the intersection. Examples: ========= >>> from sympy.geometry import Point, Line, Circle, intersection >>> p1,p2,p3 = Point(0,0), Point(1,1), Point(-1, 5) >>> l1, l2 = Line(p1, p2), Line(p3, p2) >>> c = Circle(p2, 1) >>> intersection(l1, p2) [Point(1, 1)] >>> intersection(l1, l2) [Point(1, 1)] >>> intersection(c, p2) [] >>> intersection(c, Point(1, 0)) [Point(1, 0)] >>> intersection(c, l2) [Point(1 - 5**(1/2)/5, 1 + 2*5**(1/2)/5), Point(1 + 5**(1/2)/5, 1 - 2*5**(1/2)/5)] Notes: ====== - The intersection of any geometrical entity with itself should return a list with one item: the entity in question. - An intersection requires two or more entities. If only a single entity is given then one will receive an empty intersection list. - It is possible for intersection() to miss intersections that one knows exists because the required quantities were not fully simplified internally. - Reals should be converted to Rationals, e.g. Rational(str(real_num)) or else failures due to floating point issues may result. """ from entity import GeometryEntity entities = GeometryEntity.extract_entities(entities, False) if len(entities) <= 1: return [] res = GeometryEntity.do_intersection(entities[0], entities[1]) for entity in entities[2:]: newres = [] for x in res: newres.extend( GeometryEntity.do_intersection(x, entity) ) res = newres return res

**sympy-polys**(Download)

from sympy import Symbol, Rational, sqrt, pi, cos, oo, simplify, Real, raises from sympy.geometry import Point, Polygon, convex_hull, Segment, \ RegularPolygon, Circle, Ellipse, GeometryError, Line, intersection, \ Ray, Triangle, are_similar, Curve

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

src/s/y/sympy-HEAD/sympy/geometry/tests/test_geometry.py

**sympy**(Download)

from sympy import (Abs, C, Dummy, Rational, Float, S, Symbol, cos, oo, pi, simplify, sin, sqrt, symbols, tan) from sympy.geometry import (Circle, Curve, Ellipse, GeometryError, Line, Point, Polygon, Ray, RegularPolygon, Segment, Triangle, are_similar, convex_hull, intersection, centroid)

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