Okay so I'm doing a school project that involves moving a navel fleet around an XYZ plane (I've asked for help with this project on other problems as well). But I've run into a bit of trouble with my code. Technically this is more a GNUPlot problem then c++, but I thought I might ask....
Anyway the problem is that everything works perfect when I'm just using the regular GNUPlot with an X and Y axis. All my ships float around like they should following their set patterns, but I need to build a submarine and add a Z axis with Splot. My professor's notes on the subject are very unclear and the GNUplot website wasn't able to help either. For some reason everytime I plot this, all the ships appear as if they are in a vertical column, with some ships underwater and others flying in the sky, and going positive on the Y axis sends them plummeting into the murky ocean. I was just trying to get a slightly angled top down view going so I could build and start testing my submarine.
Here is the code going into the GNUplot command line
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/// Insert starting code initializing ships
fout2.open("command.txt",ios::out); ///build the command file
fout2<<"set view (60 , 45, 45)"<<endl;
fout2 << "set ylabel \"x\"" << endl;
fout2 << "set ylabel \"y\"" << endl;
fout2<<"set xrange [-1000:1000]"<<endl;
fout2<<"set yrange [-1000:1000]"<<endl;
fout2<<"set zrange [-100:100]"<<endl;
fout2<<"set mapping cylindrical"<<endl;
fout2<<"set angles radians"<<endl;
fout2<<"set terminal png"<<endl;
/// insert code that runs the calculations to get the ships X and Y values,
/// all Z values are currently at 0.
fout2<<"set output \'"<<outfile<<"\'"<<endl;
fout2<<"splot \'"<<fname<<"\' with circles"<<endl;
Like I said before on a 2D plane it all works just fine. But I can't quite decipher my professors notes on Splot. any help is appreciated.
For a cylindrical coordinate system, the data again occupy two or three
columns. The first two are interpreted as theta (in the units specified by
`set angles`) and z. The radius is either taken from the third column or set
to unity, as in the spherical case. The mapping is: x = r * cos(theta)
y = r * sin(theta)
z = z
Looking at the generated *.dat, you've got something like
Mostly because the example the my professor had given me used "set mapping cylindrical", and I guess in my frustration before I didn't notice. I have never used GNUPlot before, or Splot, so I went based off my professors example. He doesn't ever comment on any of his code though so it's difficult to decipher at times.
I was under the impression that I absolutely needed to have a "set mapping" of some kind in my program, but when I looked it up Splot only had cylindrical, spherical, and Cartesian, all three of which didn't work right.
Actually since you pointed that out I devided to take a risk and completely remove that line, and now it works perfect!.. I feel like such an idiot now...
Thank you for all of your help today Ne555. You've been a big aid in this. I can now finally have this project cleaned up and ready to submit in the morning.