Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rotatetheta #10

Closed
esd100 opened this issue Jul 12, 2020 · 5 comments
Closed

rotatetheta #10

esd100 opened this issue Jul 12, 2020 · 5 comments

Comments

@esd100
Copy link

esd100 commented Jul 12, 2020

The rotatetheta function seems to give different results from the formula on Brian Hargreaves site. I may be too ignorant to know what the difference is, but I can't figure it out.

@StevenWhitaker
Copy link
Collaborator

Can you provide an example, prefereably with code?

@esd100
Copy link
Author

esd100 commented Jul 14, 2020

Hi, I'm not to good with Github or knowing how to easily share code, but I'll give it my best shot.

I'm not sure and don't think I'm smart enough to figure out, but I think it maybe has to do with using left or right hand rotation matrices. The way I noticed the difference was just by running your code against the simple method recommended by Brian, in A-4d) and I was getting different results.

For a rotation of phi about the axis defined by y=x*tan(theta).
Brian suggests using:

Rzθ = rotateZ(-θ)
Rxϕ = rotateX(ϕ)
Rθϕ = inv(Rzθ)*Rxϕ*Rzθ

I think he uses right hand matrix rotation rules.

When I plug this last equation written out in matrix form into with right handed matrices wolframalpha, it gives me the following matrix:

function rotateθAxis(θ::Real, ϕ::Real)
return [cos(θ)^2 + cos(ϕ)*sin(θ)^2           cos(θ)*sin(θ) - cos(θ)*cos(ϕ)*sin(θ) sin(θ)*sin(ϕ);
        cos(θ)*sin(θ) - cos(θ)*cos(ϕ)*sin(θ) cos(ϕ)*cos(θ)^2 + sin(θ)^2           -cos(θ)*sin(ϕ);
        -sin(θ)*sin(ϕ)                       cos(θ)*sin(ϕ)                        cos(ϕ)]

The above code matches up with Brian's examples.

But this is different than the one you have, which is:

function rotatetheta(θ::Real, α::Real)

    return [ sin(θ)^2+cos(α)*cos(θ)^2           sin(θ)*cos(θ)-cos(α)*sin(θ)*cos(θ)  sin(α)*cos(θ);
             sin(θ)*cos(θ)-cos(α)*sin(θ)*cos(θ) cos(θ)^2+cos(α)*sin(θ)^2           -sin(α)*sin(θ);
            -sin(α)*cos(θ)                      sin(α)*sin(θ)                       cos(α)]

Perhaps this is because you use left hand rotation rules, although When I plug in the left hand matrices into wolframalpha and follow the suggested formula from Brian, I get:

[cos(θ)^2 + cos(α)*sin(θ)^2                 cos(α)*cos(θ)*sin(θ) - cos(θ)*sin(θ)    sin(α)*sin(θ);
cos(α)*cos(θ)*sin(θ) - cos(θ)*sin(θ)       cos(α) cos(θ)^2 + sin(θ)^2                  cos(θ)*sin(α);
-sin(α)*sin(θ)                                         -cos(θ)*sin(α)                        cos(α)]

Which is also different from what you have in your code. I'm not sure why I was getting different results, although perhaps I wasn't careful enough when I put in the matrices. I'm not sure really what real difference is between right and left hand rotations. Right hand rotations seem to make more sense to me because anti-clockwise increase in angle is how I learned polar coordinates in school.

@StevenWhitaker
Copy link
Collaborator

Thanks for the very thorough reply! I understand where the confusion comes from. I guess the short answer is that we're both right, but I'm just using a different frame of reference.

There's a note in the documentation for rotatetheta that explains how the formula was derived:

rotatetheta(θ, α) == rotatez(θ) * rotatey(-α) * rotatez(-θ)

Basically, if I implement it exactly the way Brian Hargreaves suggested I end up with

rotateθAxis(0, π/2) * [0, 0, 1] == [0, 1, 0]

which I'm not a huge fan of, because then the phase of the transverse magnetization is nonzero (nonzero y component), even though the RF pulse has 0 phase (θ = 0). So, since the frame of reference is arbitrary (as long as one is consistent), I decided to define rotatetheta so that

rotatetheta(0, π/2) * [0, 0, 1] == [1, 0, 0]

Hopefully that clears things up.

As for right- versus left-handed rotations, there isn't really any difference, it's just a matter of convention. I think I read somewhere (I think in Dwight Nishimura's Principles of Magnetic Resonance Imaging) that in MRI left-handed rotations are the convention, though I can't back that up at the moment (and clearly Brian Hargreaves didn't follow that convention).

@esd100
Copy link
Author

esd100 commented Jul 26, 2020

Thanks for trying to clear that up. I guess I'm still a little confused though. I'm not sure why [1,0,0] is any different from [0,1,0]. I thought those were both transverse components [x,y,z]. Is one more preferential than the other?

Also, I thought theta was just the angle that defines the axis about which we are trying to rotate. I'll be honest in that I get a little bit confused when trying to understand an axis as y=x*tan(theta), the way Brian defines it. I believe you have a different way of defining it as "the x-y plane that makes angle θ with the negative y-axis". I'm not smart enough to know for sure if that is the same.

It becomes confusing because when I try to look at rotations about an arbitrary axis on sites like wikipedia, they use some other more complex and generic definition for axis from angle and vice versa (https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle). I get lost trying to see how that definition is similar, but they have a similar appearance and feel.

It would be interesting to know why left hand rotation is convention, since right hand rotation seems to make more intuitive sense to me.

@StevenWhitaker
Copy link
Collaborator

StevenWhitaker commented Jul 27, 2020

I'm not sure why [1,0,0] is any different from [0,1,0]. I thought those were both transverse components [x,y,z]. Is one more preferential than the other?

No, it's just personal preference. I define the complex transverse signal to be x + i*y, so the signal from [1, 0, 0] is purely real, and the signal from [0, 1, 0] is purely imaginary. So if the excitation pulse has 0 phase, I want the signal to have 0 phase (no imaginary part). Again, it's just personal preference.

I thought theta was just the angle that defines the axis about which we are trying to rotate.

Yes, that is correct (and in an MRI context, this is related to the phase of the RF excitation pulse).

I believe you have a different way of defining it

Yes.

they use some other more complex and generic definition for axis from angle and vice versa

They don't constrain the axis of rotation to lie in the x-y plane.

I'll just reiterate that the frame of reference is arbitrary as long as one is consistent. In an MRI context, the difference between Brian Hargreaves' frame of reference and mine is the phase of the transverse magnetization after excitation, and whether the transverse magnetization rotates clockwise or counterclockwise during free precession. Both frames of reference still can be used to simulate MRI physics. The only time one would need to pay attention to what frame of reference is used is when comparing results from different frames of reference (e.g., comparing results from my Bloch simulator to Brian Hargreaves'), and even then, only the phase of the transverse magnetization would be different (the magnitude would be the same).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants