How do I rotate a 2D wave about the z axis?
3 views (last 30 days)
Show older comments
I am trying to figure how to rotate my 2D wave by 30 degrees or so.
pixels = 60;
X = meshgrid(1:pixels);
Z = sin(X);
mesh(Z)
Using the rot90 function I can rotate it by 90 degrees - giving me two mesh graphs:

However, I am interested in rotating my sine wave by 30 degrees AND I still want to end up with a matrix of values to look at. To my knowledge there is no function that does that.
So, why not use the Rz Rotation Matrix?
Rz = [cos(t) -sin(t) 0; sin(t) cos(t) 0; 0 0 1];
Well, I don't know how to implement this into my code.
I followed this guide and now know how to rotate a torus about an axis - but only using symbolic variables (which I am unfamiliar with). I don't know how to apply that knowledge to my current situation. It looks like it couldn't help me build a matrix.
EDIT: My friend figured it out, but leaving this up in-case anyone has a similar question.
function Z = sinwav(pixels, nOscillations, orientation, pShift)
O = nOscillations * (2 * pi /pixels); %how many times you want wave to oscillate in x-dir
xdomain = 1:pixels;
[X,Y] = meshgrid(xdomain);
Z = sin((sin(orientation)*O*X + cos(orientation)*O*Y)+pShift);
mesh(Z)
0 Comments
Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!