Skip to content

Instantly share code, notes, and snippets.

@wein3967
Last active April 25, 2022 19:03
Show Gist options
  • Save wein3967/23221e199c5d817eccbe95adb9180349 to your computer and use it in GitHub Desktop.
Save wein3967/23221e199c5d817eccbe95adb9180349 to your computer and use it in GitHub Desktop.
DirectionCosines = LAMBDA(xl, yl, [zl], [xt], [yt], [zt],
SplitString(
IF(
OR(ISOMITTED(zl), ISOMITTED(xt), ISOMITTED(yt), ISOMITTED(zt)),
LET(
thetaz, xl,
phi, yl,
1 * SIN(RADIANS(thetaz)) * COS(RADIANS(phi)) & "," &
1 * SIN(RADIANS(thetaz)) * SIN(RADIANS(phi)) & "," &
1 * COS(RADIANS(thetaz)) & "," & thetaz & "," &
if(
phi >= 0,
phi,
360 + phi
)
),
LET(
magx, xt - xl,
magy, yt - yl,
magz, zt - zl,
mag, SQRT(magx ^ 2 + magy ^ 2 + magz ^ 2),
magx / mag & "," & magy / mag & "," & magz / mag & "," &
DEGREES(ACOS(magz / mag / 1)) & "," &
IF(
magy >= 0,
DEGREES(ACOS(magx / mag / (1 * SIN(ACOS(magz / mag / 1))))),
360 - DEGREES(ACOS(magx / mag / (1 * SIN(ACOS(magz / mag / 1)))))
)
)
),
","
)
);
SplitString = LAMBDA(text, delim, [indexInt],
IF(
ISOMITTED(indexInt),
TRANSPOSE(
FILTERXML(
"<x><y>" & SUBSTITUTE(text, delim, "</y><y>") & "</y></x>",
"//y"
)
),
INDEX(
TRANSPOSE(
FILTERXML(
"<x><y>" & SUBSTITUTE(text, delim, "</y><y>") & "</y></x>",
"//y"
)
),
1,
indexInt
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment