コード例 #1
0
ファイル: poly.py プロジェクト: fabiommendes/smallshapes
    def shadow(self, n):
        '''Retorna as coordenadas da sombra na direção n dada.
        Assume n normalizado.'''

        r = self.radius
        center_pos = dot(self.pos, n)
        return (center_pos - r, center_pos + r)
コード例 #2
0
ファイル: poly.py プロジェクト: fabiommendes/smallshapes
    def shadow(self, n):
        '''Retorna as coordenadas da sombra na direção n dada.
        Assume n normalizado.'''

        r = self.radius
        center_pos = dot(self.pos, n)
        return (center_pos - r, center_pos + r)
コード例 #3
0
ファイル: poly.py プロジェクト: gutioliveira/FGAme
def collision_poly(A, B, directions=None, collision_class=Collision):
    """
    Collision detection using SAT.
    """

    # List of directions from normals
    if directions is None:
        if A.num_normals + B.num_normals < 9:
            directions = A.get_normals() + B.get_normals()
        else:
            directions = DEFAULT_DIRECTIONS

    # Test overlap in all considered directions and picks the smaller
    # penetration
    min_overlap = float('inf')
    norm = None
    for u in directions:
        A_coords = [dot(pt, u) for pt in A.vertices]
        B_coords = [dot(pt, u) for pt in B.vertices]
        Amax, Amin = max(A_coords), min(A_coords)
        Bmax, Bmin = max(B_coords), min(B_coords)
        minmax, maxmin = min(Amax, Bmax), max(Amin, Bmin)
        overlap = minmax - maxmin
        if overlap < 0:
            return None
        elif overlap < min_overlap:
            min_overlap = overlap
            norm = u

    # Finds the correct direction for the normal
    if dot(A.pos, norm) > dot(B.pos, norm):
        norm = -norm

    # Computes the clipped polygon: collision happens at its center point.
    try:
        clipped = clip(A.vertices, B.vertices)
        col_pt = center_of_mass(clipped)
    except ValueError:
        return None

    if area(clipped) == 0:
        return None

    return collision_class(A, B, pos=col_pt, normal=norm, delta=min_overlap)
コード例 #4
0
ファイル: poly.py プロジェクト: arpit-dhankar/pythonProject
def collision_poly(A, B, directions=None, collision_class=Collision):
    """
    Collision detection using SAT.
    """

    # List of directions from normals
    if directions is None:
        if A.num_normals + B.num_normals < 9:
            directions = A.get_normals() + B.get_normals()
        else:
            directions = DEFAULT_DIRECTIONS

    # Test overlap in all considered directions and picks the smaller
    # penetration
    min_overlap = float('inf')
    norm = None
    for u in directions:
        A_coords = [dot(pt, u) for pt in A.vertices]
        B_coords = [dot(pt, u) for pt in B.vertices]
        Amax, Amin = max(A_coords), min(A_coords)
        Bmax, Bmin = max(B_coords), min(B_coords)
        minmax, maxmin = min(Amax, Bmax), max(Amin, Bmin)
        overlap = minmax - maxmin
        if overlap < 0:
            return None
        elif overlap < min_overlap:
            min_overlap = overlap
            norm = u

    # Finds the correct direction for the normal
    if dot(A.pos, norm) > dot(B.pos, norm):
        norm = -norm

    # Computes the clipped polygon: collision happens at its center point.
    try:
        clipped = clip(A.vertices, B.vertices)
        col_pt = center_of_mass(clipped)
    except ValueError:
        return None

    if area(clipped) == 0:
        return None

    return collision_class(A, B, pos=col_pt, normal=norm, delta=min_overlap)
コード例 #5
0
ファイル: circle.py プロジェクト: arpit-dhankar/pythonProject
 def shadow(self, n):
     p0 = dot(self.pos, n)
     r = self._radius
     return p0 - r, p0 + r
コード例 #6
0
ファイル: line.py プロジェクト: fabiommendes/smallshapes
 def sat_shadow(self, n):
     if abs(dot(self.tangent(), n)) < 1e-6:
         p = dot(self.p1, n)
         return p, p
     else:
         return [-Inf, Inf]
コード例 #7
0
 def sat_shadow(self, n):
     if abs(dot(self.tangent(), n)) < 1e-6:
         p = dot(self.p1, n)
         return p, p
     else:
         return [-Inf, Inf]
コード例 #8
0
ファイル: aabb.py プロジェクト: arpit-dhankar/pythonProject
 def SAT_shadows(self, n):
     points = [dot(n, p) for p in self.vertices]
     return min(points), max(points)
コード例 #9
0
    def shadow(self, n):
        '''Retorna as coordenadas da sombra na direção n dada.
        Assume n normalizado.'''

        points = [dot(n, p) for p in self.vertices]
        return min(points), max(points)
コード例 #10
0
ファイル: aabb.py プロジェクト: fabiommendes/smallshapes
 def SAT_shadows(self, n):
     points = [dot(n, p) for p in self.vertices]
     return min(points), max(points)