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


Python Vector.perp方法代码示例

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


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

示例1: point_on_line

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import perp [as 别名]
    def point_on_line(point, line):
        if line.degenerate:
            return Collisions.points_nearby(point, line.head, 0)

        u = line.head - line.tail
        v = point - line.tail

        if u == v:
            return True
        if Vector.perp(u, v) != 0:
            return False

        try:
            k = v.x // u.x
        except ZeroDivisionError:
            k = v.y // u.y

        return k == 0
开发者ID:kxgames,项目名称:PlainPeopleEater,代码行数:20,代码来源:collisions.py

示例2: lines_touching

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import perp [as 别名]
    def lines_touching(first, second):

        # Returns true if a degenerate, collinear point is on a line.
        def within_bounds(point, line):
            start, end = line.points

            if start.x == end.x:
                if point.x <= start.x and point.x >= end.x:
                    return True
                if point.x >= start.x and point.x <= end.x:
                    return True
            else:
                if point.x <= start.x and point.x >= end.x:
                    return True
                if point.x >= start.x and point.x <= end.x:
                    return True

            return False

        u = first.direction
        v = second.direction

        w = first.tail - second.tail
        q = first.head - second.tail

        denom = float(Vector.perp(u, v))

        # Parallel, maybe coincident
        if denom == 0:
            # Check for coincidence
            if Vector.perp(u, w) != 0 or Vector.perp(v, w) != 0:
                return False

            # Check for degeneracy
            elif first.degenerate and second.degenerate:
                return first.head == second.head

            elif first.degenerate:
                return within_bounds(first.head, second)

            elif second.degenerate:
                return within_bounds(second.head, second)

            # Check for segment overlap
            else:
                try:
                    s = q.x / v.x
                    t = w.x / v.x
                except ZeroDivisionError:
                    s = q.y / v.y
                    t = w.y / v.y

                if s > t:
                    s, t = t, s

                if s > 1 or t < 0:
                    return False

                return True

        # Skew: maybe intersecting.
        else:

            s = Vector.perp(v, w) / denom
            if s < 0 or s > 1:
                return False

            t = Vector.perp(u, w) / denom
            if t < 0 or t > 1:
                return False

            return True
开发者ID:kxgames,项目名称:PlainPeopleEater,代码行数:74,代码来源:collisions.py


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