The code generates radius of curvatures for three points(coordinates x1,y1 x2,y2 and x3,y3. However, i have a set of coordinates (77) in all, and I am trying to rewrite the code to loop through the coordinates and generate a radius of curvature for every three points within the set of 77, and store the result in another variable say R. I have not been able to do this and I need urgent help: See the radius of curvature code below that generates when radius of curvature for 3 points.
function lambda=mycurvature(xinput, yinput)global xstar ystar;xstar=xinput;ystar=yinput;alpha=atan2(ystar(2)-ystar(1),xstar(2)-xstar(1))-atan2(ystar(3)-ystar(2),xstar(3)-xstar(2));if abs(alpha)<0.002; %set the curvature to 0 if the points are aligned
R=inf; lambda=0;%plot(xstar,ystar,'-r',xstar,ystar,'*b','linewidth',2,'markersize',10);
elseinitialguess = [1; 1; 1]; % Make a starting guess at the solution
options=optimset('Display','none'); % Option to display output
res = fsolve(@userfun,initialguess,options); % Call optimizer
x0=res(1);y0=res(2);R=res(3); %x-coord of center; y-coord of center; radius of curvature
lambda=1/R; %curvature
%t=0:0.01:2*pi;xx=x0+R*cos(t);yy=y0+R*sin(t);
%plot(xx,yy,'-r',xstar,ystar,'*b','linewidth',2,'markersize',10);
end%str=sprintf('radius=%6.3f, curvature=%6.3f',R,lambda);
%title(str, 'fontsize', 14);xlabel('x'),ylabel('y');
%axis equal;
function F = userfun(vars)global xstar ystar;F = [...(xstar(1)-vars(1))^2+(ystar(1)-vars(2))^2-(vars(3))^2; ...(xstar(2)-vars(1))^2+(ystar(2)-vars(2))^2-(vars(3))^2; ...(xstar(3)-vars(1))^2+(ystar(3)-vars(2))^2-(vars(3))^2; ... ];
xinput are the array of x coordinates for the three points, yinput are the array of y coordinates for the 3 points.
What i am doing that is not working is
x = [array of my x-coordinates of my 77 points]; y =[array of my y-coordinates of my 77 points]for i = 1:3:length(x)-1xinput = x(i), x(i+1), x(i+2)yinput = y(i), y(i+1), y(i+2)
and then removed the function at the first line of code for the radius of curvature code above. This did not work. What am I doing wrong? Please help.
Best Answer