The main goal of this procedure is to first rotate an array of 3D coordinate leaving z untouched,finding the positions of tuples with z larger than some value, and then mapping those positions to the un-rotated array.
I will provide an example to clear things up. Let the un-rotated array be test1
and the rotated one test2
. Element #2 of test1
is {0.00195313, 0.00112764, 6.76149*10^-14}
this gets rotated to {-0.00195313, -0.00112764, 6.76149*10^-14}
in test2
at the same position,e.i. test2[[2]]
. This rotated element may not be part of the original array, I used Nearest
to find the closest element to this an then its corresponding position. The closest element in the original array is the one with coordinates X and Y {-0.00195313, -0.00112737}
and its in position 131412
. I am using the approach described here to select the elements I'd like to keep as it is the fastest method I've found. So after all this the element in position #2 of this filtered array should go to position 131412
.
The problem seems to arise when using the nearest function, it might be mapping multiple elements in one array to one in the other one. I dont know how to get around this issue.
Here is my attempt at this:
test1 = Import["C:"path"jr12.csv", "CSV"];
test2 = Import["C:"path"Rjr12.csv", "CSV"];
test22d = test2[[All, {1, 2}]];
test12d = test1[[All, {1, 2}]];
index1 = PositionIndex[test12d];
n = Nearest[test12d];
pos = Join @@ index1 /@ (Join @@ (n /@ test22d));
ind = PositionIndex[pos];
outrot = UnitStep[0.1 - test2[[All, -1]]];
out = ConstantArray[1, Dimensions[outrot][[1]]];
result = Reap[Do[Sow[{out[[n]]*outrot[[ind[n]]]}], {n, 1,Dimensions[outrot][[1]]}]][[2, 1]];
(*Failure point*)
(*Part::pkspec1: The expression Missing[KeyAbsent,131157] cannot be used as a part specification.
Part::pkspec1: The expression Missing[KeyAbsent,218453] cannot be used as a part specification
General::stop: Further output of Part::pkspec1 will be suppressed during this calculation.*)
Dimensions[test2]
(*{261972, 3}*)
Dimensions[pos]
(*{261972}*)
Dimensions[ind]
(*{261801} Loss of elements*)
Any advise or fix on this attempt would be appreciated.
nearOriginal = Nearest[MapIndexed[Most@#1 -> First@#2 &]@test1]; test2[[Ordering@Ordering@nearOriginal[test2[[All, ;; 2]], 1]]]
. $\endgroup$result
contain only zeros and ones? $\endgroup$