Advertisement
Guest User

cube_function

a guest
May 13th, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.16 KB | None | 0 0
  1. function varargout = cube(pos,width,ccolor)
  2. %CUBE Generate a three-dimensional cube
  3. % CUBE(P, W, C) creates a surface plot of a cube with one corner defined
  4. % by the 3-element vector P, the width in each dimension defined by the
  5. % 3-element vector W, and the color index into the current colormap
  6. % defined by the scalar C.
  7. %
  8. % H = CUBE(...) creates the surface plot and returns the handle H to each
  9. % graphical object created.
  10. %
  11. % [X Y Z C] = CUBE(...) does not generate the surface plot and returns
  12. % the data necessary to create the surface using:
  13. % SURF(X,Y,Z,C,'cdataMapping','direct');
  14. %
  15. % Example:
  16. % cube([2 3 1], [1 1 2], 60)
  17. % axis([0 5 0 5 0 5])
  18.  
  19. x = [NaN 0 1 NaN;0 0 1 1;0 0 1 1;...
  20.   NaN 0 1 NaN;NaN 0 1 NaN;NaN NaN NaN NaN]*...
  21. width(1) + pos(1);
  22. y = [NaN 0 0 NaN;0 0 0 0;1 1 1 1;...
  23.   NaN 1 1 NaN;NaN 0 0 NaN;NaN NaN NaN NaN]*...
  24. width(2) + pos(2);
  25. z = [NaN 0 0 NaN;0 1 1 0;0 1 1 0;...
  26.   NaN 0 0 NaN;NaN 0 0 NaN;NaN NaN NaN NaN]*...
  27. width(3) + pos(3);
  28. c = ccolor*ones(6,4);
  29. if nargout == 0
  30.   surf(x,y,z,c,'cdataMapping','direct');
  31. elseif nargout == 1
  32.   varargout = {surf(x,y,z,c,'cdataMapping','direct')};
  33. else
  34.   varargout = {x y z c};
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement