How to export a 3D animation in Mathematica? - wolfram-mathematica

I'm trying to visualize molecular vibrations in Mathematica and make some 3D animations using commands something like this:
Animate[Graphics3D[{x[t],y[t],z[t]}],{t,tmin,tmax}]
I couldn't find a way to export it. There are official documents for 3D graphics and 2D animations. I tried most of those filetypes but failed. If it's not possible, then a 2D gif being looked at a certain angle is acceptable. Any suggestion will help.

This just worked.
In[1]:= x[t_]:=Sin[t];y[t_]:=Cos[t];z[t_]:=t;
plots = Table[
ParametricPlot3D[{x[a+t], y[a+t], z[a+t]}, {t,0,2 Pi}], {a,5}]
<<<snip plots>>>
In[4]:= ListAnimate[plots]
<<<snip animation>>>
In[5]:= Export["animate.avi", plots]
Out[5]= "animate.avi"
<<<find your file in your Mathematica folder and run your exported animation>>>
All just mimicking the second example in
http://reference.wolfram.com/mathematica/howto/ImportAndExportAnimations.html

Related

Solving an equation in terms of unknown constants wolfram mathematica

I want to solve the following equation. I want to get an expression of x in terms of unknown constants alpha and beta. Does anyone know how to solve this in Matlab or Mathematica?
Thanks.
Here's my one line code in wolfram Mathematica.
'Assuming[alpha>beta>0,Solve[Cos(alpha*Cos(x)) + Cos(beta*Cos(x)) -1.96 ==0,x]] '
Since it doesn't appear simple to get an analytic solution, perhaps a graphic showing the behavior might provide some insight about what to do next.
ListPointPlot3D[Reap[Do[
{alpha, beta, x} = RandomReal[{0, 2 Pi}, 3];
If[alpha > beta,
err = Norm[Cos[alpha*Cos[x]]+Cos[beta*Cos[x]]-1.96];
If[err < .01, Sow[{alpha, beta, x}]]
],{10^6}]][[2, 1]], ViewPoint->{0, -2., 0}]
Once that displays on your monitor you can either adjust the numbers inside that Viewpoint or you might be able to place your mouse inside the graphic, press and hold the left mouse button and drag to rotate the image around.
That graphic seems to show that the solutions lie within a fairly well defined region.
Once you have looked at this then you might bump the range of the random numbers up to {0,4Pi} because it looks like there is more interesting behavior for larger values of alpha and beta.

Three.js rotating and positioning of geometries

I try to write an export of an 3-d plant modelling software to Three.js but got stuck with the rotations and translations of the objects.
So far I tried to use quaternions and transformation matrices but both results are not satisfying. For my tests I use a simple binary tree that originally looks like this:
the results of my export are this:
You can find the code of both export under
http://ufgb966.forst.uni-goettingen.de/three/test2Quaternion.html
http://ufgb966.forst.uni-goettingen.de/three/test2Matrix.html
It seams that my rotations are made around the wrong point. Each rotation should be done around the origin of each geometry. What would be a method to achieve the result I'm looking for?
Just in case you haven't already, you might want to take a look at this: Using Matrices & Object3Ds in THREE and this How to use matrix for transformation, it helped me out. Also note that three.js uses a right handed coordinate system which you probably know.
If you export from blender, try -Z Forward, Y up.
In my opinion you must change sequence of translation and rotation transformations - the problem is in transformations sequence.

SmoothDensityHistogram - Mathematica

I made Monte Carlo simulation of a cone shaped light source - like lighthouse. Then I tried to draw results. I took the points from which the rays have come. Then I tried to draw SmoothDensityHistogram, but I have problems with binning. I know that the most rays came from {0,0,0}, but that is just not obvious from the picture. The center is somehow translated, but it should't be.
Here's a link to picture.
Thanks for help.
try to play with the PlotPoints option. Even value of the parameter could help, even though I cannot reproduce your problem:
tb = Table[{RandomVariate[NormalDistribution[0, 3]],
RandomVariate[NormalDistribution[0, 3]]}, {n, 10000}];
SmoothDensityHistogram[tb, PlotPoints -> 6]

get points of listplot in mathematica

I have a few graphs which took quite some time for calculations. I would like to extract the data of those plots instead of recalculing a list. I found the command pts=Cases[(*I paste graph here*),x_Line:>First#x,Infinity];, which works fine for my line plots but not for listplots. How can I do the same for listplots?
It is essentially the same except for a scatter plot you use point:
Cases[(*pasted graphic*), x_Point :> First#x, Infinity]
It may be instructive to do
(*paste*)//FullForm
Of course you really ought to just save the data before generating the plot..

Possible to put equation's expression near its graphic representation?

Is it possible that when I Plot a function in Mathematica, it will automatically put near it it's equation(i.e. y = 2x) or even some other text?
At first glance I don't find any option for it, but if there is one I'd like to know.
Thanks
Using Mathematica 6 or higher, I often use Tooltip to help me identify plot curves:
Plot[Tooltip[Sin[x]], {x, 0, 8 Pi}]
Alas, this is only useful when using the graph interactively since you must hover the mouse cursor over the curve. It doesn't work so well on paper or on a static image.
You can use the Epilog option to manually place some text on the plot, as in this example:
Plot[
Sin[x], {x, 0, 8 Pi},
Epilog -> Text["My Text", Offset[{32, 0}, {14, Sin[14]}]]
]
Tweak the arguments of Offset to taste.
This works if you do not mind manual placement. Automatic placement poses some challenges, depending upon the kinds of functions that you wish to plot. But if you know something of the general characteristics of the functions of interest, you could write a function that calculates nice looking values for the Offset arguments. For example, if I knew I was going to plot lots of exponential decline functions, I might define something like the function myPlot in this example:
SetAttributes[myPlot, HoldAll]
myPlot[function_, {var_, min_, max_}] :=
Plot[
function, {var, min, max},
Epilog -> Text[function, Offset[{40, 0}, {var, function} /. var -> min + (max - min)/20]],
PlotRange -> All, AxesOrigin -> {0, 0}
]
... where the arguments to Offset are computed automatically using some arbitrary constants that work reasonably well for these kinds of plots:
Manipulate[
myPlot[1000 E^(-d t), {t, 0, 100}, "My Label"],
{d, 0.01, .2}
]
Since all of these options are programmable, the sky's limit as to how much sophistication you could code up for the label placement. Of course, such programming drifts farther and farther away from the ideal of a built-in option to Plot that just magically drops on some text next to the function. Mathematica 8 or 9 maybe :)
One way to do this, which automatically associates the expression with the style used to plot it, is to use the PlotLegends standard add-on package. The output doesn't look very good by default; I recommend setting the LegendShadow -> None option and using Style on the expressions you stick in the legend to make them look better. Also, loading the package inflicts some funny redefinitions on Plot and related functions which can break some other things if you're not careful.
"Near its equation" is the problem. This isn't an easy problem to solve, and it becomes somewhat impossible when you start getting "busy" graphs with overlapping plots and so on.
I don't have a good example to show, but usually I'll define a "labelling function" that takes the same input as the function being plotted, which places a dot on the graph and writes some text nearby. This has the advantage of being able to easily vary the location of the text but still have it tied to the function.

Resources