I have the following piece of code
all[phi_, theta_, alpha_] :=
EulerMatrix[{-(phi +
90) Degree, theta Degree, -(180 - alpha) Degree}, {3, 2, 1}]
condition = Cases[data, { _, _, x_, _, _, vx_, vy_, vz_, _} /;
85 < VectorAngle[all[Phi[x], Theta[x], Alpha[x]].{0, 0, -1},
{vx, vy, vz}]/Degree < 95]
with Phi[x]
, Theta[x]
and Alpha[x]
defined as Piecewise
functions that give back angles in degrees along x. "data"
is a list of particles, each with different positions, velocities and other properties.
What the code does is filter out all particles in data, whose velocity vector is out of a certain field of view.
Since the orientation of the field of view is not constant, but changing depending on the x coordinate inside my reference system, I need to apply a transformation matrix to the field of view-system inside my condition.
VectorAngle[all[Phi[x], Theta[x], Alpha[x]].{0, 0, -1},{vx, vy, vz}]
But the way I'm doing it seems very slow. For a 500k long list, it takes about 10 min. The main problem seems to be the calling of the rotation matrix inside VectorAngle. Is there a faster way?
Edit:
An example of the entries in data
:
{0, 3.5104e-07, 45.351, -0.654687, 0.300059, 6.81731, -1.25439, -4.13684, 8.07234}
The first entry identifies the particles species, the second is a numerical weight, the last entry is actually the magnitude of the particles velocity.
Here's how I defined Phi[x]
(I didn't include all conditions):
Phi[x_] :=
Piecewise[{{140, x < -14.},{125.,-14. <= x < -12.},{90.,12.<= x <-9.5},
{160., -9.5 <= x < -2.},{180.,-2. <= x < 4.5}}
Alpha[x]
and Theta[x]
are defined in the exact same way, just other numbers. And the intervals covered in the conditions do not overlap completely inbetween the three.
Phi[x]
,Theta[x]
, andAlpha[x]
. It would be nice to have their definitions. $\endgroup$ – Henrik Schumacher Nov 24 '17 at 17:39