我想将同一3D平面ax + by + cz = d中的多个点旋转到2D平面xy。我能够旋转飞机,但无法完全旋转。 如您在这张图片中所看到的(红色点是xy平面上的圆,黄色是我想要旋转的圆,红色是我能够旋转的圆。
我试图创建旋转矩阵,计算平面(a,b,c)的法线向量,然后计算this rotation matrix! ,通过垂直于(a,b,c)和(0,0,1)的向量旋转平面。
def grid2d_perplane(plane): # creates a 2d grid in a plane ax+by+cz=d by calculating a,b,c,d
p1 = copy.copy(plane[0])
p2 = copy.copy(plane[13])
p3 = copy.copy(plane[30])
# These two vectors are in the plane
v1 = p3 - p1
v2 = p2 - p1
# the cross product is a vector normal to the plane
cp = np.cross(v1, v2)
cp /= np.sqrt(cp[0]*cp[0] + cp[1]*cp[1] +cp[2]*cp[2])
a, b, c = cp
# This evaluates a * x3 + b * y3 + c * z3 which equals d
d = np.dot(cp, p3)
maxx = np.max(plane[:,0:1])
maxy = np.max(plane[:,1:2])
minx = np.min(plane[:,0:1])
miny = np.min(plane[:,1:2])
x = np.arange(minx*2,maxx*2,0.25)
y = np.arange(miny*2,maxy*2,0.25)
xx,yy= np.meshgrid(x,y)
zz = (d - a * xx - b * yy) / c
return xx, yy, zz, a , b , c, d
def transfor2d(p,a,b,c):
"The function will transform a set of points from a 3d plane to xy plane we have to keep the indexes intact for us to use later"
#TODO make it only rotation, and try to translate after wards
norm = np.sqrt(a**2+ b**2 +c **2)
cos = c /norm
theta = np.arccos(cos)
# if cos < 0:
# cos = -cos # this is a hack I have to test it again.
sen = np.sqrt((a**2+ b**2)/(norm**2))
theta1 = np.arcsin(sen)
print(theta,theta1)
u_one = b /norm
u_two = -a /norm
u_one_s = u_one**2
u_two_s = u_two**2
T11 = cos + (u_one_s*(1-cos))
T12 = ((u_one)*(u_two))*(1-cos)
T13 = u_two * sen
T21 = ((u_one)*(u_two))*(1-cos)
T22 = cos + (u_two_s*(1-cos))
T23 = -u_one * sen
T31 = -u_two * sen
T32 = u_one * sen
T33 = cos
matrix = np.zeros((3,3),np.float32)
matrix[0][0] = T11
matrix[0][1] = T12
matrix[0][2] = T13
matrix[1][0] = T21
matrix[1][1] = T22
matrix[1][2] = T23
matrix[2][0] = T31
matrix[2][1] = T32
matrix[2][2] = T33
m = matrix.dot(p)
return np.array([m[0],m[1],m[2]])