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


Python Geometry.intersect_seg方法代码示例

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


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

示例1: _collides

# 需要导入模块: import Geometry [as 别名]
# 或者: from Geometry import intersect_seg [as 别名]
        def _collides(x1, y1, x2, y2, x3, y3, x4, y4):
            i = Geometry.intersect_seg(x1, y1, x2, y2, x3, y3, x4, y4)

            if i is not None:
                if y2 == y1:
                    n = 0 + math.pi / 2.0
                else:
                    n = math.atan((x2 - x1) / (y2 - y1)) + math.pi / 2.0

                if y4 == y3:
                    i1 = 0 - n
                else:
                    i1 = math.atan((x4 - x3) / (y4 - y3)) - n

                # i1 = math.pi / 2 - Geometry.angle(x1, y1, x2, y2, x3, y3, x4, y4)

                if self.indice == p.last_indice:
                    n1 = self.indice
                    n2 = p.last_indice
                else:
                    n1 = p.last_indice
                    n2 = self.indice

                sini2 = math.sin(i1) * n1 / n2
                if math.fabs(sini2) <= 1:
                    i2 = math.asin(sini2)
                    # print i2 / math.pi * 360

                    c = math.cos(-i1 + math.pi + i2)
                    s = math.sin(-i1 + math.pi + i2)
                    vx = p.vx * c - p.vy * s
                    vy = p.vx * s + p.vy * c
                    p.vx = vx
                    p.vy = vy

                    print 180 * i1 / math.pi, 180 * i2 / math.pi

                    if not p in self.inside:
                        self.inside[p] = True
                    else:
                        self.inside[p] = not self.inside[p]
                    if not self.inside[p]:
                        p.last_indice = self.indice
                else:
                    # print 'coucou'
                    c = math.cos(-2 * i1)
                    s = math.sin(-2 * i1)
                    vx = p.vx * c - p.vy * s
                    vy = p.vx * s + p.vy * c
                    # p.vx = vx
                    # p.vy = vy

                return True
            return False
开发者ID:AnisB,项目名称:CosmicBeam,代码行数:56,代码来源:Medium.py

示例2: collides

# 需要导入模块: import Geometry [as 别名]
# 或者: from Geometry import intersect_seg [as 别名]
	def collides(self,p):
		#if Geometry.intersec_seg(self,{'x':p}):
		#try:
		#	if Geometry.intersect(self.x1,self.y1,self.x2,self.y2,p.x,p.y,p.old_x,p.old_y):
		#		p.kill()
		#except ZeroDivisionError:
		#	pass
		i = Geometry.intersect_seg(self.x1,self.y1,self.x2,self.y2,p.x,p.y,p.old_x,p.old_y)
		#if i is not None: p.kill()
		#if i is not None: p.engine.rem_part(p)
		if i is not None:
			if self.is_a_barrier:
				p.kill()
			else:
				#print "Mirror intersection!! ", p.id
				# ix,iy = i
				# p.x = ix
				# p.y = iy
				# p.x = p.old_x
				# p.y = p.old_y
				p.x = (i[0]*9+p.old_x)/10.0
				p.y = (i[1]*9+p.old_y)/10.0
				p.vx, p.vy = Geometry.reflect(self.x2-self.x1, self.y2-self.y1, p.vx, p.vy)
开发者ID:AnisB,项目名称:CosmicBeam,代码行数:25,代码来源:Mirror.py


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