Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function[] = qspline2 (xCor,yCor)
- n=length(xCor);
- syms x;
- syms t;
- for i=1:n
- P(i,1)=xCor(i);
- P(i,2)=yCor(i);
- end
- S=sym(zeros(n,2));
- for i=1:n-1
- prev=i-1;
- next=i+1;
- nextNext=i+2;
- if i==1
- prev=n;
- elseif i==n
- next=1;
- nextNext=2;
- elseif i==n-1
- nextNext=1;
- end
- middle=P(next,:)-P(i,:);
- tan1=(P(next,:)-P(prev,:))*(abs(middle/(P(next,:)-P(prev,:))));
- tan2=(P(nextNext,:)-P(i,:))*(abs(middle)/(P(nextNext,:)-P(i,:)));
- a=tan1+tan2-2*middle;
- b=3*middle-tan2-2*tan1;
- c=tan1;
- S(i,:)=a*t^3+b*t^2+c*t+P(1,:);
- end
- for i=[1:n-1]
- eq1= S(1)-xCor(i);
- eq2= S(1)-xCor(i+1);
- a1=solve(eq1)
- a2=solve(eq2)
- a1= a1(1)
- a2= a2(1)
- fy=matlabFunction((S(i,2)))
- fplot(fy, [a1 a2]); hold on;
- plot(eq1(1),yCor(i),'*');hold on;
- %for i=[1:n-1]
- %fx=matlabFunction(S(i,1));
- %fy=matlabFunction((S(i,2)));
- %fplot(fx,[0 1]); hold on;
- %fplot(fy, [0 1]); hold on;
- %end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement