Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a random N dimensional rotation matrix using Python?

Can I find a specific function in Numpy or Scipy to generate a random N dimensional rotation matrix (or orthogonal matrix)? I need to move a vector on an ND sphere to another random point on this sphere.

like image 914
Chong Sun Avatar asked May 27 '26 09:05

Chong Sun


1 Answers

https://math.stackexchange.com/questions/442418/random-generation-of-rotation-matrices

This may answer your question, at least as far as the strategy goes. As far as I know, there is no standard or library function from numpy that will do precisely what you need. A myriad of computational strategies are presented there, but I would prefer an extension of the quaternion approach since it can preserve a uniform distribution, which is what I'm assuming you're after.

EDIT: My original answer stated "roughly uniform," whereas after a bit more research I found that the quaternion approach, when sampled from a uniform distribution, will in fact preserve a uniform distribution in the rotations.

like image 140
gankoji Avatar answered May 30 '26 03:05

gankoji