美文网首页每天学一点新知识
使用python实现图形的变换_线性代数_day22

使用python实现图形的变换_线性代数_day22

作者: FANDX | 来源:发表于2020-02-05 21:47 被阅读0次
    import matplotlib.pyplot as plt
    import numpy as np
    from Matrix import Matrix
    from playLA.Vector import Vector
    
    if __name__ == '__main__':
        points = [[0, 0], [0, 5], [3, 5], [3, 4], [1, 4],
                  [1, 3], [2, 3], [2, 2], [1, 2], [1, 0]]
    
        x = [point[0] for point in points]
        y = [point[1] for point in points]
    
        # 设置一个正方形的窗口
        plt.figure(figsize=(5, 5))
        plt.xlim(-10, 10)
        plt.ylim(-10, 10)
    
        # 使用matplotlib进行绘制
        plt.plot(x, y)
        # plt.show()
    
        # 创建一个矩阵
        # P = np.array(points)
        P = Matrix(points)
    
        # 进行控制矩阵的值,来进行不同的变换
        T = Matrix([[2, 0], [0, 1.5]])
        # T = np.array([[2, 0], [0, 1.5]])
    
        # 图形旋转变换
        theta = np.math.pi / 3
        T = Matrix([[np.math.cos(theta), np.math.sin(theta)], [-np.math.sin(theta)], np.math.cos(theta)])
    
    
        P2 = T.dot(P.T())
        # print([P2.col_vector(i)[1] for i in range(P2.col_num())])
        plt.plot([P2.col_vector(i)[0] for i in range(P2.col_num())],
                 [P2.col_vector(i)[1] for i in range(P2.col_num())])
    
        plt.show()
    
    

    相关文章

      网友评论

        本文标题:使用python实现图形的变换_线性代数_day22

        本文链接:https://www.haomeiwen.com/subject/bwuexhtx.html