引用第1楼lzian于2008-05-15 13:28发表的 :
在main.cpp中,in1.txt只是一个x坐标数据,空格间隔,y坐标是通过给定数组结合x算出来的.
main.cpp
#include <QtGui>
#include "plotter.h"
void readFlightCurves(Plotter *plotter, const QString &fileName)
{
QVector<QPointF> data[6];
double factX = 0.0013;
double factY[6] = { 0.0008, 0.1, 0.2, 0.2, 0.1, 0.8 };
double offsY[6] = { +500, -55, +309, +308, 0, 0 };
int pos[6] = { 3, 6, 7, 8, 9, 10 };
QFile file(fileName);
double offsX = 0.0;
if (file.open(QIODevice::ReadOnly)) {
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
QStringList coords = line.split(' ',
QString::SkipEmptyParts);
if (coords.count() >= 6) {
double x = factX * coords[0].toDouble();
if (data[0].isEmpty())
offsX = x;
for (int i = 0; i < 6; ++i) {
double y = coords[pos
].toDouble();
data.append(QPointF(x - offsX,
factY * (y - offsY)));
}
}
}
}
plotter->setCurveData(0, data[0]);
plotter->setCurveData(1, data[1]);
plotter->setCurveData(2, data[2]);
plotter->setCurveData(3, data[3]);
plotter->setCurveData(4, data[4]);
plotter->setCurveData(5, data[5]);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Plotter plotter;
plotter.setWindowTitle(QObject::tr("Jambi Plotter"));
#if 0
readFlightCurves(&plotter, ":/in1.txt");
#else
int numPoints = 100;
QVector<QPointF> points0;
QVector<QPointF> points1;
for (int x = 0; x < numPoints; ++x) {
points0.append(QPointF(x, uint(qrand()) % 100));
points1.append(QPointF(x, uint(qrand()) % 100));
}
plotter.setCurveData(0, points0);
plotter.setCurveData(1, points1);
PlotSettings settings;
settings.minX = 0.0;
settings.maxX = 100.0;
settings.minY = 0.0;
settings.maxY = 100.0;
plotter.setPlotSettings(settings);
#endif
plotter.show();
return app.exec();
}
-------------------------------------------------------------------------------------------------
in1.txt
54061 48.0776 11.2922 577.6 571.5 946.45 31.303 309.279 311.580 40.4 12.390 12.323 13.0866
54062 48.0771 11.2916 577.7 571.6 946.44 31.474 309.453 311.833 41.3 12.810 12.637 13.4058
54063 48.0767 11.2909 578.3 572.2 946.37 31.378 309.362 311.807 42.7 13.168 12.896 13.6785
54064 48.0762 11.2904 578.1 572.0 946.40 31.161 309.139 311.483 41.5 12.633 12.419 13.1915
54065 48.0757 11.2897 578.0 571.9 946.41 31.167 309.144 311.478 41.3 12.576 12.353 13.1236
54066 48.0753 11.2891 578.3 572.2 946.37 31.065 309.044 311.397 41.9 12.684 12.476 13.2553
54067 48.0748 11.2884 578.7 572.6 946.33 31.119 309.103 311.362 40.1 12.169 12.018 12.7747
54068 48.0742 11.2877 579.2 573.1 946.27 31.030 309.018 311.252 39.9 12.038 11.880 12.6340
54069 48.0738 11.2870 581.6 575.2 946.03 31.238 309.251 311.503 39.6 12.123 11.934 12.6785
54070 48.0732 11.2863 583.8 577.3 945.79 30.927 308.958 311.194 40.1 12.046 11.909 12.6623
54071 48.0727 11.2856 586.2 579.6 945.54 30.902 308.956 311.249 41.1 12.355 12.256 13.0213
54072 48.0722 11.2848 589.3 582.4 945.22 30.625 308.704 310.996 41.8 12.359 12.194 12.9639
54073 48.0716 11.2842 593.6 586.5 944.75 30.452 308.572 310.760 40.3 11.800 11.616 12.3618
54074 48.0711 11.2834 599.3 591.7 944.16 30.429 308.604 310.774 40.0 11.703 11.570 12.3069
54075 48.0705 11.2826 605.5 597.4 943.51 30.376 308.611 310.791 40.3 11.751 11.659 12.3936
54076 48.0699 11.2819 613.3 604.7 942.68 30.384 308.697 310.905 40.8 11.906 11.866 12.5979
54077 48.0694 11.2811 620.2 611.2 941.95 30.275 308.653 310.873 41.2 11.971 11.899 12.6274
54078 48.0689 11.2804 629.3 619.6 940.99 30.325 308.795 311.013 41.0 11.955 11.887 12.6000
54079 48.0683 11.2796 638.6 628.3 940.01 30.179 308.738 310.947 41.1 11.905 11.803 12.5059
.
.
.
能从那段看出是计算出来的呢?!请明示!