MATLAB Answers

Seereen
0

Rotate 3D quiver

Asked by Seereen
on 6 Sep 2019
Latest activity Commented on by Bjorn Gustavsson on 11 Sep 2019
I am trying to plot 3D vectors of the scene using quiver 3 function, The output upsidedown!
I reverse all the axis X,Y and Z ... I try to reverse each one separately
I could not get what I really want .. I want it as we see it in the reality
as you see in the image ... the wall and floor not adjust correctly!
How can I make them in the correct position?
I am including the function that I am used to getting this plot
%---------------------3D VECTOR FLOW -------------------------%
function Display_3D_flow(Z,U,V,W,sample,scale,title_stg,...
filename,ymin,ymax,zmin,zmax,xmin,xmax)
pic_x=size(Z,1);
pic_y=size(Z,2);
U=U*scale;
V=V*scale;
W=W*scale;
rx=pic_x:-sample:1;
%rx=1:sample:pic_x;
ry=1:sample:pic_y;
littleU=U(rx,ry);
littleV=V(rx,ry);
littleW=W(rx,ry);
NO_AUTOMATIC_SCALING=0;
[littleX,littleY] = meshgrid(ry,rx);
littleZ=Z(rx,ry);
figure
quiver3(littleX,littleY,littleZ,littleU,littleV,littleW,NO_AUTOMATIC_SCALING);
%view([90,90,-180])
axis([xmin xmax ymin ymax zmin zmax])
title(title_stg)
xlabel('X-axis')
ylabel('Y-axis')
zlabel('Z-axis')
hold on
%set(gca,'YDir','Reverse')
set(gca,'ZDir','Reverse')
%set(gca,'XDir','Reverse')
hold off
jpg_filename=[filename,'.jpg'];
print('-djpeg',jpg_filename)
end

  5 Comments

darova
on 10 Sep 2019
I don't know too
littleV = -abs(littleV);
littleW = -abs(littleW);
Bjorn Gustavsson on 10 Sep 2019
The only thing we others can say for sure is that your "wall" and "floor" labels are in unusual positions. If you change those two around then it would be fine for us. Otherwise you have done some mix-up with what coordinates you put in the x-y-z and vx-vy-vz variables. Your quiver3-call is "correct" for the x-y-z-vx-vy-vz variables you call it with. If you skip the set(gca,'ZDir','Reverse') call you will get z increasing upwards. After that you might have to figure out what your variables actually represent.
HTH
Seereen
on 10 Sep 2019
The lable just to explaine my issue ... I wnat to rotate the scene to have the wall and floor in the right position

Sign in to comment.

3 Answers

Seereen
Answer by Seereen
on 10 Sep 2019
Edited by Seereen
on 10 Sep 2019
 Accepted Answer

For any one face this in the future, I change the order of the variable in the quiver to become like this
instead of using X Y Z order now I am using X Z Y
quiver3(littleX,littleZ,littleY,littleU,littleW,littleV,NO_AUTOMATIC_SCALING);
axis([xmin xmax zmin zmax ymin ymax])
This change the scene to looks better

  3 Comments

Bjorn Gustavsson on 11 Sep 2019
It seems to me that you now should have a long think about your variable naming. It seems you want your Z-variable to be in a horizontal direction. I cannot remember ever seeing that. I strongly encourage you to rename your variables such that your z-named variable is in the vertical direction. (This will make the code easier to read, maintain and distribute to others)
Seereen
on 11 Sep 2019
Also this is confusing me ... naming the values is important to me ! .. U, V, W in my code represent the motion of the scene in 3D. U the motion in X direction , V the motion in the Y direction and W is the motion in the Z direction ! ..
Ploting them as it is give me rotated scene ... when I change the order I got the right direction !
Do you know why it is in worng direction like this?
Bjorn Gustavsson on 11 Sep 2019
Have a manual look at a couple of components of your [X,Y,Z] (your positions) and your motion components [U,V,W] - preferably some you have at least a hunch about what they should be. For example something like this:
[X(1,1),Y(1,1),Z(1,1)] % should give you the position of the first point
[U(1,1),V(1,1),W(1,1)] % The corresponding motion-vector.
Then you can repeat that for littleX, littleY, and littleZ etc. Just to trace where things go strange...
HTH

Sign in to comment.


Answer by Bjorn Gustavsson on 10 Sep 2019

Matlab uses right-handed coordinate systems (sensible), with the default convention that z is in the upward vertical direction in 3-D plots. My guess is that you've either goofed (very very unlikely, but "I know you as I know myself") with the wall-floor labling, or you've used a different notation for your x-y-z coordinates? The rest looks OK.

  1 Comment

Seereen
on 10 Sep 2019
Actually this labling ( wall and floor) not from quiver ... I just added by preview app to explain my issue
I want to change the direction of the 3D scene

Sign in to comment.


Bruno Luong
Answer by Bruno Luong
on 11 Sep 2019
Edited by Bruno Luong
on 11 Sep 2019

Another alternative: instead of reordering your data/plot parameters, you can change the view.
Play on camera parameters, especially important in your case is CameraUpVector
s=5*peaks;
ax = subplot(1,2,1);
surf(ax,s);
axis equal
ax = subplot(1,2,2);
surf(ax,s);
set(ax,'CameraUpVector',[0 -1 0]);
axis equal
Note: some interactive tool such as rotate3d won't work well with CameraUpVector different than default value of [0 0 1];

  0 Comments

Sign in to comment.