Search code examples
gnuplot

Problems with gnuplot to plot some images with 3d plot


So i made a little code to print some points over a spherical surface and i made him too locate all the positions of the center of mass of all the point printed (every time that he print a point he recalculate the position of the center of mass). The positions of the center of mass was printed to one file with i (that was the number of points printed until this moment) and the coordinates x, y and z. And based on script made by a professor of mine i made this script below to run with gnuplot to make a row of images with a ball that moves around the positions of the center of mass and at the final i that could made a video with the images.

set terminal pngcairo size 1080,1080

set view equal xyz
fx(t)= system(sprintf("sed -n '%d p' ../dat/cm.dat | cut -f2 -d' '", t))
fy(t)= system(sprintf("sed -n '%d p' ../dat/cm.dat | cut -f3 -d' '", t))
fz(t)= system(sprintf("sed -n '%d p' ../dat/cm.dat | cut -f4 -d' '", t))
unset xtics
unset ytics
unset ztics

t= 1
while(t <= 100000){
    set output sprintf("%d.png", t/10)
    set object circle at fx(t), fy(t), fz(t) size 0.35 fc rgb "#000000" fillstyle solid 1.0
    splot "../dat/cm.dat" u 2:3:4 w l lc rgb "#FFFFFF" t""
    unset object
    t= t+10
}
unset terminal
unset output

The problem who bring me here, i tried everything that passed out of my mind, but every time that i run the script the ball that should move around the positions of center of mass is printed so giant that is almost impossible to see the movement, you can see the problem with the size here. So if someone know what is the problem, i will be grateful. enter image description here

p.s.: Maybe this isn't important at all, but sorry for my write i'm not much acquainted with english.


Solution

  • you first have to set your output and then plot.

    ...
    set output sprintf("%d.png", t/10)
    splot "../dat/cm.dat" u 2:3:4 w l lc rgb "#FFFFFF" t""
    ...
    

    Addition:

    I guess I still don't understand your problem. My understanding so far: you have a huge datafile with for columns: i,x,y,z. And x,y,z describe a movement in 3D. In the end you want to animate this movement with a sphere or circle, correct? And your problem is that this sphere is too large? Then make the size smaller, e.g. instead of size 0.35 try size 0.05.

    Maybe with the following (different) example we will come (iteratively) closer what you want. By the way:

    1. I don't see any need for sed, can be done with gnuplot
    2. you can create animated GIF with gnuplot

    This is just a guess, I could be on the wrong track. Just let me know.

    Code:

    ### animated movement in 3D
    reset session
    
    set term gif animate delay 10 optimize
    set output "myAnimation.gif"
    
    # create some test data
    set print $Data 
        x0 = y0 = z0 = 0
        do for [i=1:200] {
            x0=x0+rand(0)-0.5; y0=y0+rand(0)-0.5; z0=z0+rand(0)-0.5
            print sprintf("%d %.3f %.3f %.3f",i,x0,y0,z0)
        }
    set print
    
    do for  [i=0:199] {
        splot $Data u 2:3:4 w l lc rgb "blue" notitle, \
              '' u 2:3:4 every ::i::i w p pt 7 ps 2 lc rgb "red" notitle
    }
    set output
    ### end of code
    

    Result:

    enter image description here