本文整理汇总了Python中sympy.geometry.Line类的典型用法代码示例。如果您正苦于以下问题:Python Line类的具体用法?Python Line怎么用?Python Line使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Line类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_reflect
def test_reflect():
b = Symbol('b')
m = Symbol('m')
l = Line((0, b), slope=m)
p = Point(x, y)
r = p.reflect(l)
dp = l.perpendicular_segment(p).length
dr = l.perpendicular_segment(r).length
assert test_numerically(dp, dr)
t = Triangle((0, 0), (1, 0), (2, 3))
assert t.area == -t.reflect(l).area
e = Ellipse((1, 0), 1, 2)
assert e.area == -e.reflect(Line((1, 0), slope=0)).area
assert e.area == -e.reflect(Line((1, 0), slope=oo)).area
raises(NotImplementedError, lambda: e.reflect(Line((1,0), slope=m)))
# test entity overrides
c = Circle((x, y), 3)
cr = c.reflect(l)
assert cr == Circle(r, -3)
assert c.area == -cr.area
pent = RegularPolygon((1, 2), 1, 5)
l = Line((0, pi), slope=sqrt(2))
rpent = pent.reflect(l)
poly_pent = Polygon(*pent.vertices)
assert rpent.center == pent.center.reflect(l)
assert str([w.n(3) for w in rpent.vertices]) == (
'[Point(-0.586, 4.27), Point(-1.69, 4.66), '
'Point(-2.41, 3.73), Point(-1.74, 2.76), '
'Point(-0.616, 3.10)]')
assert pent.area.equals(-rpent.area)
开发者ID:Acebulf,项目名称:sympy,代码行数:30,代码来源:test_geometry.py
示例2: cast
def cast(self):
# generate line
line = Line(self.current, self.direction)
shortest_ray = None
intersecting_segment = None
intersection_point = None
l = math.inf
for segment in self.mirrors:
# intersect line with segments from triangle
mirror_point = line.intersection(segment)
if mirror_point != []:
mirror_point = mirror_point[0]
ray = Segment(self.current, mirror_point)
if isinstance(ray, Segment):
if ray.length < l:
l = ray.length
shortest_ray = ray
intersecting_segment = segment
intersection_point = mirror_point
# calculate angle between ray and segment
next_ray = None
if intersecting_segment is not None:
incidenting_angle = shortest_ray.angle_between(intersecting_segment)
corrected_incidenting_angle = incidenting_angle % (pi/2)
print("ray is intersecting with an angle: ", math.degrees(incidenting_angle), "corrected", math.degrees(corrected_incidenting_angle))
next_ray = shortest_ray.rotate((math.pi/2-corrected_incidenting_angle)*2, pt=intersection_point)
self.current = next_ray.points[0]
self.direction = next_ray.points[1]
return [shortest_ray, next_ray]
开发者ID:ventilator,项目名称:peuler,代码行数:30,代码来源:mirr0r.py
示例3: test_symbolic_intersect
def test_symbolic_intersect():
x = Symbol('x', real=True)
y = Symbol('y', real=True)
z = Symbol('z', real=True)
k = Symbol('k', real=True)
# Issue 7814.
circle = Circle(Point(x, 0), y)
line = Line(Point(k, z), slope=0)
assert line.intersection(circle) == [
Point(x - sqrt(y**2 - z**2), z), Point(x + sqrt(y**2 - z**2), z)]
开发者ID:Kogorushi,项目名称:sympy,代码行数:10,代码来源:test_line.py
示例4: intersection_of_vector_with_triangle
def intersection_of_vector_with_triangle(self):
A,B,C = self.get_trinangle_points()
S_AB = Segment(A,B)
S_AC = Segment(A,C)
S_BC = Segment(B,C)
P1, P2 = self.two_points_from_vector(self.vector())
L_vector = Line(P1, P2)
mirror_point = L_vector.intersection(S_AB)
return mirror_point
开发者ID:ventilator,项目名称:peuler,代码行数:11,代码来源:mirr0r.py
示例5: get_angle_between
def get_angle_between(self, line1, line2):
"""
Uses SymPy to calculate the angle between two lines. Assumes input formatted as Shapely lines.
:param: line 1
:param: line 2
:return: angle between two lines
"""
return SymLine.angle_between(
SymLine(SymPoint(*line1.coords[0]), SymPoint(*line1.coords[1])),
SymLine(SymPoint(*line2.coords[0]), SymPoint(*line2.coords[1]))
)
开发者ID:LucNies,项目名称:devrob-corbetta,代码行数:11,代码来源:eye.py
示例6: test_reflect
def test_reflect():
x = Symbol('x', real=True)
y = Symbol('y', real=True)
b = Symbol('b')
m = Symbol('m')
l = Line((0, b), slope=m)
p = Point(x, y)
r = p.reflect(l)
dp = l.perpendicular_segment(p).length
dr = l.perpendicular_segment(r).length
assert verify_numerically(dp, dr)
t = Triangle((0, 0), (1, 0), (2, 3))
assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=oo)) \
== Triangle(Point(5, 0), Point(4, 0), Point(4, 2))
assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=oo)) \
== Triangle(Point(-1, 0), Point(-2, 0), Point(-2, 2))
assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=0)) \
== Triangle(Point(1, 6), Point(2, 6), Point(2, 4))
assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=0)) \
== Triangle(Point(1, 0), Point(2, 0), Point(2, -2))
开发者ID:alexako,项目名称:sympy,代码行数:21,代码来源:test_polygon.py
示例7: test_equation
def test_equation():
p1 = Point(0, 0)
p2 = Point(1, 1)
l1 = Line(p1, p2)
l3 = Line(Point(x1, x1), Point(x1, 1 + x1))
assert simplify(l1.equation()) in (x - y, y - x)
assert simplify(l3.equation()) in (x - x1, x1 - x)
assert simplify(l1.equation()) in (x - y, y - x)
assert simplify(l3.equation()) in (x - x1, x1 - x)
assert Line(p1, Point(1, 0)).equation(x=x, y=y) == y
assert Line(p1, Point(0, 1)).equation() == x
assert Line(Point(2, 0), Point(2, 1)).equation() == x - 2
assert Line(p2, Point(2, 1)).equation() == y - 1
assert Line3D(Point(x1, x1, x1), Point(y1, y1, y1)
).equation() == (-x + y, -x + z)
assert Line3D(Point(1, 2, 3), Point(2, 3, 4)
).equation() == (-x + y - 1, -x + z - 2)
assert Line3D(Point(1, 2, 3), Point(1, 3, 4)
).equation() == (x - 1, -y + z - 1)
assert Line3D(Point(1, 2, 3), Point(2, 2, 4)
).equation() == (y - 2, -x + z - 2)
assert Line3D(Point(1, 2, 3), Point(2, 3, 3)
).equation() == (-x + y - 1, z - 3)
assert Line3D(Point(1, 2, 3), Point(1, 2, 4)
).equation() == (x - 1, y - 2)
assert Line3D(Point(1, 2, 3), Point(1, 3, 3)
).equation() == (x - 1, z - 3)
assert Line3D(Point(1, 2, 3), Point(2, 2, 3)
).equation() == (y - 2, z - 3)
开发者ID:Lenqth,项目名称:sympy,代码行数:32,代码来源:test_line.py
示例8: 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
示例9: generate_map
def generate_map():
screen.fill((0, 0, 0))
points = generate_random_points(num_points, width, height, buf)
#for x, y in points:
# pygame.draw.circle(screen, WHITE, (x,y), 2, 1)
voronoi_context = voronoi(points)
voronoi_point_dict = {}
point_to_segment_dict = {}
segments = []
vertices = []
top_l = Point(0,0)
top_r = Point(width,0)
bottom_l = Point(0, height)
bottom_r = Point(width, height)
top = Line(top_l, top_r)
left = Line(top_l, bottom_l)
right = Line(top_r, bottom_r)
bottom = Line(bottom_l, bottom_r)
boundaries = [top, right, bottom, left]
for edge in voronoi_context.edges:
il, i1, i2 = edge # index of line, index of vertex 1, index of vertex 2
line_color = RED
vert1 = None
vert2 = None
print_line = True
if i1 is not -1 and i2 is not -1:
vert1 = voronoi_context.vertices[i1]
vert2 = voronoi_context.vertices[i2]
else:
line_point = None
if i1 is -1:
line_p = voronoi_context.vertices[i2]
if i2 is -1:
line_p = voronoi_context.vertices[i1]
line_point = Point(line_p[0], line_p[1])
line = voronoi_context.lines[il]
p1 = None
p2 = None
if line[1] == 0:
p1 = line_point
p2 = Point(line[0]/line[2], 1)
else:
p1 = Point(0, line[2]/line[1])
p2 = line_point
l = Line(p1, p2)
top_intersect = l.intersection(top)
bottom_intersect = l.intersection(bottom)
right_intersect = l.intersection(right)
left_intersect = l.intersection(left)
distances = []
top_dist = None
bottom_dist = None
right_dist = None
left_dist = None
if len(top_intersect) != 0:
top_dist = abs(line_point.distance(top_intersect[0]))
distances.append(top_dist)
if len(bottom_intersect) != 0 :
bottom_dist = abs(line_point.distance(bottom_intersect[0]))
distances.append(bottom_dist)
if len(right_intersect) != 0:
right_dist = abs(line_point.distance(right_intersect[0]))
distances.append(right_dist)
if len(left_intersect) != 0:
left_dist = abs(line_point.distance(left_intersect[0]))
distances.append(left_dist)
vert1 = line_p
v2 = None
if top_dist == min(distances):
v2 = top_intersect[0]
elif bottom_dist == min(distances):
v2 = bottom_intersect[0]
elif right_dist == min(distances):
v2 = right_intersect[0]
elif left_dist == min(distances):
#.........这里部分代码省略.........
开发者ID:jesselupica,项目名称:EmpyreGameMapGenerator,代码行数:101,代码来源:map.py
示例10: test_point
def test_point():
x = Symbol('x', real=True)
y = Symbol('y', real=True)
x1 = Symbol('x1', real=True)
x2 = Symbol('x2', real=True)
y1 = Symbol('y1', real=True)
y2 = Symbol('y2', real=True)
half = Rational(1, 2)
p1 = Point(x1, x2)
p2 = Point(y1, y2)
p3 = Point(0, 0)
p4 = Point(1, 1)
p5 = Point(0, 1)
line = Line(Point(1,0), slope = 1)
assert p1 in p1
assert p1 not in p2
assert p2.y == y2
assert (p3 + p4) == p4
assert (p2 - p1) == Point(y1 - x1, y2 - x2)
assert p4*5 == Point(5, 5)
assert -p2 == Point(-y1, -y2)
raises(ValueError, lambda: Point(3, I))
raises(ValueError, lambda: Point(2*I, I))
raises(ValueError, lambda: Point(3 + I, I))
assert Point(34.05, sqrt(3)) == Point(Rational(681, 20), sqrt(3))
assert Point.midpoint(p3, p4) == Point(half, half)
assert Point.midpoint(p1, p4) == Point(half + half*x1, half + half*x2)
assert Point.midpoint(p2, p2) == p2
assert p2.midpoint(p2) == p2
assert Point.distance(p3, p4) == sqrt(2)
assert Point.distance(p1, p1) == 0
assert Point.distance(p3, p2) == sqrt(p2.x**2 + p2.y**2)
# distance should be symmetric
assert p1.distance(line) == line.distance(p1)
assert p4.distance(line) == line.distance(p4)
assert Point.taxicab_distance(p4, p3) == 2
assert Point.canberra_distance(p4, p5) == 1
p1_1 = Point(x1, x1)
p1_2 = Point(y2, y2)
p1_3 = Point(x1 + 1, x1)
assert Point.is_collinear(p3)
with warns(UserWarning):
assert Point.is_collinear(p3, Point(p3, dim=4))
assert p3.is_collinear()
assert Point.is_collinear(p3, p4)
assert Point.is_collinear(p3, p4, p1_1, p1_2)
assert Point.is_collinear(p3, p4, p1_1, p1_3) is False
assert Point.is_collinear(p3, p3, p4, p5) is False
raises(TypeError, lambda: Point.is_collinear(line))
raises(TypeError, lambda: p1_1.is_collinear(line))
assert p3.intersection(Point(0, 0)) == [p3]
assert p3.intersection(p4) == []
x_pos = Symbol('x', real=True, positive=True)
p2_1 = Point(x_pos, 0)
p2_2 = Point(0, x_pos)
p2_3 = Point(-x_pos, 0)
p2_4 = Point(0, -x_pos)
p2_5 = Point(x_pos, 5)
assert Point.is_concyclic(p2_1)
assert Point.is_concyclic(p2_1, p2_2)
assert Point.is_concyclic(p2_1, p2_2, p2_3, p2_4)
for pts in permutations((p2_1, p2_2, p2_3, p2_5)):
assert Point.is_concyclic(*pts) is False
assert Point.is_concyclic(p4, p4 * 2, p4 * 3) is False
assert Point(0, 0).is_concyclic((1, 1), (2, 2), (2, 1)) is False
assert p4.scale(2, 3) == Point(2, 3)
assert p3.scale(2, 3) == p3
assert p4.rotate(pi, Point(0.5, 0.5)) == p3
assert p1.__radd__(p2) == p1.midpoint(p2).scale(2, 2)
assert (-p3).__rsub__(p4) == p3.midpoint(p4).scale(2, 2)
assert p4 * 5 == Point(5, 5)
assert p4 / 5 == Point(0.2, 0.2)
raises(ValueError, lambda: Point(0, 0) + 10)
# Point differences should be simplified
assert Point(x*(x - 1), y) - Point(x**2 - x, y + 1) == Point(0, -1)
a, b = Rational(1, 2), Rational(1, 3)
assert Point(a, b).evalf(2) == \
Point(a.n(2), b.n(2))
raises(ValueError, lambda: Point(1, 2) + 1)
# test transformations
p = Point(1, 0)
assert p.rotate(pi/2) == Point(0, 1)
#.........这里部分代码省略.........
开发者ID:asmeurer,项目名称:sympy,代码行数:101,代码来源:test_point.py
示例11: 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)
l1 = Line(p1, p2)
l2 = Line(p3, p4)
l3 = Line(p3, p5)
# Basic stuff
assert Line(p1, p2) == Line(p2, p1)
assert l1 == l2
assert l1 != l3
assert l1.slope == 1
assert l3.slope == oo
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)
r1 = Ray(p1, Point(-1, 5))
r2 = Ray(p1, Point(-1, 1))
r3 = Ray(p3, p5)
assert l1.projection(r1) == Ray(p1, p2)
assert l1.projection(r2) == p1
assert r3 != r1
s1 = Segment(p1, p2)
s2 = Segment(p1, p1_1)
assert s1.midpoint == Point(Rational(1,2), Rational(1,2))
assert s2.length == sqrt( 2*(x1**2) )
assert s1.perpendicular_bisector() == Line(Point(0, 1), Point(1, 0))
# Testing distance from a Segment to an object
s1 = Segment(Point(0, 0), Point(1, 1))
s2 = Segment(Point(half, half), Point(1, 0))
pt1 = Point(0, 0)
pt2 = Point(Rational(3)/2, Rational(3)/2)
assert s1.distance(pt1) == 0
assert s2.distance(pt1) == 2**(half)/2
assert s2.distance(pt2) == 2**(half)
# Special cases of projection and intersection
r1 = Ray(Point(1, 1), Point(2, 2))
r2 = Ray(Point(2, 2), Point(0, 0))
r3 = Ray(Point(1, 1), Point(-1, -1))
r4 = Ray(Point(0, 4), Point(-1, -5))
assert intersection(r1, r2) == [Segment(Point(1, 1), Point(2, 2))]
assert intersection(r1, r3) == [Point(1, 1)]
assert r1.projection(r3) == Point(1, 1)
assert r1.projection(r4) == Segment(Point(1, 1), Point(2, 2))
r5 = Ray(Point(0, 0), Point(0, 1))
r6 = Ray(Point(0, 0), Point(0, 2))
#.........这里部分代码省略.........
开发者ID:pernici,项目名称:sympy,代码行数:101,代码来源:test_geometry.py
示例12: test_parameter_value
def test_parameter_value():
t = Symbol('t')
p1, p2 = Point(0, 1), Point(5, 6)
l = Line(p1, p2)
assert l.parameter_value((5, 6), t) == {t: 1}
raises(ValueError, lambda: l.parameter_value((0, 0), t))
开发者ID:Lenqth,项目名称:sympy,代码行数:6,代码来源:test_line.py
示例13: 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
示例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_intersection_2d
def test_intersection_2d():
p1 = Point(0, 0)
p2 = Point(1, 1)
p3 = Point(x1, x1)
p4 = Point(y1, y1)
l1 = Line(p1, p2)
l3 = Line(Point(0, 0), Point(3, 4))
r1 = Ray(Point(1, 1), Point(2, 2))
r2 = Ray(Point(0, 0), Point(3, 4))
r4 = Ray(p1, p2)
r6 = Ray(Point(0, 1), Point(1, 2))
r7 = Ray(Point(0.5, 0.5), Point(1, 1))
s1 = Segment(p1, p2)
s2 = Segment(Point(0.25, 0.25), Point(0.5, 0.5))
s3 = Segment(Point(0, 0), Point(3, 4))
assert intersection(l1, p1) == [p1]
assert intersection(l1, Point(x1, 1 + x1)) == []
assert intersection(l1, Line(p3, p4)) in [[l1], [Line(p3, p4)]]
assert intersection(l1, l1.parallel_line(Point(x1, 1 + x1))) == []
assert intersection(l3, l3) == [l3]
assert intersection(l3, r2) == [r2]
assert intersection(l3, s3) == [s3]
assert intersection(s3, l3) == [s3]
assert intersection(Segment(Point(-10, 10), Point(10, 10)), Segment(Point(-5, -5), Point(-5, 5))) == []
assert intersection(r2, l3) == [r2]
assert intersection(r1, Ray(Point(2, 2), Point(0, 0))) == [Segment(Point(1, 1), Point(2, 2))]
assert intersection(r1, Ray(Point(1, 1), Point(-1, -1))) == [Point(1, 1)]
assert intersection(r1, Segment(Point(0, 0), Point(2, 2))) == [Segment(Point(1, 1), Point(2, 2))]
assert r4.intersection(s2) == [s2]
assert r4.intersection(Segment(Point(2, 3), Point(3, 4))) == []
assert r4.intersection(Segment(Point(-1, -1), Point(0.5, 0.5))) == [Segment(p1, Point(0.5, 0.5))]
assert r4.intersection(Ray(p2, p1)) == [s1]
assert Ray(p2, p1).intersection(r6) == []
assert r4.intersection(r7) == r7.intersection(r4) == [r7]
assert Ray3D((0, 0), (3, 0)).intersection(Ray3D((1, 0), (3, 0))) == [Ray3D((1, 0), (3, 0))]
assert Ray3D((1, 0), (3, 0)).intersection(Ray3D((0, 0), (3, 0))) == [Ray3D((1, 0), (3, 0))]
assert Ray(Point(0, 0), Point(0, 4)).intersection(Ray(Point(0, 1), Point(0, -1))) == \
[Segment(Point(0, 0), Point(0, 1))]
assert Segment3D((0, 0), (3, 0)).intersection(
Segment3D((1, 0), (2, 0))) == [Segment3D((1, 0), (2, 0))]
assert Segment3D((1, 0), (2, 0)).intersection(
Segment3D((0, 0), (3, 0))) == [Segment3D((1, 0), (2, 0))]
assert Segment3D((0, 0), (3, 0)).intersection(
Segment3D((3, 0), (4, 0))) == [Point3D((3, 0))]
assert Segment3D((0, 0), (3, 0)).intersection(
Segment3D((2, 0), (5, 0))) == [Segment3D((2, 0), (3, 0))]
assert Segment3D((0, 0), (3, 0)).intersection(
Segment3D((-2, 0), (1, 0))) == [Segment3D((0, 0), (1, 0))]
assert Segment3D((0, 0), (3, 0)).intersection(
Segment3D((-2, 0), (0, 0))) == [Point3D(0, 0)]
assert s1.intersection(Segment(Point(1, 1), Point(2, 2))) == [Point(1, 1)]
assert s1.intersection(Segment(Point(0.5, 0.5), Point(1.5, 1.5))) == [Segment(Point(0.5, 0.5), p2)]
assert s1.intersection(Segment(Point(4, 4), Point(5, 5))) == []
assert s1.intersection(Segment(Point(-1, -1), p1)) == [p1]
assert s1.intersection(Segment(Point(-1, -1), Point(0.5, 0.5))) == [Segment(p1, Point(0.5, 0.5))]
assert s1.intersection(Line(Point(1, 0), Point(2, 1))) == []
assert s1.intersection(s2) == [s2]
assert s2.intersection(s1) == [s2]
assert asa(120, 8, 52) == \
Triangle(
Point(0, 0),
Point(8, 0),
Point(-4 * cos(19 * pi / 90) / sin(2 * pi / 45),
4 * sqrt(3) * cos(19 * pi / 90) / sin(2 * pi / 45)))
assert Line((0, 0), (1, 1)).intersection(Ray((1, 0), (1, 2))) == [Point(1, 1)]
assert Line((0, 0), (1, 1)).intersection(Segment((1, 0), (1, 2))) == [Point(1, 1)]
assert Ray((0, 0), (1, 1)).intersection(Ray((1, 0), (1, 2))) == [Point(1, 1)]
assert Ray((0, 0), (1, 1)).intersection(Segment((1, 0), (1, 2))) == [Point(1, 1)]
assert Ray((0, 0), (10, 10)).contains(Segment((1, 1), (2, 2))) is True
assert Segment((1, 1), (2, 2)) in Line((0, 0), (10, 10))
# 16628 - this should be fast
p0 = Point2D(S(249)/5, S(497999)/10000)
p1 = Point2D((-58977084786*sqrt(405639795226) + 2030690077184193 +
20112207807*sqrt(630547164901) + 99600*sqrt(255775022850776494562626))
/(2000*sqrt(255775022850776494562626) + 1991998000*sqrt(405639795226)
+ 1991998000*sqrt(630547164901) + 1622561172902000),
(-498000*sqrt(255775022850776494562626) - 995999*sqrt(630547164901) +
90004251917891999 +
496005510002*sqrt(405639795226))/(10000*sqrt(255775022850776494562626)
+ 9959990000*sqrt(405639795226) + 9959990000*sqrt(630547164901) +
8112805864510000))
p2 = Point2D(S(497)/10, -S(497)/10)
p3 = Point2D(-S(497)/10, -S(497)/10)
l = Line(p0, p1)
s = Segment(p2, p3)
n = (-52673223862*sqrt(405639795226) - 15764156209307469 -
9803028531*sqrt(630547164901) +
33200*sqrt(255775022850776494562626))
d = sqrt(405639795226) + 315274080450 + 498000*sqrt(
630547164901) + sqrt(255775022850776494562626)
assert intersection(l, s) == [
Point2D(n/d*S(3)/2000, -S(497)/10)]
开发者ID:bjodah,项目名称:sympy,代码行数:100,代码来源:test_line.py
注:本文中的sympy.geometry.Line类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论