Sympy模块正在运行

2024-10-01 00:27:18 发布

您现在位置:Python中文网/ 问答频道 /正文

给定一个长度列表和一个点(x,y),我想找出一个以(a,b)为中心半径为25的圆是否与任何直线相交。这些线都以点(x,y)为中心,在长度列表中具有相应索引的长度,并且所有相邻的线都具有相同的“角度”(所有线在角度方面是等距的)

我试过使用Sympy,但不幸的是,它非常慢。以前,我的游戏是50-60帧/秒,但现在是0.3-0.5帧/秒。不幸的是,我不知道是什么导致了所有的滞后,所以我将展示整个函数:

# the point where the lines are centered around is represented by pl.x,pl.y
#sympy is imported as sym
def shotcheck(self,lines):
        x,y = self.x,self.y #x and y represent the center of the circle
        c = sym.Circle(sym.Point(x,y,evaluate=False),25)
        diff = 2*math.pi/len(lines)
        direction = math.acos((x-pl.x)/hypot((pl.x-x),(pl.y-y)))
        if y < pl.y:
            direction = 2*math.pi-direction
        dfind = direction -0.005
        lowline,highline = math.floor(dfind/diff),math.ceil(dfind/diff)
        lline = sym.Segment(sym.Point(pl.x,pl.y,evaluate=False),sym.Point(pl.x+lines[lowline]*math.cos(a*lowline+0.005),pl.y+lines[lowline]*math.sin(a*lowline+0.005),evaluate=False))
        hline = sym.Segment(sym.Point(pl.x,pl.y,evaluate=False),sym.Point(pl.x+lines[highline]*math.cos(a*highline+0.005),pl.y+lines[highline]*math.sin(a*highline+0.005),evaluate=False))
        if len(sym.intersection(c,lline)) == 0 and len(sym.intersection(c,hline)) == 0:
            return False
        else:
            return True #Returns True if intersecting

我本以为这会运行得很快,但它完全降低了fps。 我能做些什么来解决这个问题? 编辑:我发现滞后是由对称交叉口. 我怎样才能让它更快?你知道吗


Tags: theselffalselenifdiffmathpoint