[Simnibs-discuss] transformation matrix usage

Oula Puonti oulap at drcmr.dk
Fri Feb 10 14:16:43 CET 2023


Hi Stefan,

Good to hear you sorted it out!

The function was meant mostly as a reference of how the matsimnibs
matrix is constructed, i.e., what the x, y and z-directions are.

I think I have some matlab code somewhere for changing the rotation. I
can send you that in case you need it, but it seems like you figured it
out already.

Best,
Oula

On Fri, 2023-02-10 at 10:09 +0000, Haren, S.L. van (Stefan, Student M-
TM) wrote:
> Hi Oula,
> 
> Thanks for the quick response, unfortunately I am yet to learn how to
> program with python and can therefore not really use that function,
> but I was able to use a rotation matrix to recalculate the input and
> therefore also acquire a desired rotation.
> 
> for i=1:length(xrotation)
>     a = zrotation(i)*pi/180;
>     b = yrotation(i)*pi/180;
>     y = xrotation(i)*pi/180;
>     
>     rotationmatrix = [cos(a)*cos(b)...
>         (cos(a)*sin(b)*sin(y))-(sin(a)*cos(y))...
>         (cos(a)*sin(b)*cos(y))+(sin(a)*sin(y)),...
>         sin(a)*cos(b)...
>         (sin(a)*sin(b)*sin(y))+(cos(a)*cos(y))...
>         (sin(a)*sin(b)*cos(y))-(cos(a)*sin(y)),...
>         -sin(b)...
>         cos(b)*sin(y)...
>         cos(b)*cos(y)];
>     
>     corretion = [-1 1 1, 1 1 1, 1 1 -1];
>     corrected = rotationmatrix.*corretion;
>     
>     simnibsmatrix = zeros(4,4);
>     simnibsmatrix(1,1:3) = corrected(1,1:3);
>     simnibsmatrix(2,1:3) = corrected(4:6);
>     simnibsmatrix(3,1:3) = corrected(7:9);
>     simnibsmatrix(1,4) = centrecoords(1);
>     simnibsmatrix(2,4) = centrecoords(2);
>     simnibsmatrix(3,4) = centrecoords(3);
>     simnibsmatrix(4,1:4) = [0 0 0 1];
> 
>     s.poslist{1, 1}.pos(i).matsimnibs = simnibsmatrix;
> end
> 
> Best,
> Stefan
> 
> -----Original Message-----
> From: Oula Puonti <oulap at drcmr.dk> 
> Sent: Wednesday, 8 February 2023 16:34
> To: Haren, S.L. van (Stefan, Student M-TM)
> <s.l.vanharen at student.utwente.nl>; simnibs-discuss at drcmr.dk
> Subject: Re: [Simnibs-discuss] transformation matrix usage
> 
> Hi Stefan,
> 
> Have a look at this function, which defines matsimnibs based on a
> center coordinate and a "y-direction" pointing away from the coil
> handle:
> 
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsimnibs%2Fsimnibs%2Fblob%2Fefd0e3df2ed74a68238055ffeaca594f721a584e%2Fsimnibs%2Fmesh_tools%2Fmesh_io.py%23L1840&data=05%7C01%7Cs.l.vanharen%40student.utwente.nl%7C8a6691e0474941d58e1408db09e9d6db%7C723246a1c3f543c5acdc43adb404ac4d%7C0%7C0%7C638114672165951293%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=StzFw7nF9kcjOXszsw496b3nI%2BuIUQdrbAI89dIUM2g%3D&reserved=0
> 
> The z-direction is defined to be normal to the nodes on the skin so
> the coil should be more or less tangential to the scalp.
> 
> Best,
> Oula
> 
> 
> On Mon, 2023-02-06 at 12:48 +0000, Haren, S.L. van (Stefan, Student
> M-
> TM) wrote:
> > Hello all,
> >  
> > I am still quite new to using SimNIBS, and I am struggling with one
> > of 
> > the attributes in the Position format. I am using the
> > transformation 
> > matrix from the pos.matsimnibs function for more accurately 
> > positioning my TMS coil over the scalp of a subject. I know the 
> > coordinates of my coil and I can fill them in into the matrix and
> > get 
> > the correct centre of the coil. However, I cannot figure out how to
> > rotate the coil/coordinate system using the transformation matrix.
> > I 
> > am unable to get it to be perpendicular to the scalp or change 
> > direction altogether.
> >  
> > Hopefully someone can help me with my struggles, Stefan
> >  
> >  
> > _______________________________________________
> > Simnibs-discuss mailing list
> > Simnibs-discuss at drcmr.dk
> > https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail
> > man.drcmr.dk%2Fmailman%2Flistinfo%2Fsimnibs-
> > discuss&data=05%7C01%7Cs.l
> > .vanharen%40student.utwente.nl%7C8a6691e0474941d58e1408db09e9d6db%7
> > C72
> > 3246a1c3f543c5acdc43adb404ac4d%7C0%7C0%7C638114672165951293%7CUnkno
> > wn%
> > 7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiL
> > CJX
> > VCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FQTqpbxGpi6h3U859t1I7okH89bNxkJ8
> > fEc
> > TPy9hZpw%3D&reserved=0
> 



More information about the Simnibs-discuss mailing list