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


Python Vector.distance_between方法代码示例

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


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

示例1: collide

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import distance_between [as 别名]
    def collide(self, p1, p2):
        """Collission detection and handling method"""
        distance = Vector.distance_between(p1.pos, p2.pos)
        if distance < (p1.size + p2.size):

            angle = Vector.angle_between(p1.pos, p2.pos) + 0.5 * math.pi
            total_mass = p1.mass + p2.mass

            p1.direction = Vector(p1.direction.length * (p1.mass - p2.mass) / total_mass, p1.direction.angle) \
                + Vector(2 * p2.direction.length * p2.mass / total_mass, angle)
            p2.direction = Vector(p2.direction.length * (p2.mass - p1.mass) / total_mass, p2.direction.angle) \
                + Vector(2 * p1.direction.length * p1.mass / total_mass, angle)
            p1.direction.length *= self.elasticity
            p2.direction.length *= self.elasticity

            tangent = Vector.angle_between(p1.pos, p2.pos)
            # bounce on tangent
            #p1.direction.bounce(2 * tangent)
            #p2.direction.bounce(2 * tangent)
            # change speed
            #(p1.direction.length, p2.direction.length) = (p2.direction.length, p1.direction.length) 
            #avoid sticky problem
            angle = 0.5 * math.pi + tangent
            overlap = 0.5 * (p1.size + p2.size - distance + 1)
            p1.pos.x += math.sin(angle) + overlap
            p1.pos.y -= math.cos(angle) + overlap
            p2.pos.x -= math.sin(angle) + overlap
            p2.pos.y += math.cos(angle) + overlap
开发者ID:gunny26,项目名称:pygame,代码行数:30,代码来源:Particle.py

示例2: find_selected

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import distance_between [as 别名]
 def find_selected(self, pos):
     for particle in self.particles:
         if abs(Vector.distance_between(particle.pos, pos)) <= particle.size:
             particle.direction = Vector(10, math.pi)
开发者ID:gunny26,项目名称:pygame,代码行数:6,代码来源:Particle.py


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