I developed a script that calculates the position of N bodies during a gravitational simulation, and I'd like some tips to visualize it. So far, I can either plot the initial conditions, the final position or the trajectories of all bodies, which is not so great. My goal now is "simply" to visualize the movement of all the bodies and/or to plot several figures (one for each time increase) such that, later, it may be possible to do a gif with "animate *.png".
So far I managed to call Gnuplot inside my Fortran code like this:
call system('gnuplot data_test.plt')
Where "data_test.plt" is:
set terminal x11
plot 'teste.dat' pt 5 ps 1
pause 0.1
clear
And "teste.dat" is a file (re-)created at every time increase, which contains the position (x,y) of all the N bodies at that given time.
Related
I have been working to find temporal displacement between audio signals using a spectrogram. I have a short array containing data of a sound wave (pulses at specific frequencies). Now I want to plot spectrogram from that array. I have followed this steps (Spectrogram C++ library):
It would be fairly easy to put together your own spectrogram. The steps are:
window function (fairly trivial, e.g. Hanning)
FFT (FFTW would be a good choice but if licensing is an issue then go for Kiss FFT or
similar)
calculate log magnitude of frequency domain components(trivial: log(sqrt(re * re + im * im))
Now after performing these 3 steps, I am stuck at how to plot the spectrogram from this available data? Being naive in this field, I need some clear steps ahead to plot the spectrogram.
I know that a simple spectrogram has Frequency at Y-Axis, time at X-axis and magnitude as the color intensity.
But how do I get these three things to plot the spectrogram? (I want to observe and analyze data behind spectral peaks(what's the value on Y-axis and X-axis), the main purpose of plotting spectrogram).
Regards,
Khubaib
For my current project I want to be able to plot a N x N matrix in real time in C++. Where N is in the range between 100 and 1000. The content of the matrix changes over time. I also want to be able to interact with the matrix i.e. draw objects inside the matrix using my mouse.
I found this post but I find it hard to decide which tool I should use.
Any reccomendations?
Short intro: I am working on a 3D laserscanning device, that creates a point cloud using pictures of an object which is illuminated by the laser.
Each picture shows essentially a line which represents the objects surface.
What I do then is store the value of brightness of each pixel in a 2D Array, which in the end results in a Matrix that puts a number on the position of the illuminated line. This I can take to further calculate the point cloud. All of this I'm doing in C++.
Now to the problem at hand:
After storing the brightness information inside the matrix, I get a complex line which is several pixels thick (thickness not uniform). I need it to be exactly 1 Pixel wide. Up until now I calculated either the mean value of the line, or used a weight function.
This only works well as long as your line mostly runs vertically or horizontally throughout the picture/matrix, because you can calculate the right value for each seperate line or column.
I have now pictures/matrices where the line has a more complex shape, so these simple solutions won't work anymore. Here are two examples:
How can I calculate the mean value or put a weight function on these lines, so i can bring them down to a thickness of 1px? I need an algorithm that does this automatically because I have sets of hundreds of pictures, where this line can be differently shaped, so it would be too timeconsuming/impossible to edit all of them seperately.
I hope I somehow talked sense rather then complicate things ;)
Ok So, I recently checked out Lazy Foo Tutorials for SDL 1.2, and I read the tutorials.
I want to program a 2 body problem onto the screen. So where the user enters the data for both body, velocity, mass etc, the distance b/w the bodies and such. After that the bodies start
to move on the screen. What I wanted to know was what math would I need to know to program it. I looked into Wikipedia and other sites pertaining to the 2 Body Motion, does the math really need to be as complex as the math that is given on the sites?
http://en.wikipedia.org/wiki/Two-body_problem
Or could I opt to do a simple Formula of Universal Gravitation http://www.regentsprep.org/regents/physics/phys01/unigrav/Image25.gif and then just after every frame just update the two dots on the screen according to the points given by the formula?
I am trying to make polygon A be at position (x,y) at time= 1 sec for example. Then it should be at position (x,y+2) when time = 2 sec. Then I plan to make more polygons like this. I also want this to be animated and the polygon to smoothly move from the first position to the second, not a polygon jumping a round.
Now thus far, I have learned about the glutTimerFunction, however, from my understanding, I cannot individually tell polygons to be at position (x,y) and time T. But rather it seems like I have to make every polygon that i desire(around 500) and then have timer cycle through all the polygons at once.
Is there a way to explicitly tell the polygon to be at position (x,y) at time T using the glutTimerFunc?
OpenGL is a low level API, not an engine or a framework. It has no built-in method for automatically doing interpolation between positions over time, that's up to you as the engine writer to implement as you see fit. Linear interpolation between two points over time is fairly easy (ie, in pseudocode position = startPos + ((endPos - startPos) * timeElapsed). Interpolation along a more complex curve is essentially the same, just the math is a little more involved to represent the desired curve.
You are correct that you must iterate through all of your polygons by hand and position them. This is another feature of using the low level graphics API instead of a pre-written engine.
There are a number of engines of varying complexity (and price) available that abstract away these details for you, however, if your goal is to learn graphics programming I would suggest shying away from them and plowing through.