trasformation of a unit vector quiver3

Hi everyone , i would like to know if it is possibile to obtain a trasformation of quiver3 object . I have a normal quiver3 object and i want to trasform with my homogenous traformation matrix hM(4*4). i don't want modify my q_w but get another one. thank you very much.
q_w=quiver3(zeros(3,1),zeros(3,1),zeros(3,1),[1;0;0],[0;1;0],[0;0;1]);
q_w.LineWidth=3;
q_w.AutoScaleFactor=8;
rz=[ cos(psi) -sin(psi) 0 ;
sin(psi) cos(psi) 0 ;
0 0 1] ;
ry=[ cos(theta) 0 sin(theta) ;
0 1 0 ;
-sin(theta) 0 cos(theta)];
rx=[ 1 0 0 ;
0 cos(fi) -sin(fi);
0 sin(fi) cos(fi)];
rM=ry*rx*rz; % giusta
% rMf=matlabFunction(rM);
%creaiamo la nostra matrice omogenea
transition=[x y z]';
% transitionF=matlabFunction(transition);
one=ones(1);
hM= [ rM transition ;
zeros one ];

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 4 de Mayo de 2020
Editada: Ameer Hamza el 4 de Mayo de 2020
Try this
vec1 = [1;0;0];
vec2 = [0;1;0];
vec3 = [0;0;1];
q_w=quiver3(zeros(3,1),zeros(3,1),zeros(3,1),vec1,vec2,vec3);
q_w.LineWidth=3;
q_w.AutoScaleFactor=8;
psi = pi/4;
theta = pi/3;
fi = pi/6;
rz=[ cos(psi) -sin(psi) 0 ;
sin(psi) cos(psi) 0 ;
0 0 1] ;
ry=[ cos(theta) 0 sin(theta) ;
0 1 0 ;
-sin(theta) 0 cos(theta)];
rx=[ 1 0 0 ;
0 cos(fi) -sin(fi);
0 sin(fi) cos(fi)];
rM=ry*rx*rz; % giusta
figure;
q_w=quiver3(zeros(3,1),zeros(3,1),zeros(3,1),rM*vec1,rM*vec2,rM*vec3);
q_w.LineWidth=3;
q_w.AutoScaleFactor=8;
Also see eul2rotm(): https://www.mathworks.com/help/releases/R2020a/robotics/ref/eul2rotm.html to generate the rotation matrix.

12 comentarios

