import numpy as np
import math
#defining the K matrix with parameters fx=fy=1, cx=cy=0 and skew factor 0
#Here fx,fy are focal lengths of the camera along the x and y axes and cx,cy are the principal point's coordinates
intrinsic = np.array([[1, 0, 0],[0, 1, 0]])
#defining a rotation matrix along the y-dimension
def rotation_matrix_y(angle):
rot_angle=np.radians(angle)
R = np.array([[math.cos(rot_angle),0,math.sin(rot_angle)],[0,1,0],[-math.sin(rot_angle),0,math.cos(rot_angle)]])
return R
#here we are taking 4 2D images oriented at different angles (0, 10, 20 etc.)
R=rotation_matrix_y(0)
R1=rotation_matrix_y(10)
R2=rotation_matrix_y(20)
R3=rotation_matrix_y(30)
#mutliplying the intrinsic matrix with each of the 2D images
R=np.dot(intrinsic,R)
R1=np.dot(intrinsic,R1)
R2=np.dot(intrinsic,R2)
R3=np.dot(intrinsic,R3)
#creating a 3Dpoints matrix vertically stacking a,b,c on top of each other
threeDpoints=np.vstack([a,b,c])
#creating a trans matrix which is the product of K and R with dimension 2F*3 where F=4 by vertically stacking R, R1, R2, R3 on top of each other
trans=np.vstack([R,R1,R2,R3])
print(np.shape(trans))
#computing new 2D points for the spherical structure
new2Dpoints=np.dot(trans,threeDpoints)
#Pair of x,y dimension of 1st 2D image
a1=new2Dpoints[0]
b1=new2Dpoints[1]
#Pair of x,y dimensions of 2nd 2D image
c1=new2Dpoints[2]
d1=new2Dpoints[3]
#Pair of x,y dimension of 3rd 2D image
e1=new2Dpoints[4]
f1=new2Dpoints[5]
#Pair of x,y dimension of 4th 2D image
g1=new2Dpoints[6]
h1=new2Dpoints[7]
fig = plt.figure(figsize=(15,25))
ax = fig.add_subplot(411)
#Plotting 2D image with zero degree rotation
ax.set_title('2D image with zero degree rotation')
ax.scatter(a1,b1, marker='*')
ax1=fig.add_subplot(412)
#Plotting 2D image with ten degree rotation
ax1.set_title('2D image with ten degree rotation')
ax1.scatter(c1,d1,marker='*')
ax2=fig.add_subplot(413)
#Plotting 2D image with twenty degree rotation
ax2.set_title('2D image with twenty degree rotation')
ax2.scatter(e1,f1,marker='*')
ax3=fig.add_subplot(414)
#Plotting 2D image with thirty degree rotation
ax3.set_title('2D image with thirty degree rotation')
ax3.scatter(g1,h1,marker='*')