rot 3d k

Rotates a 3d coordinate by an angle theta.
Author: Sputnki
License: BSD
Github: sptnk/math/rot 3d k.axo

Inlets

frac32 x

frac32 y

frac32 z

frac32 angle of rotation (64 = 2pi)

Outlets

frac32 x

frac32 y

frac32 z

Parameters

frac32.s.map angle of rotation (64 = 2pi)

Attributes

combo rotation axis

Declaration
void rotate(int32_t x, int32_t y, int32_t z, int32_t costheta, int32_t sintheta,
            int32_t *x_out, int32_t *y_out, int32_t *z_out) {
#if (attr_axis == 0) // rotation around x
  *x_out = x;
  *y_out = ___SMMLA(y, costheta, ___SMMUL(z, -sintheta)) << 1;
  *z_out = ___SMMLA(y, sintheta, ___SMMUL(z, costheta)) << 1;
#elif (attr_axis == 1) // rotation around y
  *x_out = ___SMMLA(x, costheta, ___SMMUL(z, sintheta)) << 1;
  *y_out = y;
  *z_out = ___SMMLA(x, -sintheta, ___SMMUL(z, costheta)) << 1;
#elif (attr_axis == 2) // rotation around z
  *x_out = ___SMMLA(x, costheta, ___SMMUL(y, -sintheta)) << 1;
  *y_out = ___SMMLA(x, sintheta, ___SMMUL(y, costheta)) << 1;
  *z_out = z;
#endif
}
Control Rate
int32_t costheta;
int32_t sintheta;
SINE2TINTERP((inlet_theta + param_theta << 5) + (1 << 30), costheta);
SINE2TINTERP((inlet_theta + param_theta << 5), sintheta);

rotate(inlet_x, inlet_y, inlet_z, costheta, sintheta, &outlet_x, &outlet_y,
       &outlet_z);

Privacy

© 2024 Zrna Research