Rotate horizontal components to principal axes.
rotateComponents.RdApplies a 2-D PCA rotation to the two horizontal signal components
(DIR == "H1" and "H2") so that H1 aligns with the direction of
maximum variance and H2 is orthogonal. The vertical component
(DIR == "UP") is left untouched.
Value
DT with s values updated in-place for DIR %in% c("H1","H2") and attr(DT, "theta") set. Returns DT unchanged
when the record does not have exactly two horizontal components.
Details
This step requires a LONG table already classified with DIR values
H1, H2, and UP. New processing code should usually call
mapComponents() with rotate = TRUE instead of calling this helper
directly.
The rotation angle theta is stored as attr(DT, "theta") in radians so
that extractRecord() can persist it in the JSON sidecar.
Examples
t <- seq(0, 1, by = 0.1)
x <- data.table::rbindlist(list(
data.table::data.table(t = t, OCID = "N", DIR = "H1",
s = sin(2 * pi * t)),
data.table::data.table(t = t, OCID = "E", DIR = "H2",
s = 0.5 * cos(2 * pi * t)),
data.table::data.table(t = t, OCID = "Z", DIR = "UP",
s = 0.1 * sin(2 * pi * t))
))
rotated <- rotateComponents(x)
attr(rotated, "theta")
#> [1] 3.141593