저는 Python으로 작성한 피팅 루틴에 대한 좌표 변환을 무작위로 생성하려고합니다. 원점에 대한 데이터 (x, y, z 좌표의 묶음)를 회전시키고 싶습니다. 평면을 정의하기 위해 이미 생성 한 무작위로 생성 된 법선 벡터를 사용하는 것이 이상적입니다. 각 평면을 이동하려고합니다. 그것이 z = 0 평면에 놓 이도록 정의되었다.랜덤하게 생성 된 법선 벡터의 좌표 변환
다음은 내 변환 행렬을 얻은 후에 처리해야하는 코드 조각입니다. 나는 나의 법선 벡터로부터 변환 행렬을 얻는 법과 numpy보다 더 복잡한 것을 필요로하는지 잘 모르겠습니다.
import matplotlib as plt
import numpy as np
import math
origin = np.array([35,35,35])
normal = np.array([np.random.uniform(-1,1),np.random.uniform(-1,1),np.random.uniform(0,1)])
mag = np.sum(np.multiply(normal,normal))
normal = normal/mag
a = normal[0]
b = normal[1]
c = normal[2]
#I know this is not the right transformation matrix but I'm not sure what is...
#Looking for the steps that will take me from the normal vector to this transformation matrix
rotation = np.array([[a, 0, 0], [0, b, 0], [0, 0, c]])
#Here v would be a datapoint I'm trying to shift?
v=(test_x,test_y,test_z)
s = np.subtract(v,origin) #shift points in the plane so that the center of rotation is at the origin
so = np.multiply(rotation,s) #apply the rotation about the origin
vo = np.add(so,origin) #shift again so the origin goes back to the desired center of rotation
x_new = vo[0]
y_new = vo[1]
z_new = vo[2]
fig = plt.figure(figsize=(9,9))
plt3d = fig.gca(projection='3d')
plt3d.scatter(x_new, y_new, z_new, s=50, c='g', edgecolor='none')
무엇이 당신의 질문입니까? 현재 코드가 작동하는지 여부 감사. –
제 질문은 어떻게 법선 벡터에서 올바른 변환 매트릭스를 얻을 수 있습니까? – Arnold
이제 귀하의 질문을 이해합니다.Z 축을 중심으로 평면을 회전시킬 수 있기 때문에 여러 변형 행렬이 올바른 답을 줄 수 있습니다. 아마도 대신 http://math.stackexchange.com/을 시도해보십시오. –