File: spaceRot.py

package info (click to toggle)
yade 2025.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,308 kB
  • sloc: cpp: 93,298; python: 50,409; sh: 577; makefile: 162
file content (11 lines) | stat: -rw-r--r-- 866 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
# jerome.duriez@inrae.fr
def spaceRot(index=0, nTot=10):
	'''Returns the rotation (as a quaternion) that transforms z-axis into some other direction vector, chosen from an adequate set of direction vectors that cover the whole 3D space
    :param int index: from 0 to nTot-1, to pick among that adequate set
    :param int nTot: how many different image directions / rotations to consider in total'''
	phiMult = pi * (3 - 5.**0.5)  # same spiral path as in polyhedralBall
	phi = index * phiMult
	theta = acos(-1. + (2. * index + 1.) / nTot)
	vec = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta))  # the direction in space, image of z through the desired rotation
	vecRot = (Vector3.UnitZ).cross(vec)  # the vector carrying the rotation
	return Quaternion(vecRot.normalized(), theta)  # the angle is the oriented angle (vecZ,vec) = theta, basically