Animations in SciLab - scilab

I want to plot the trajectory of a simple spring mass system using SciLab. I have successfully managed to plot a graph of x vs t. Now I want to make a gif of the trajectory of the body with respect to time (something like this https://www.youtube.com/watch?v=kAl4XATyke4). How am I supposed to go about it? Attached is my progress till now.
//Input the spring constant k, mass m. and the initial values of x and x dot. The code will plot both x (in red) and x dot (in green)
function sol = spingmass(k,m,x_initial,xdot_initial,time)
osqr = k/m;
function dx = f(t,x)
dx(1)=x(2);
dx(2)=-1*osqr*x(1);
endfunction
t = 0:0.1:10;
sol = ode([x_initial;xdot_initial],time,t,f);
clf;
plot(t,sol(1,:),'r');
plot(t,sol(2,:),'g');
//disp(sol);
endfunction

You will be able to build an animated GIF with a series of Scilab snapshots of a graphical figure thanks to the animaGIF toolbox available # https://atoms.scilab.org/toolboxes/animaGIF
It is a standalone toolbox. No dependency like imageMagick or other GIMP is required.
The single animaGIF() function of the toolbox is extensively documented.
The documentation includes some animated GIF figures, moving in the Scilab help browser. Enjoy!

Related

Creating a 3D "ribbon" style plot in R

I want to plot the recorded path of an object such as a plane or drone in 3d space using R. The plotted path should be represented by a flat “ribbon” whose orientation perpendicular to the direction of travel changes to reflect the roll of the object. In other words, I want to be able to visualize the path and orientation of the object in one "ribbon" as it banks in turns.
As far as as I can tell, a traditional ribbon plot in R won't allow you to change the orientation in a third dimension.
Matlab and Python have functionality for creating quiver plots where arrows may be placed to indicate the xyz orientation of the object at a given point in time along the path. I cannot find any R packages with similar functionality.
I have played with Plot3D, Plotrgl, Plot3Drgl and cannot find a package that has this capability.
Q1: Are there any packages in R that would support this type of plot?
Q2: If there isn't, how can I go about creating this type of plot R?
Below are examples in Python and Matlab for the 3D quiver type plots, as well as an image demonstrating the ribbon concept I am imagining.
https://medium.com/analytics-vidhya/exploring-data-acquisition-and-trajectory-tracking-with-android-devices-and-python-9fdef38f25ee
Example of 3D quiver plot in python
https://github.com/xioTechnologies/Gait-Tracking-With-x-IMU
Example of 3D quiver plot in matlab
This is an example of what the "ribbon" would look like
Thanks for any help!

How to change light settings for a 3d plot in sage?

I try to plot a gyroid surface in sage which is defined implicitly. However, I get reflections of the light source on my surface which do not look very good. How can I change light settings for the 3d plots?
I tried to set different texture properties for my surface, but the changes showed no result. I also tried to set the light source but also without any resulting changes.
x, y, z = var('x,y,z')
def phi_g(x,y,z):
X=x+pi/2
Y=y+pi/2
Z=z+pi/2
return sin(X)*cos(Y)+sin(Y)*cos(Z)+sin(Z)*cos(X)
G1=implicit_plot3d(phi_g(x,y,z)==0.02, (x,0,2*pi), (y,0,2*pi), (z,0,2*pi),color='blue', frame=False, plot_points=80)
G2=implicit_plot3d(phi_g(x,y,z)==-0.02, (x,0,2*pi), (y,0,2*pi), (z,0,2*pi),color='red', frame=False, plot_points=80)
C=cube(center=(pi, pi, pi), size=2*pi, color='grey', opacity=0.1)
G=G1+G2+C
plot_G=G.plot()
plot_G.save('g.png',figsize=20,zoom=1.27)
I would like to have the output without any reflections of the light source on the surface.
I don't really use it much, but I think the Tachyon ray-tracer in Sage can do a lot of what you are looking for. I don't know if the implicit_plot3d fully supports these things in the default viewer.

How to draw scrolling graphics in R, like financial time series

I would like to draw financial time series in R, that are continuously updated all along the day. Sometimes I can have several updates per second and I want to draw the time series as it evolves.
Moreover, I want to improve my graphics with extra information that I will plot too on the same graph (not necessarily a time series).
So I wonder if there is either:
a package in R to draw such series and have them scroll automatically as soon as I push new data
or a way to do bit blit in R and simply update my graph,
or a way to use packages like grid or anything else that would draw what is necessary (at least lines and points) and help scroll the data quickly to have a smooth rendering.
I would like something a bit more modern than a TCL/TK solution like explained here
We are doing this with shiny and a timer variable which refreshes the plot every n seconds.
R itself isn't really made for continuous updates. The (default) graphics device is static (so you can't easily 'append one point'), and there is only one event loop.
You can do it with external programs -- I have used both custom Qt applications I wrote for this as well as custom data handler in the (awesome, under-appreciated) kst real-time visualization program.
I'm not on financial data, but if the data file is itself updated along the day, the simplest solution would be something like:
k <- 0
while ( k<=3600 ) {
foo <- read.table("data.txt")
plot(foo[,1], foo[,2])
Sys.sleep(60) # seconds
k <- k+1
}
This would redraw the plot each 60 seconds. You can put a web adress for the data instead of "data.txt" also. To "scroll", you can play with the xlim argument to plot().

using a graph in R in Powerpoint

I have certain x and y coordinates for the position of an animal for a certain time t-max. I am using the code in R:
for (t in 1:tmax) {
plot(x[1:t],y[1:t]);
Sys.sleep(0.1);
}
to see how the animal is moving with time. So this shows me the path from each value of x to the subsequent value, till tmax. So now i have to present my findings in a Powerpoint presentation. so i was wondering if there is a method to insert this graph in a slide so that when i click a button, the graph is plotted and everybody can understand how the animal is moving.
Have a look on the Animation-Package on Cran:
http://cran.r-project.org/web/packages/animation/index.html
The animations package is cool, but i found it hard to learn. Instead of sleeping after each point is plotted, you could save the graph, and then use a video editor to merge the graphs into a movie clip. Windows movie maker will do this for you.
I'm not a big fan of animation, and in this case it doesn't seem useful. Why not just plot the graph, or if the path is seriously tangled, plot with a rainbow colormap applied to the line so you can easily follow from start to finish? See plotrix::color.scale.lines

Is there an interactive output device to view 3D graphs in R?

I'm currently generating 3D graphs in R using the persp-command. To change the viewpoint one has to set the parameters theta and phi. To evaluate (a good viewpoint on) the graph, one has to try lots of combinations for these parameters.
I was wondering if one can define an interactive output device that allows to rotate the graph using the mouse. It would be also nice if this device gives the current values for theta and phi.
Is there such a device/package?
See the rgl package: http://cran.r-project.org/web/packages/rgl/index.html
It won't report the theta and phi values you need, IIRC (though see #Dieter's comment below for a solution to this), but you can use rgl.snapshot() or rgl.postscript() to grab the current display as a bitmap or vector image. The package has persp3d() which is very similar to persp().
See the package rggobi http://cran.r-project.org/web/packages/rggobi/index.html
For data visualisation in 3 or even more dimensions, try the package rggobi which makes use of the program ggobi. It is possible to manipulate the data using the mouse, "brush" data, identify points in the data all while visualizing in a number of dimensions.

Resources