Search code examples
gnuplotbinary-data

Splot triangles from binary data file


I have a binary files that have binary format='%float32%float32%float32', having D3 points (using 1:2:3). Originally logically points grouped by 3 to form triangles. I want to plot just legs of triangles as a lines using with lines. In ASCII data file I can make so-called datablocks by adding an empty line between triples of lines, but in binary I can't. I want to break a chain of lines at every three points to form at least V-like parts of triangle contours.

Is there an option to make gnuplot to treat a triples of points as separate datablocks?

Is there another option to splot the data as (maybe) a solid triangles?


Solution

  • I'm still not sure whether I'm fully on the right track. The following code writes your binary data into a table and makes groups of 3 datapoints for a triangle, inserting an empty line and then shifted by one for the next triangle. So, So from the points p1=f1,f2,f3; p2=f4,f5,f6; p3=f7,f8,f9; ... it creates the triangles p1p2p3p1 p2p3p4p2 p3p4p5p3 (space=empty line).

    Certainly, not very (memory) efficient, but maybe this gets closer to your final goal. Check help pm3d and help hidden3d, where you might get some additional information. I very much hope that there is a better approach.

    Code: (assuming the binary file 'myBinary.bin', not sure whether I decoded your ASCII string correctly)

    # plot binary data
    reset session
    
    # put binary data into a datablock
    set table $Data
        plot 'myBinary.bin' u 1:2:3 binary format='%float32%float32%float32' skip=12 w table
    unset table
    
    # separate each triangle by an empty line
    set print $Data2
        do for [i=1:|$Data|-2] {
            print $Data[i]
            print $Data[i+1]
            print $Data[i+2]
            print $Data[i]
            print ""          # insert empty line
        }
    set print
    set pm3d hidden3d
    set view 40, 24
    
    splot $Data2 u 1:2:3 w pm3d notitle
    ### end of code
    

    Result:

    enter image description here