Skip to content

Commit

Permalink
Cython: matrix utils - new multiplication functions between vector an…
Browse files Browse the repository at this point in the history
…d matrix
  • Loading branch information
jfranmatheu committed Feb 17, 2025
1 parent c70baf9 commit 057738c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions retopoflow/cy/matrix.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ cdef void mat4_multiply(float[4][4] a, float[4][4] b, float[4][4] result) noexce
cdef void mat4_get_translation(float[4][4] m, float* result) noexcept nogil
cdef void mat4_get_col3(float[4][4] m, int col, float* result) noexcept nogil
cdef void mat4_get_col4(float[4][4] m, int col, float* result) noexcept nogil

################################################################
################################################################
################################################################

cdef void mul_m4_v3(const float[4][4] M, float[3] r) noexcept nogil
cdef void mul_v3_m4v3(float[3] r, const float[4][4] mat, const float[3] vec) noexcept nogil
23 changes: 23 additions & 0 deletions retopoflow/cy/matrix.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,26 @@ cdef void mat4_get_translation(float[4][4] m, float* result) noexcept nogil:
result[0] = m[0][3]
result[1] = m[1][3]
result[2] = m[2][3]


################################################################
################################################################
################################################################

cdef void mul_m4_v3(const float[4][4] M, float[3] r) noexcept nogil:
cdef:
float x = r[0];
float y = r[1];

r[0] = x * M[0][0] + y * M[1][0] + M[2][0] * r[2] + M[3][0]
r[1] = x * M[0][1] + y * M[1][1] + M[2][1] * r[2] + M[3][1]
r[2] = x * M[0][2] + y * M[1][2] + M[2][2] * r[2] + M[3][2]

cdef void mul_v3_m4v3(float[3] r, const float[4][4] mat, const float[3] vec) noexcept nogil:
cdef:
float x = vec[0]
float y = vec[1]

r[0] = x * mat[0][0] + y * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]
r[1] = x * mat[0][1] + y * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]
r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]

0 comments on commit 057738c

Please sign in to comment.