juegos

Juegos de terminal de Pancho: Catan (TUI, GUI, web, servidor, PicoCalc), ajedrez, calculadora y minijuegos
git clone https://git.lu3dhn.xyz/juegos.git
Log | Files | Refs

matrix.h (1294B)


      1 /* matrix.h - matrices y vectores de hasta 4x4 con elementos Num (exactos si se puede). */
      2 #ifndef MATRIX_H
      3 #define MATRIX_H
      4 #include "num.h"
      5 
      6 #define MAT_N 4
      7 enum { MV_SCALAR, MV_MAT, MV_VEC };
      8 
      9 /* un valor del modo Matrices: escalar, matriz r x c o vector (r = 1, c = 2 o 3) */
     10 typedef struct {
     11     uint8_t kind, r, c;
     12     Num a[MAT_N * MAT_N];
     13 } MVal;
     14 
     15 static inline Num *mv_at(MVal *m, int i, int j) { return &m->a[i * MAT_N + j]; }
     16 static inline const Num *mv_get(const MVal *m, int i, int j) { return &m->a[i * MAT_N + j]; }
     17 
     18 void mv_scalar(MVal *o, Num v);
     19 void mv_zero(MVal *o, int kind, int r, int c);
     20 bool mv_add(MVal *o, const MVal *a, const MVal *b, bool sub);
     21 bool mv_mul(MVal *o, const MVal *a, const MVal *b);
     22 bool mv_scale(MVal *o, const MVal *a, Num k, bool div);
     23 bool mv_neg(MVal *o, const MVal *a);
     24 bool mv_det(Num *o, const MVal *a);
     25 bool mv_inv(MVal *o, const MVal *a);
     26 bool mv_pow(MVal *o, const MVal *a, int64_t n);
     27 bool mv_trn(MVal *o, const MVal *a);
     28 bool mv_ident(MVal *o, int n);
     29 bool mv_dot(Num *o, const MVal *a, const MVal *b);
     30 bool mv_cross(MVal *o, const MVal *a, const MVal *b);
     31 bool mv_norm(Num *o, const MVal *a);
     32 bool mv_unit(MVal *o, const MVal *a);
     33 bool mv_angle(Num *o, const MVal *a, const MVal *b, int ang);
     34 bool mv_abs(MVal *o, const MVal *a);
     35 
     36 #endif