Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 线对线与pygame'相交;s倒y轴_Python_Python 3.x_Pygame - Fatal编程技术网

Python 线对线与pygame'相交;s倒y轴

Python 线对线与pygame'相交;s倒y轴,python,python-3.x,pygame,Python,Python 3.x,Pygame,x1 = other.pos1[0] y1 = other.pos1[1] x2 = other.pos2[0] y2 = other.pos2[1] x3 = self.pos1[0] y3 = self.pos1[1] x4 = self.pos2[0] y4 = self.pos2[1] den = (x1 - x2) * (y3 - y4) - (y1 *

        x1 = other.pos1[0]
        y1 = other.pos1[1]
        x2 = other.pos2[0]
        y2 = other.pos2[1]

        x3 = self.pos1[0]
        y3 = self.pos1[1]
        x4 = self.pos2[0]
        y4 = self.pos2[1]

        den = (x1 - x2) * (y3 - y4) - (y1 * y2 * (x3 - x4))

        if den == 0:
            return

        t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den

        u = -(((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3))) / den

        if t > 0 and t < 1 and u > 0:
            point = (x3 + u * (x4 - x3), y3 + u * (y4 - y3))

            pygame.gfxdraw.filled_circle(surface, point[0], point[1], 3, (255, 0, 0))

            return point

        else:
            return

        x1 = other.pos1[0]
        y1 = other.pos1[1]
        x2 = other.pos2[0]
        y2 = other.pos2[1]

        x3 = self.pos1[0]
        y3 = self.pos1[1]
        x4 = self.pos2[0]
        y4 = self.pos2[1]

        den = (x1 - x2) * (y3 - y4) - (y1 * y2 * (x3 - x4))

        if den == 0:
            return

        t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den

        u = -(((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3))) / den

        if t > 0 and t < 1 and u > 0:
            point = (x3 + u * (x4 - x3), y3 + u * (y4 - y3))

            pygame.gfxdraw.filled_circle(surface, point[0], point[1], 3, (255, 0, 0))

            return point

        else:
            return
我曾尝试在我的代码中实现此方法,但没有成功,我确实认为问题在于pygame中的y轴反转,还是有其他东西隐藏在我的视线之下?有什么建议吗

        x1 = other.pos1[0]
        y1 = other.pos1[1]
        x2 = other.pos2[0]
        y2 = other.pos2[1]

        x3 = self.pos1[0]
        y3 = self.pos1[1]
        x4 = self.pos2[0]
        y4 = self.pos2[1]

        den = (x1 - x2) * (y3 - y4) - (y1 * y2 * (x3 - x4))

        if den == 0:
            return

        t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den

        u = -(((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3))) / den

        if t > 0 and t < 1 and u > 0:
            point = (x3 + u * (x4 - x3), y3 + u * (y4 - y3))

            pygame.gfxdraw.filled_circle(surface, point[0], point[1], 3, (255, 0, 0))

            return point

        else:
            return
这是我的密码:

        x1 = other.pos1[0]
        y1 = other.pos1[1]
        x2 = other.pos2[0]
        y2 = other.pos2[1]

        x3 = self.pos1[0]
        y3 = self.pos1[1]
        x4 = self.pos2[0]
        y4 = self.pos2[1]

        den = (x1 - x2) * (y3 - y4) - (y1 * y2 * (x3 - x4))

        if den == 0:
            return

        t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den

        u = -(((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3))) / den

        if t > 0 and t < 1 and u > 0:
            point = (x3 + u * (x4 - x3), y3 + u * (y4 - y3))

            pygame.gfxdraw.filled_circle(surface, point[0], point[1], 3, (255, 0, 0))

            return point

        else:
            return
x1=other.pos1[0]
y1=其他位置1[1]
x2=其他.pos2[0]
y2=其他。位置2[1]
x3=self.pos1[0]
y3=self.pos1[1]
x4=self.pos2[0]
y4=self.pos2[1]
den=(x1-x2)*(y3-y4)-(y1*y2*(x3-x4))
如果den==0:
返回
t=((x1-x3)*(y3-y4)-(y1-y3)*(x3-x4))/den
u=-((x1-x2)*(y1-y3)-(y1-y2)*(x1-x3))/den
如果t>0且t<1且u>0:
点=(x3+u*(x4-x3),y3+u*(y4-y3))
pygame.gfxdraw.filled_圆(曲面,点[0],点[1],3,(255,0,0))
返回点
其他:
返回
的分母由以下公式计算:

        x1 = other.pos1[0]
        y1 = other.pos1[1]
        x2 = other.pos2[0]
        y2 = other.pos2[1]

        x3 = self.pos1[0]
        y3 = self.pos1[1]
        x4 = self.pos2[0]
        y4 = self.pos2[1]

        den = (x1 - x2) * (y3 - y4) - (y1 * y2 * (x3 - x4))

        if den == 0:
            return

        t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den

        u = -(((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3))) / den

        if t > 0 and t < 1 and u > 0:
            point = (x3 + u * (x4 - x3), y3 + u * (y4 - y3))

            pygame.gfxdraw.filled_circle(surface, point[0], point[1], 3, (255, 0, 0))

            return point

        else:
            return
所以下面的表达是错误的:

        x1 = other.pos1[0]
        y1 = other.pos1[1]
        x2 = other.pos2[0]
        y2 = other.pos2[1]

        x3 = self.pos1[0]
        y3 = self.pos1[1]
        x4 = self.pos2[0]
        y4 = self.pos2[1]

        den = (x1 - x2) * (y3 - y4) - (y1 * y2 * (x3 - x4))

        if den == 0:
            return

        t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den

        u = -(((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3))) / den

        if t > 0 and t < 1 and u > 0:
            point = (x3 + u * (x4 - x3), y3 + u * (y4 - y3))

            pygame.gfxdraw.filled_circle(surface, point[0], point[1], 3, (255, 0, 0))

            return point

        else:
            return
它必须是:

        x1 = other.pos1[0]
        y1 = other.pos1[1]
        x2 = other.pos2[0]
        y2 = other.pos2[1]

        x3 = self.pos1[0]
        y3 = self.pos1[1]
        x4 = self.pos2[0]
        y4 = self.pos2[1]

        den = (x1 - x2) * (y3 - y4) - (y1 * y2 * (x3 - x4))

        if den == 0:
            return

        t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den

        u = -(((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3))) / den

        if t > 0 and t < 1 and u > 0:
            point = (x3 + u * (x4 - x3), y3 + u * (y4 - y3))

            pygame.gfxdraw.filled_circle(surface, point[0], point[1], 3, (255, 0, 0))

            return point

        else:
            return
den=(x1-x2)*(y3-y4)-(y1-y2)*(x3-x4))

(x1-x2)*(y3-y4)-(y1*y2*(x3-x4))
必须是
(x1-x2)*(y3-y4)-(y1-y2)*(x3-x4))
哦,我的天啊,非常感谢你,我现在感觉很傻。像这样的错误发生在我们所有人身上。