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


Python Line.intersection方法代码示例

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


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

示例1: cast

# 需要导入模块: from sympy.geometry import Line [as 别名]
# 或者: from sympy.geometry.Line import intersection [as 别名]
 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,代码行数:32,代码来源:mirr0r.py

示例2: test_symbolic_intersect

# 需要导入模块: from sympy.geometry import Line [as 别名]
# 或者: from sympy.geometry.Line import intersection [as 别名]
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,代码行数:12,代码来源:test_line.py

示例3: intersection_of_vector_with_triangle

# 需要导入模块: from sympy.geometry import Line [as 别名]
# 或者: from sympy.geometry.Line import intersection [as 别名]
 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,代码行数:13,代码来源:mirr0r.py

示例4: generate_map

# 需要导入模块: from sympy.geometry import Line [as 别名]
# 或者: from sympy.geometry.Line import intersection [as 别名]
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,代码行数:103,代码来源:map.py


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