PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/utils/ellipse.m

http://slac-lucretia.googlecode.com/
MATLAB | 55 lines | 23 code | 5 blank | 27 comment | 2 complexity | f4bd540e7a278f82e0beb39ead665c9e MD5 | raw file
Possible License(s): BSD-2-Clause
  1. function [x,y]=ellipse(X,p,q)
  2. % function [x,y]=ellipse(X,p,q)
  3. %
  4. % Return coordinates which can be used to plot the ellipse described by the
  5. % 2x2 symmetric matrix "X", centered at the point (p,q).
  6. %
  7. % INPUTS:
  8. %
  9. % X: a 2x2 symmetric matrix which describes the ellipse as follows:
  10. %
  11. % [x y]*X*[x y]' = 1,
  12. %
  13. % or, with X = [a b
  14. % b c],
  15. %
  16. % ax^2 + 2bxy + cy^2 = 1;
  17. %
  18. % for a beam ellipse, X=inv(sigma)=(1/emit)*[gamma alpha
  19. % alpha beta]
  20. %
  21. % p: ordinate of ellipse center
  22. % q: abscissa of ellipse center
  23. %
  24. % OUTPUTS:
  25. %
  26. % x: a 1001 element column vector of x-coordinates
  27. % y: a 1001 element column vector of y-coordinates
  28. %===============================================================================
  29. [r,c]=size(X);
  30. if ((r~=2)|(c~=2))
  31. error('X must be a 2x2 matrix')
  32. end
  33. if (abs(X(1,2)-X(2,1))>(abs(.001*X(1,2))+eps))
  34. error('X must be a symmetric matrix')
  35. end
  36. a=X(1,1);
  37. b=X(1,2);
  38. c=X(2,2);
  39. delta=0.001;
  40. theta=[0:delta:pi]';
  41. C=cos(theta);
  42. S=sin(theta);
  43. r=sqrt((a*(C.^2)+2*b*(C.*S)+c*(S.^2)).^(-1));
  44. r=[r,r];
  45. C=[C,-C];
  46. S=[S,-S];
  47. x=r.*C;
  48. y=r.*S;