I'm trying to randomly generate coordinate transformations for a fitting routine I'm writing in python. I want to rotate my data (a bunch of [x,y,z] coordinates) about the origin, ideally using a bunch of randomly generated normal vectors I've already created to define planes -- I just want to shift each plane I've defined so that it lies in the z=0 plane.
Here's a snippet of my code that should take care of things once I have my transformation matrix. I'm just not sure how to get my transformation matrix from my normal vector and if I need something more complicated than numpy for this.
import matplotlib as plt
import numpy as np
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
b = normal
c = normal
#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?
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
y_new = vo
z_new = vo
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')
I think you have a wrong concept of rotation matrices. Rotation matrices define rotation of a certain angle and can not have diagonal structure.
If you imagine every rotation as a composition of a rotation around the X axis, then around the Y axis, then around the Z axis, you can build each matrix and compose the final rotation as product of matrices
R = Rz*Ry*Rx Rotated_item = R*original_item
Rotated_item = np.multiply(R,original_item)
In this formula Rx is the first applied rotation.
Be aware that
How to compose each single rotation matrix around 1 axis? See this image from wikipedia. Numpy has all things you need.
Now you just have to define 3 angles values. Of course you can derive 3 angles values from a random normalized vector (a,b,c) as you write in your question, but rotation is a process that transform a vector in another vector. Maybe you have to specify something like "I want to find the rotation R around the origin that transform (0,0,1) into (a,b,c)". A completely different rotation R' is the one that transform (1,0,0) into (a,b,c).