results of 2 plots seem to be overlapping each other

1 次查看(过去 30 天)
i have generated a virtual 3D cube. after that i am asked to capture an image of that virtual cube in at 4 meters distance and 30 degree tilted. i am able to do that too. but in both cases 2 plots of 2 images are supposed to be generated. but the result of the second plotting seems to be overlapping the previous plotting image. if i give a 'break' command in between these 2 code then i can see the previous plot again. but if i delete the break command then i can only see the 2nd plot. please let me know how to solve this.
%question 6(3)(a)
%generating a virtual 3D cube
%%Generating 3D calibration pattern:
%%Pw holds 32 points on two surfaces (Xw = 1 and Yw = 1) of a cube
%%Values are measured in meters.
%%There are 4x4 uniformly distributed points on each surface.
cnt = 1;
%%plane : Xw = 1
Pw = zeros(4,3);%preallocating Pw
for i=0.2:0.2:0.8,
for j=0.2:0.2:0.8,
Pw(cnt,:) = [1 i j];
cnt = cnt + 1;
end
end
%%plane : Yw = 1
for i=0.2:0.2:0.8,
for j=0.2:0.2:0.8,
Pw(cnt,:) = [i 1 j];
cnt = cnt + 1;
end
end
N = cnt;
%%plot3(Pw(:,1), Pw(:,2), Pw(:,3), '+');
%%Virtual camera model
%%Extrinsic parameters : R = RaRbRr
gamma = 40.0*pi/180.0;
Rr = [ [cos(gamma) -sin(gamma) 0];
[sin(gamma) cos(gamma) 0];
[ 0 0 1]; ];
beta = 0.0*pi/180.0;
Rb = [ [cos(beta) 0 -sin(beta)];
[0 1 0];
[sin(beta) 0 cos(beta)]; ];
alpha = -120.0*pi/180.0;
Ra = [ [1 0 0];
[0 cos(alpha) -sin(alpha)];
[0 sin(alpha) cos(alpha)]; ];
R = Ra*Rb*Rr;
T = [0 0 4]';
%%Intrinsic parameters
fa = 0.016;
Ox = 256;
Oy = 256;
Sx = 0.0088/512.0;
Sy = 0.0066/512.0;
Fx = fa/Sx;
Fy = fa/Sy;
%%asr is the aspect ratio
asr = Fx/Fy;
%%Generate Image coordinates
%%surface Xw = 1
cnt = 1;
Pc = zeros(16,3);
n=length([(Ox - Fx*Pc(cnt,1)/Pc(cnt,3)) (Oy - Fy*Pc(cnt,2)/Pc(cnt,3))]);
p=zeros(16,n);
for cnt = 1:1:16,
Pc(cnt,:) = (R*Pw(cnt,:)' + T)';
p(cnt,:) = [(Ox - Fx*Pc(cnt,1)/Pc(cnt,3)) (Oy - Fy*Pc(cnt,2)/Pc(cnt,3))];
end
plot(p(:,1), p(:,2), 'r+');
axis([0 512 0 512]);
grid;
hold;
%%surface Yw = 1
for cnt = 17:1:32,
Pc(cnt,:) = (R*Pw(cnt,:)' + T)';
p(cnt,:) = [(Ox - Fx*Pc(cnt,1)/Pc(cnt,3)) (Oy - Fy*Pc(cnt,2)/Pc(cnt,3))];
end
plot(p(17:32,1), p(17:32,2), 'g+');
%%plot3(Pc(:,1), Pc(:,2), Pc(:,3), '+');
grid;
%3D point generated from the 3D virtual cube
xvals = Pc(:,1);
yvals = Pc(:,2);
zvals = Pc(:,3);
%..6.3.b
cnt1 = 1;
%%plane : Xw = 1
Pw1 = zeros(4,3);%preallocating Pw
for i=0.2:0.2:0.8,
for j=0.2:0.2:0.8,
Pw1(cnt1,:) = [1 i j];
cnt1 = cnt1 + 1;
end
end
%%plane : Yw = 1
for i=0.2:0.2:0.8,
for j=0.2:0.2:0.8,
Pw1(cnt1,:) = [i 1 j];
cnt1 = cnt1 + 1;
end
end
N1 = cnt1;
%%plot3(Pw(:,1), Pw(:,2), Pw(:,3), '+');
%%Virtual camera model
%%Extrinsic parameters : in a certain pose where R = 30 degree and T is 4 meters
Rb1 = 30.0*pi/180.0;
Tb = [0 0 4]';
%%Intrinsic parameters
fb = 0.016;
Ox = 256;
Oy = 256;
Sx = 0.0088/512.0;
Sy = 0.0066/512.0;
Fxb = fb/Sx;
Fyb = fb/Sy;
%%asr is the aspect ratio
asrb = Fxb/Fyb;
%%Generate Image coordinates
%%surface Xw = 1
cnt1 = 1;
Pc1 = zeros(16,3);
n1=length([(Ox - Fxb*Pc1(cnt1,1)/Pc1(cnt1,3)) (Oy - Fyb*Pc1(cnt1,2)/Pc1(cnt1,3))]);
p1=zeros(16,n1);
for cnt = 1:1:16,
Pc1(cnt,:) = (Rb1*Pw1(cnt1,:)' + Tb)';
p1(cnt,:) = [(Ox - Fxb*Pc1(cnt1,1)/Pc1(cnt1,3)) (Oy - Fyb*Pc1(cnt1,2)/Pc1(cnt1,3))];
end
plot(p1(:,1), p1(:,2), 'r+');
axis([0 512 0 512]);
grid;
hold;
%%surface Yw = 1
for cnt1 = 17:1:32,
Pc1(cnt1,:) = (Rb*Pw1(cnt1,:)' + Tb)';
p1(cnt1,:) = [(Ox - Fxb*Pc1(cnt1,1)/Pc1(cnt1,3)) (Oy - Fyb*Pc1(cnt1,2)/Pc1(cnt1,3))];
end
plot(p1(17:32,1), p1(17:32,2), 'g+');
%%plot3(Pc1(:,1), Pc(:,2), Pc(:,3), '+');
grid;

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by