私は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/を試してみてください。 –