particlescv2.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:python-opencv2 作者: bunkahle 项目源码 文件源码
def Draw(self, display):
        if not self.hascontacts:
            # W = display.get_width()
            # H = display.get_height()
            (W, H) = display.shape[1], display.shape[0]
            edgecontacts = []  # Where the line touches the screen edges

            if self.normal[0] == 0.0:
                edgecontacts = [[0, self.pos[1]], [W, self.pos[1]]]

            elif self.normal[1] == 0.0:
                edgecontacts = [[self.pos[0], 0], [self.pos[0], H]]

            else:
                pdotn = (self.pos[0] * self.normal[0]) + (self.pos[1] * self.normal[1])
                reciprocaln0 = (1.0 / self.normal[0])
                reciprocaln1 = (1.0 / self.normal[1])

                # Left-hand side of the screen
                pointl = [0, 0]
                pointl[1] = pdotn * reciprocaln1
                if (pointl[1] >= 0) and (pointl[1] <= H):
                    edgecontacts.append(pointl)

                # Top of the screen
                pointt = [0, 0]
                pointt[0] = pdotn * reciprocaln0
                if (pointt[0] >= 0) and (pointt[0] <= W):
                    edgecontacts.append(pointt)

                # Right-hand side of the screen
                pointr = [W, 0]
                pointr[1] = (pdotn - (W * self.normal[0])) * reciprocaln1
                if (pointr[1] >= 0) and (pointr[1] <= H):
                    edgecontacts.append(pointr)

                # Bottom of the screen
                pointb = [0, H]
                pointb[0] = (pdotn - (H * self.normal[1])) * reciprocaln0
                if (pointb[0] >= 0) and (pointb[0] <= W):
                    edgecontacts.append(pointb)

            self.edgecontacts = edgecontacts
            self.hascontacts = True

        # pygame.draw.aalines(display, self.colour, True, self.edgecontacts)
        # cv.Line(display, (int(self.edgecontacts[0][0]), int(self.edgecontacts[0][1])), (int(self.edgecontacts[1][0]), int(self.edgecontacts[1][1])), self.colour, lineType=cv.CV_AA)
        cv2.line(display, (int(self.edgecontacts[0][0]), int(self.edgecontacts[0][1])), (int(self.edgecontacts[1][0]), int(self.edgecontacts[1][1])), self.colour, lineType=cv2.CV_AA)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号