# Repetetion of x,z,b,c value simulataneous

1 view (last 30 days)
Kundan Prasad on 28 Dec 2021
Answered: Walter Roberson on 30 Dec 2021
I am unable to repeat the x,z,c,b value simultaneously. I have attached the final plot to be obtained.
Please look into the problem
Thank you
%% to find the cloud points of xzbc
%% to calculate the number of grating on primary surface
clc
clear all
R=30; %% radius of curvature
W=0.0125; %% width of grating
r=10; %% radius of workpiece
th_1=(asin(W/R)); %% angle at which blazed grating existd
degr=(180*th_1)/pi; %% conversion into degree
th_2=2*(asin(r/R)); %% angle at which primary profile exists
degr_2=(180*th_2)/pi; %% conversion into degree
n=round(degr_2/degr); %% number of grating
%% to generate the primary profile
for i=1:n
th (i)= ((i*th_1)-((th_2)/2));
deg (i)=(180*th (i))/pi;
x(i)= -(R*cos(th (i)));
z(i)= (R*sin(th (i)));
end
X1=x;
Z1=z;
figure (1)
% plot(X1,Z1); hold on
%% to calculate the B-axis Coordinate
th_3=0.144; %% blazed grating angle
degr_3=8.25;
for i=1:n
th (i)= ((i*th_1)-((th_2)/2));
b(i)= th (i)+th_3;
deg_2(i)= (180*b(i))/pi;
end
B1=b;
% figure (1)
% plot(B1); hold on
% figure (2)
% plot3(X1,Z1,B1);
% x2=x;
% z2=z;
%% Cutting action i.e. XZBC Calculation
th_4=0.017; %% radial data resolution in radian
m= round(th_2/th_4)-1; %%
for j=1:m
c(j)=((j*th_4-(th_2/2))*(180/pi)); %% to extract C-axis coordinate
end
c2=c;
b2=b;
x2=x;
z2=z;
%% Non-cutting action i.e. XZBC Calculation
p=round(((2*pi)-th_2)/(th_4));
for i=1:n-1
for k=1:p
X(k)= x(i)+((k*(x(i+1)-x(i))/p));
Z(k)= z(i)+(k*(z(i+1)-z(i))/p);
C(k)=((m*th_4-(th_2/2)+k*th_4)*(180/pi));
B(k)= b(i)+(k*(b(i+1)-b(i))/p);
end
end
newx= X1+X;
newz= Z1+x;
plot(newx,newz);
% xrep= repelem(X,3);
% zrep= repelem(Z,3);
% crep= repelem(C,3);
% brep= repelem(B,3);
% plot(xrep,zrep);
% C= [0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360];
% X= [30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30];
% Z= [0.984 0.985 0.986 0.987 0.988 0.989 0.99 0.991 0.992 0.993 0.994 0.995 0.996 0.997 0.998 0.999 1.000 1.000 1.000 1.000 1.000 1.001 1.002 1.003 1.004 1.005 1.006 1.007 1.008 1.009 1.01 1.011 1.012 1.013 1.014 1.015 1.016];
% B=[0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.139 0.14 0.14 0.14 0.14 0.14 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141 0.141];
%
% plot3(Z,C,B);
Kundan Prasad on 30 Dec 2021
Sir please find the attahced pdf

Walter Roberson on 30 Dec 2021
%% to find the cloud points of xzbc
%% to calculate the number of grating on primary surface
clc
clear all
R=30; %% radius of curvature
W=0.0125; %% width of grating
r=10; %% radius of workpiece
th_1=(asin(W/R)); %% angle at which blazed grating existd
degr=(180*th_1)/pi; %% conversion into degree
th_2=2*(asin(r/R)); %% angle at which primary profile exists
degr_2=(180*th_2)/pi; %% conversion into degree
n=round(degr_2/degr); %% number of grating
%% to generate the primary profile
for i=1:n
th (i)= ((i*th_1)-((th_2)/2));
deg (i)=(180*th (i))/pi;
x(i)= -(R*cos(th (i)));
z(i)= (R*sin(th (i)));
end
X1=x;
Z1=z;
figure (1)
% plot(X1,Z1); hold on
%% to calculate the B-axis Coordinate
th_3=0.144; %% blazed grating angle
degr_3=8.25;
for i=1:n
th (i)= ((i*th_1)-((th_2)/2));
b(i)= th (i)+th_3;
deg_2(i)= (180*b(i))/pi;
end
B1=b;
% figure (1)
% plot(B1); hold on
% figure (2)
% plot3(X1,Z1,B1);
% x2=x;
% z2=z;
%% Cutting action i.e. XZBC Calculation
th_4=0.017; %% radial data resolution in radian
m= round(th_2/th_4)-1; %%
for j=1:m
c(j)=((j*th_4-(th_2/2))*(180/pi)); %% to extract C-axis coordinate
end
c2=c;
b2=b;
x2=x;
z2=z;
%% Non-cutting action i.e. XZBC Calculation
p=round(((2*pi)-th_2)/(th_4));
for i=1:n-1
for k=1:p
X(p,k)= x(i)+((k*(x(i+1)-x(i))/p));
Z(p,k)= z(i)+(k*(z(i+1)-z(i))/p);
C(p,k)=((m*th_4-(th_2/2)+k*th_4)*(180/pi));
B(p,k)= b(i)+(k*(b(i+1)-b(i))/p);
end
end
subplot(4,1,1); surf(X, 'edgecolor', 'none'); title('X'); xlabel('k'); ylabel('i');
subplot(4,1,2); surf(Z, 'edgecolor', 'none'); title('Z'); xlabel('k'); ylabel('i');
subplot(4,1,3); surf(C, 'edgecolor', 'none'); title('C'); xlabel('k'); ylabel('i');
subplot(4,1,4); surf(B, 'edgecolor', 'none'); title('B'); xlabel('k'); ylabel('i');
whos
Name Size Bytes Class Attributes B 330x330 871200 double B1 1x1631 13048 double C 330x330 871200 double R 1x1 8 double W 1x1 8 double X 330x330 871200 double X1 1x1631 13048 double Z 330x330 871200 double Z1 1x1631 13048 double b 1x1631 13048 double b2 1x1631 13048 double c 1x39 312 double c2 1x39 312 double deg 1x1631 13048 double deg_2 1x1631 13048 double degr 1x1 8 double degr_2 1x1 8 double degr_3 1x1 8 double i 1x1 8 double j 1x1 8 double k 1x1 8 double m 1x1 8 double n 1x1 8 double p 1x1 8 double r 1x1 8 double th 1x1631 13048 double th_1 1x1 8 double th_2 1x1 8 double th_3 1x1 8 double th_4 1x1 8 double x 1x1631 13048 double x2 1x1631 13048 double z 1x1631 13048 double z2 1x1631 13048 double
%you have a problem. X was just created as 330 x 330, but X1 is 1 x 1361.
%Even if we had only created X as 330 x 1 or 1 x 330 then we would have a
%problem.
newx= X1+X;
Arrays have incompatible sizes for this operation.
newz= Z1+x;
plot(newx, newz)
Maybe you mean X1+x like you have for Z1 ? Speaking of which, wouldn't Z1 + z make more sense for z values?
Anyhow, it is not obvious to me what out of what you calculated (X, Z, B, C) that you want to plot against what. And if you look at the shapes in those variables... are you sure that is what you are expecting with increasing i values?