{"id":4891,"date":"2013-11-01T09:00:42","date_gmt":"2013-11-01T13:00:42","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4891"},"modified":"2013-10-31T08:22:36","modified_gmt":"2013-10-31T12:22:36","slug":"comet3-with-speed-control","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/11\/01\/comet3-with-speed-control\/","title":{"rendered":"Comet3 with Speed Control"},"content":{"rendered":"\r\n\r\n<div class=\"content\"><p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/43629-3d-comet-plot\">3D Comet Plot<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/387115\">Nick<\/a>.<\/p><p>As a continuation to one of my previous posts, on <a href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/06\/28\/multi-line-comet-plot\/\">multi-line comet plots<\/a>, this submission extends <a href=\"\"><tt>comet3<\/tt><\/a> to give the user ability to control the length of the tail, the speed of the animation, and the style of the head and tail of the comet. <tt>comet<\/tt> and <tt>comet3<\/tt> are useful functions, because these are functions that take similar type of input as other plotting functions and have animation built into them. I have used both of these functions in the past, but as computers became faster, the animation became too fast to view. That's why I really like the ability of <tt>PlotComet_3D<\/tt> to control the speed.<\/p><p>Here's what <tt>comet3<\/tt> looks like.<\/p><pre class=\"language-matlab\">t = -pi:pi\/300:pi;\r\nx = sin(5*t);\r\ny = cos(3*t);\r\nz = t;\r\n<\/pre><pre class=\"language-matlab\">comet3(x, y, z)\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_plotcomet3d\/comet3.gif\" alt=\"\"> <\/p><p>By using Nick's <tt>PlotComet_3D<\/tt>, you can specify the speed in frequency, allowing for a consistent animation regardless of processing speed. Here, I'm also specifying a particular marker for the head of the comet.<\/p><pre class=\"language-matlab\"><span class=\"comment\">% Define marker style for the head of the comet<\/span>\r\nHead = struct(<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'Marker'<\/span>, <span class=\"string\">'p'<\/span>, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'MarkerSize'<\/span>, 10, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'MarkerEdgeColor'<\/span>, <span class=\"string\">'b'<\/span>, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'MarkerFaceColor'<\/span>, <span class=\"string\">'b'<\/span>);\r\n<\/pre><pre class=\"language-matlab\"><span class=\"comment\">% Animate at 100 Hz, tail length of 30<\/span>\r\nPlotComet_3D(x, y, z, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'Frequency'<\/span>, 100, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'blockSize'<\/span>, 30, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'headFormat'<\/span>, Head);\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_plotcomet3d\/new_comet3.gif\" alt=\"\"> <\/p><p><b>Comments<\/b><\/p><p>If you have used <tt>comet<\/tt> or <tt>comet3<\/tt> in the past and stopped using it because the animation has gotten too fast, give this a try. Let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4891#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/43629-3d-comet-plot#comments\">comment<\/a> for Nick.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_523347e7ed2a4732b67e2074a3f882c4() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='523347e7ed2a4732b67e2074a3f882c4 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 523347e7ed2a4732b67e2074a3f882c4';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_523347e7ed2a4732b67e2074a3f882c4()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><\/div><!--\r\n523347e7ed2a4732b67e2074a3f882c4 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/43629-3d-comet-plot 3D Comet Plot>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/387115\r\n% Nick>.\r\n%\r\n% As a continuation to one of my previous posts, on\r\n% <https:\/\/blogs.mathworks.com\/pick\/2013\/06\/28\/multi-line-comet-plot\/\r\n% multi-line comet plots>, this submission extends\r\n% <\r\n% |comet3|> to give the user ability to control the length of the tail, the\r\n% speed of the animation, and the style of the head and tail of the comet.\r\n% |comet| and |comet3| are useful functions, because these are functions\r\n% that take similar type of input as other plotting functions and have\r\n% animation built into them. I have used both of these functions in the\r\n% past, but as computers became faster, the animation became too fast to\r\n% view. That's why I really like the ability of |PlotComet_3D| to control\r\n% the speed.\r\n%\r\n% Here's what |comet3| looks like.\r\n%\r\n%   t = -pi:pi\/300:pi;\r\n%   x = sin(5*t);\r\n%   y = cos(3*t);\r\n%   z = t;\r\n% \r\n%   comet3(x, y, z)\r\n% \r\n% <<comet3.gif>>\r\n%\r\n% By using Nick's |PlotComet_3D|, you can specify the speed in frequency,\r\n% allowing for a consistent animation regardless of processing speed. Here,\r\n% I'm also specifying a particular marker for the head of the comet.\r\n%\r\n%   % Define marker style for the head of the comet\r\n%   Head = struct(...\r\n%       'Marker', 'p', ...\r\n%       'MarkerSize', 10, ...\r\n%       'MarkerEdgeColor', 'b', ...\r\n%       'MarkerFaceColor', 'b');\r\n% \r\n%   % Animate at 100 Hz, tail length of 30\r\n%   PlotComet_3D(x, y, z, ...\r\n%       'Frequency', 100, ...\r\n%       'blockSize', 30, ...\r\n%       'headFormat', Head);\r\n%\r\n% <<new_comet3.gif>>\r\n%\r\n% *Comments*\r\n%\r\n% If you have used |comet| or |comet3| in the past and stopped using it\r\n% because the animation has gotten too fast, give this a try. Let us know\r\n% what you think <https:\/\/blogs.mathworks.com\/pick\/?p=4891#respond here> or\r\n% leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/43629-3d-comet-plot#comments\r\n% comment> for Nick.\r\n\r\n##### SOURCE END ##### 523347e7ed2a4732b67e2074a3f882c4\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_plotcomet3d\/comet3.gif\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n\r\nJiro's pick this week is 3D Comet Plot by Nick.As a continuation to one of my previous posts, on multi-line comet plots, this submission extends comet3 to give the user ability to control the... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/11\/01\/comet3-with-speed-control\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4891"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4891"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4891\/revisions"}],"predecessor-version":[{"id":4894,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4891\/revisions\/4894"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}