Skip to content

Commit

Permalink
Corrected mat_to_quaternion and make sure w is non-negative
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Dec 17, 2024
1 parent 0a972a2 commit 5215640
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.0.1
Date: 2024-09-12 20:57:24 UTC
SHA: a255878475e582dcc44af9b2eb7d4210e2a0a0ed
Version: 0.0.2
Date: 2024-10-31 22:50:46 UTC
SHA: 0a972a2f23ac8190b2cd282a9341e16de5c27955
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ieegio
Title: File IO for Intracranial Electroencephalography
Version: 0.0.2
Version: 0.0.2.9000
Language: en-US
Encoding: UTF-8
Authors@R:
Expand Down
14 changes: 13 additions & 1 deletion R/math.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ mat_to_quaternion <- function(m) {
y <- (m23 + m32) / s
z <- 0.25 * s
}
c(x = x, y = y, z = z, w = w)

re <- c(x = x, y = y, z = z, w = w)

if(w < 0) {
# make sure w is positive as described: https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h
# Requiring a >= 0 is equivalent to requiring -Pi <= h <= Pi. (Note that
# [-a,-b,-c,-d] represents the same rotation as [a,b,c,d]; there are 2
# quaternions that can be used to represent a given rotation matrix R.)
# To rotate a 3-vector (x,y,z) using quaternions, we compute the
# quaternion product
re <- re * -1
}
re
}

#
Expand Down

0 comments on commit 5215640

Please sign in to comment.