效果
按下“c”展示不同的三维图形的一点、二点、三点透视图,需注意展示的是三个txt文件中的图形。 按下”q”退出
三维图形文件
边-三棱锥.txt
0,1
0,2
0,3
1,2
1,3
2,3
边-长方体.txt
0,1
0,3
0,4
1,2
1,5
2,3
2,6
3,7
4,5
4,7
5,6
6,7
边-正方体.txt
0,1
0,3
0,4
1,2
1,5
2,3
2,6
3,7
4,5
4,7
5,6
6,7
点-三棱锥.txt
2,3,5
4,2,0
3,6,0
1,4,0
点-长方体.txt
0,0,0
1,0,0
1,1,0
0,1,0
0,0,3
1,0,3
1,1,3
0,1,3
点-正方体.txt
0,0,0
1,0,0
1,1,0
0,1,0
0,0,1
1,0,1
1,1,1
0,1,1
代码
import cv2
import numpy as np
import time
from math import*
img = np.zeros((800, 1020, 3), np.uint8)#背景
cv2.namedWindow('src')
filestr=["三棱锥","正方体","长方体"]
growthFactor=[20,100,40]
#三维透视变换:一点、两点、三点
def PerspectiveP(verticies,l,m,n,p,q,r,o=0,a=0):
global choice,growthFactor
#平移变换矩阵
TsM=np.array([[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[l,m,n,1] ], dtype = np.float)
#旋转变换矩阵
RyM=np.array([[cos(o),0,-sin(o),0],
[