Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

给我一个可以快速初步求解碰撞的aabb

  1. User

    给我一个可以快速初步求解碰撞的aabb

  2. Assistant

    框架

    以下是一个简单的AABB(轴对齐的边界框)碰撞检测框架,它可以快速地初步检测是否存在碰撞:

    class AABB:
        def __init__(self, left, right, bottom, top):
            self.left = left
            self.right = right
            self.bottom = bottom
            self.top = top
    
        def collides_with(self, other):
            if self.right < other.left or self.left > other.right:
                return False
            if self.top < other.bottom or self.bottom > other.top:
                return False
            return True
    

    该类表示一个AABB,它由其左、右、下和上边界定义。该类具有一个名为“collides_with”的方法,该方法接受另一个AABB作为参数,并确定两个AABB是否重叠。

    在“collides_with”方法中,我们检查两个AABB是否相交。否则,我们返回False以指示碰撞不存在,否则我们返回True。

    使用方法:

    aabb1 = AABB(0, 10, 0, 10)
    aabb2 = AABB(5, 15, 5, 15)
    
    if aabb1.collides_with(aabb2):
        print("Collision detected!")
    else:
        print("No collision detected.")
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.