Filter löschen
Filter löschen

i' can't delete a quiver object from my patch

4 Ansichten (letzte 30 Tage)
Andrea Gusmara
Andrea Gusmara am 3 Jun. 2020
Kommentiert: Walter Roberson am 7 Jun. 2020
clear all
close all
%% SPAZIO LAVORO
%regolo i limiti degli assi dello spazio
surf=gca;
xlim(surf,[-30 +30]);
xlabel('x');
zlim(surf,[-30 +30]);
zlabel('z');
ylim(surf,[-30 +30]);
ylabel('y');
%regola in una modalità fissa la lunghezza dela singola unita degli assi
daspect([1 1 1]);
%creo i versori del sistema di riferimento del mondo
%% VARIABILI AUSILIARIE
%creo i versori del sistema di riferimento del mondo
S.Vertices=[];
S.Faces=[];
p=patch(S);
frameb=eye(4);
frame0=frameb;
vec1 = [1;0;0];
vec2 = [0;1;0];
vec3 = [0;0;1];
vec0=[0;0;0];
body=eye(4);
wrt=eye(4); % sistema di riferimento world
zero=zeros(1,3);
cycle=true;
color1=[1 0 0; 0 1 0 ; 0 0 1 ; 0 1 1 ; 1 0 1 ; 1 1 0 ];
color2=[0.6350 0.0780 0.1840; 0.3010 0.7450 0.9330 ; 0.4660 0.6740 0.1880 ; 0.4940 0.1840 0.5560 ; 0.9290 0.6940 0.1250 ; 0.8500 0.3250 0.0980];
color3=[rand(1,3); rand(1,3) ; rand(1,3) ; rand(1,3) ; rand(1,3) ; rand(1,3)];
syms a;
syms d;
syms alpha;
syms theta;
%matrice omogenea trasformation from frame i-1 to frame i
%% (PRIMO PASSO) CREAZIONE DEL BASAMENTO CON IL SUO SISTEMA DI RIFERIMENTO
hold('on');
frame0V=ReferenceSystem(frame0);
dx=5;
dy=7;
dz=2;
%[BASE]
%faccia superiore e dimensioni specificate dall'utente.
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;%inizializzo il campo Vertices dell'oggetto di S la variabile di 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;%assegno al campo Faces dell'oggetto di S la variabile di faces
delete(p);
p=patch(S);
p.FaceVertexCData=color1;
p.FaceColor="flat";
%% (SECONDO PASSO) CREAZIONE DI FRAME1 E DEL LINK1
%interazione con L'utente :chiede le dimensione del parallelepipedo
% parDH=input('enter the DH parameters [a,d,alpha,theta]\n ');
% frame2=subs(fA,{a,d,alpha,theta},{parDH(1),parDH(2),parDH(3),parDH(4)});
% frame1=subs(fA,{a,d,alpha,theta},{0,12,pi/2,pi/2});
a=0;
d=12;
alpha=pi/2;
theta=pi/2;
A=[ cos(theta) -sin(theta)*cos(alpha) sin(theta)*sin(alpha) a*cos(theta)
sin(theta) cos(theta)*cos(alpha) -cos(theta)*sin(alpha) a*sin(theta)
0 sin(alpha) cos(alpha) d
0 0 0 1 ];
frame1=A;
hold('on');
frame1V=ReferenceSystem(frame1);
%interazione con L'utente :chiede le dimensione del parallelepipedo
% dim=input('enter the dimensions of your link1 [x,y,z]\n ');
dim_link1=[1,1,9];
dx=dim_link1(1);
dy=dim_link1(2);
dz=dim_link1(3);
%%richiesta della variabile
variabile1Tetha=input(' revolutionary joint [TRUE] else [FALSE] \n ');
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=[S.Vertices ; vertices];%concateno nell'insieme dei vertici i vertici del nuovo poligono riportandolo nella forma normale
%ottenuto con la trasformazione rigida
S.Faces=[S.Faces ; faces+(8)];%concateno la matrice che specifica i vertici che comongono le facce del nuovo poligono
delete(p);
p=patch(S);
%concateno tante matrici color(che raopresentano i colori delle facce dei poligoni) tante quante i poligni che disegno
p.FaceVertexCData=[color1; color2];
p.FaceColor="flat";
%% (TERZO PASSO) CREAZIONE FRAME2 E LINK2
%interazione con L'utente :chiede le dimensione del parallelepipedo
% dim=input('enter the dimensions of your link1 [x,y,z]\n ');
dim_link1=[1,1,9];
dx=dim_link1(1);
dy=dim_link1(2);
dz=dim_link1(3);
variabile2Tetha=input(' revolutionary joint [TRUE] else [FALSE] \n ');
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];
link2=frame1*[vertices ones(8,1)]';
S.Vertices=double([S.Vertices ; link2(1:3,:)']);
% S.Vertices=[S.Vertices ; vertices];%concateno nell'insieme dei vertici i vertici del nuovo poligono riportandolo nella forma normale
%ottenuto con la trasformazione rigida
S.Faces=[S.Faces ; faces+(16)];%concateno la matrice che specifica i vertici che comongono le facce del nuovo poligono
delete(p);
p=patch(S);
%concateno tante matrici color(che raopresentano i colori delle facce dei poligoni) tante quante i poligni che disegno
p.FaceVertexCData=[color1; color2;color3];
p.FaceColor="flat";
%answ=input(' Vuoi ridefinire Frame0 e base [true,false] \n ');
%end
%% ITERAZIONE UTENTE
fprintf("first link rotation\n");
if variabile1Tetha
answ=input(' insert the rotation degree[degs] \n ');
a=0;
d=0;
alpha=0;
theta=deg2rad(answ);
A=[ cos(theta) -sin(theta)*cos(alpha) sin(theta)*sin(alpha) a*cos(theta)
sin(theta) cos(theta)*cos(alpha) -cos(theta)*sin(alpha) a*sin(theta)
0 sin(alpha) cos(alpha) d
0 0 0 1 ];
else
d=input(' insert the distance[degs] \n ');
a=0;
alpha=0;
theta=0;
A=[ cos(theta) -sin(theta)*cos(alpha) sin(theta)*sin(alpha) a*cos(theta)
sin(theta) cos(theta)*cos(alpha) -cos(theta)*sin(alpha) a*sin(theta)
0 sin(alpha) cos(alpha) d ];
end
frame0=frame0*A;
frame1=frame0*frame1;
delete(frame0V(1));
delete(frame0V(1));
delete(frame0V(1));
frame0V=ReferenceSystem(frame0);
delete(frame1V(1));
delete(frame1V(1));
delete(frame1V(1));
frame1V=ReferenceSystem(frame1);
newLink=frame0*[vertices ones(8,1)]';
newLink2=frame1*[vertices ones(8,1)]';
S.Vertices=double([S.Vertices(1:8,:) ; newLink(1:3,:)' ; newLink2(1:3,:)']);
delete(p);
p=patch(S);
p.FaceVertexCData=[color1; color2 ; color3];
p.FaceColor="flat";
fprintf("second link rotation\n");
if variabile2Tetha
answ=input(' insert the rotation degree[degs] \n ');
a=0;
d=0;
alpha=0;
theta=deg2rad(answ);
A=[ cos(theta) -sin(theta)*cos(alpha) sin(theta)*sin(alpha) a*cos(theta)
sin(theta) cos(theta)*cos(alpha) -cos(theta)*sin(alpha) a*sin(theta)
0 sin(alpha) cos(alpha) d
0 0 0 1 ];
else
d=input(' inserire de distance \n ');
a=0;
alpha=0;
theta=0;
A=[ cos(theta) -sin(theta)*cos(alpha) sin(theta)*sin(alpha) a*cos(theta)
sin(theta) cos(theta)*cos(alpha) -cos(theta)*sin(alpha) a*sin(theta)
0 sin(alpha) cos(alpha) d
0 0 0 1 ];
end
frame1=frame1*A;
delete(frame1V(1));
delete(frame1V(1));
delete(frame1V(1));
frame1V=ReferenceSystem(frame1);
newLink2=frame1*[vertices ones(8,1)]';
S.Vertices=double([S.Vertices(1:16,:) ; newLink2(1:3,:)']);
delete(p);
p=patch(S);
p.FaceVertexCData=[color1; color2 ; color3];
p.FaceColor="flat";
function [q1,q2,q3]=ReferenceSystem(frame)
q1 =quiver3(frame(1,4),frame(2,4),frame(3,4),frame(1,1),frame(2,1),frame(3,1), 'Color', 'r');
q1.LineWidth=3;
q1.AutoScaleFactor=8;
q2 = quiver3(frame(1,4),frame(2,4),frame(3,4),frame(1,2),frame(2,2), frame(3,2), 'Color', 'g');
q2.LineWidth=3;
q2.AutoScaleFactor=8;
q3 = quiver3(frame(1,4),frame(2,4),frame(3,4),frame(1,3),frame(2,3), frame(3,3), 'Color', 'b');
q3.LineWidth=3;
q3.AutoScaleFactor=10;
in this script I'm trying to realize a robotic harm movement . I use quiver objects to represent different reference frame . But when i try to change my frame , deleting the previous frame , it happens that a frame's quiver doesn't deleted.
So i'm looking for a effective method for delete my quiver object .

Antworten (0)

Kategorien

Mehr zu Vector Fields finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by