Andrea Gusmara
Andrea Gusmara el 4 de Mayo de 2020
i understan and how can i translate quiver3 object.
Add a constant value to the x, y, and z coordinates. Following translate the vectors to (1 2 3)
q_w=quiver3(zeros(3,1)+1,zeros(3,1)+2,zeros(3,1)+3,rM*vec1,rM*vec2,rM*vec3);
Andrea Gusmara
Andrea Gusmara el 4 de Mayo de 2020
Editada: Ameer Hamza el 4 de Mayo de 2020
ok i can follow you but when i try to apply this changes into my matlab program i encotered the following error.
Index in position 1 exceeds array bounds (must not exceed 1).
Error in prova (line 103)
q_w=quiver3(zeros(3,1)+x,zeros(3,1)+y,zeros(3,1)+z,rM*vec1,rM*vec2,rM*vec3);
This is my full program. i've tried for hours to understand why the error occursbut i can't fix the problem .
clear all
close all
surf=gca;
xlim(surf,[-15 +15]);
xlabel('x');
zlim(surf,[-15 +15]);
zlabel('z');
ylim(surf,[-15 +15]);
ylabel('y');
daspect([1 1 1]);
dim=input('enter the dimensions of your cuboid [x,y,z]\n ');
dx=dim(1);
dy=dim(2);
dz=dim(3);
vertices=[-dx/2,-dy/2,0;-dx/2,+dy/2,0;dx/2,dy/2,0;dx/2,-dy/2,0; -dx/2,-dy/2,dz;-dx/2,+dy/2,dz;dx/2,dy/2,dz;dx/2,-dy/2,dz];
S.Vertices=vertices;
faces=[1,2,3,4;1,2,6,5;3,2,6,7;4,3,7,8;4,1,5,8;5,6,7,8];
S.Faces=faces;
color=[1 0 0; 0 1 0 ; 0 0 1 ; 0 1 1 ; 1 0 1 ; 1 1 0 ];
p=patch(S);
p.FaceVertexCData=color;
p.FaceColor="flat";
hold('on');
q_w=quiver3(zeros(3,1),zeros(3,1),zeros(3,1),[1;0;0],[0;1;0],[0;0;1]);
q_w.LineWidth=3;
q_w.AutoScaleFactor=8;
wrt=eye(4);
rsb=eye(4);
zeros=zeros(1,3);
continua=true;
count=0;
while continua
rs=input('insert body if you want to transform with respect to the body reference system or insert world if you want with respect to the world \n ');
dof=input('enter the transformation values [fi,theta,psi,x,y,z] \n ');
fi=deg2rad(dof(1));
theta=deg2rad(dof(2));
psi=deg2rad(dof(3));
x=dof(4);
y=dof(5);
z=dof(6);
rz=[ cos(psi) -sin(psi) 0 ;
sin(psi) cos(psi) 0 ;
0 0 1] ;
ry=[ cos(theta) 0 sin(theta) ;
0 1 0 ;
-sin(theta) 0 cos(theta)];
rx=[ 1 0 0 ;
0 cos(fi) -sin(fi);
0 sin(fi) cos(fi)];
rM=ry*rx*rz; % giusta
% rMf=matlabFunction(rM);
%creaiamo la nostra matrice omogenea
transition=[x y z]';
% transitionF=matlabFunction(transition);
one=ones(1);
hM= [ rM transition ;
zeros one ];
if strcmp(rs,'body')
rsb=rsb*hM;
newVertices=rsb*[vertices ones(1,8)']';
else
rsb=wrt*hM;
newVertices=rsb*[vertices ones(1,8)']';
end
count=count+1;
newVertices=newVertices';
S.Vertices=[S.Vertices ; newVertices(:,1:3)];
S.Faces=[S.Faces ; faces+(8*count)];
p=patch(S);
for j=0:count
p.FaceVertexCData=[p.FaceVertexCData ; color];
end
p.FaceColor="flat";
hold('on');
q_=bquiver3(zeros(3,1)+x,zeros(3,1)+y,zeros(3,1)+z,rM*vec1,rM*vec2,rM*vec3);
q_b.LineWidth=3;
q_b.AutoScaleFactor=8;
risp=input('do you wish to continue? (yes,no) \n ');
if strcmp(risp,'yes')
continua=true;
else
continua=false;
end
end
Ameer Hamza
Ameer Hamza el 4 de Mayo de 2020
What inputs did you use for input() statements?
Andrea Gusmara
Andrea Gusmara el 4 de Mayo de 2020
[0,45,0,5,5,5]
Ameer Hamza
Ameer Hamza el 4 de Mayo de 2020
You haven't defined vec1, vec2, and vec3, as I have defined in the answer.
Andrea Gusmara
Andrea Gusmara el 4 de Mayo de 2020
yes you are right , i forgot it . but now , the error persists.
You have used a line
zeros=zeros(1,3);
But zeros is also the name of the MATLAB function. Change the name of the variable here and everywhere else in the code.
Andrea Gusmara
Andrea Gusmara el 4 de Mayo de 2020
q_w=quiver3(zeros(3,1),zeros(3,1),zeros(3,1),[0.7071;0;-0.7071],[0;1;0],[0.7071;0;0.7071]);
Index in position 1 exceeds array bounds (must not exceed 1).
this is the istruction with the unit_vector rotated.
But the strange thing is also without rotation of the unit_vectors i encontered the error
Index in position 1 exceeds array bounds (must not exceed 1).
Error in roto_traslazione_spazio (line 106)
q_w=quiver3(zeros(3,1),zeros(3,1),zeros(3,1),vec1,vec2,vec3);
Ameer Hamza
Ameer Hamza el 4 de Mayo de 2020
Editada: Ameer Hamza el 4 de Mayo de 2020
Have you modified the name of variable zeros? Also run
clear zeros
to remove the variable from workspace.
Andrea Gusmara
Andrea Gusmara el 4 de Mayo de 2020
you are right , the problem was the variable zeros , thank you so much
for your patience and attention.
Ameer Hamza
Ameer Hamza el 4 de Mayo de 2020
I am glad to be of help.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 4 de Mayo de 2020

Comentada:

el 4 de Mayo de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by