how to assign 3D points? i have 3D points on graph but i need to use those points as a variable in equation

i have generated a virtual 3D cube. as a result a graph is generated and on the graph, at each surface there are 4x4 points. i need to use those points as variables for an equation. can you please tell me how to assign some points that are on a graph, to a variable? this is the code
%%Generate 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,%it means it starts from 0.2 gives an interval 0.2 and goes till 0.8
for j=0.2:0.2:0.8,
Pw(cnt,:) = [1 i j];%is the cnt-th row of pw , pw is a matrix whos cnt-th row is a row matrix, cnt is a variable that starts from 1 and after forming
%the row matrix, it goes on till i and j conditions are fulfilled.
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
f = 0.016;
Ox = 256;
Oy = 256;
Sx = 0.0088/512.0;
Sy = 0.0066/512.0;
Fx = f/Sx;
Fy = f/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;
this is the graph
please open the picture in new tab to preview the graph.. thank you

 Accepted Answer

You seem to already have them in your variable "Pc".

7 Comments

so if i do, for example
x1 = Pc(1)
x2 = Pc(2)
....
then can i assign these points to variable x1, x2? please let me know
xvals = Pc(:,1);
yvals = Pc(:,2);
zvals = Pc(:,3);
x1 = xvals(1);
x2 = xvals(2);
etc.
thank you. it worked...i can get 16 different points in 4 sets as. are these 2D points? if yes, then how can i know which are the x and y coordinates? and from there, how can i get the 3D points? please let me know
there are 32 values for each x, y, and z.. so instead of assigning 96 values manually, i would like to write something as
for h (from 1 till 32 with a gap 1)
xdh=xvals(h);
ydh=yvals(h);
zdh=zvals(h);
end
disp(xdh);
disp(ydh);
disp(zdh);
can you tell me how to write [for h (from 1 till 32 with a gap of 1)] in matlab format? where h is just a number. i tried 1:1:32 but i suppose this format only works for array.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!