Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. function[] = qspline2 (xCor,yCor)
  2. n=length(xCor);
  3. syms x;
  4. syms t;
  5. for i=1:n
  6. P(i,1)=xCor(i);
  7. P(i,2)=yCor(i);
  8. end
  9.  
  10. S=sym(zeros(n,2));
  11. for i=1:n-1
  12. prev=i-1;
  13. next=i+1;
  14. nextNext=i+2;
  15. if i==1
  16. prev=n;
  17. elseif i==n
  18. next=1;
  19. nextNext=2;
  20. elseif i==n-1
  21. nextNext=1;
  22. end
  23. middle=P(next,:)-P(i,:);
  24. tan1=(P(next,:)-P(prev,:))*(abs(middle/(P(next,:)-P(prev,:))));
  25. tan2=(P(nextNext,:)-P(i,:))*(abs(middle)/(P(nextNext,:)-P(i,:)));
  26. a=tan1+tan2-2*middle;
  27. b=3*middle-tan2-2*tan1;
  28. c=tan1;
  29. S(i,:)=a*t^3+b*t^2+c*t+P(1,:);
  30.  
  31. end
  32. for i=[1:n-1]
  33. eq1= S(1)-xCor(i);
  34. eq2= S(1)-xCor(i+1);
  35. a1=solve(eq1)
  36. a2=solve(eq2)
  37. a1= a1(1)
  38. a2= a2(1)
  39. fy=matlabFunction((S(i,2)))
  40. fplot(fy, [a1 a2]); hold on;
  41. plot(eq1(1),yCor(i),'*');hold on;
  42. %for i=[1:n-1]
  43. %fx=matlabFunction(S(i,1));
  44. %fy=matlabFunction((S(i,2)));
  45. %fplot(fx,[0 1]); hold on;
  46. %fplot(fy, [0 1]); hold on;
  47. %end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement