Advertisement
Guest User

Untitled

a guest
Oct 29th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include <QtCore/qmath.h>
  4. #include <QList>
  5. #include <QtWidgets/QApplication>
  6. #include <QtWidgets/QMainWindow>
  7. #include <QtCharts/QChartView>
  8. #include <QtCharts/QLineSeries>
  9. QT_CHARTS_USE_NAMESPACE
  10. class PointerList{
  11.  
  12. public:
  13.     double   x1,y1;
  14.     PointerList(double pts[]){
  15.         x1=pts[0];
  16.         y1=pts[1];
  17.     }
  18.     PointerList(){
  19.     }
  20. };
  21.  
  22. class FlightObject{
  23. private:
  24.     double V0=0, angle=0, g=9.8;
  25. public:
  26. FlightObject(double _v0, double _angle){
  27.     V0=_v0;
  28.     angle=_angle;
  29. }
  30.  
  31. QList<PointerList> getPointer(){
  32.     QList<PointerList> temp;
  33.     double Vx0 = V0 * qCos(angle),
  34.            Vy0 = V0 * qSin(angle),
  35.            t0=0, T =  2 * Vy0 / g;
  36.     for(auto i = t0; i<=T;i+=0.1){
  37.         double X1 = 0 + Vx0 * i;
  38.         double Y1 = 0 + Vy0 * i - g * i * i / 2;
  39.         temp.append(PointerList(new double[2]{X1,Y1}));
  40.     }
  41.     return temp;
  42. }
  43. QList<PointerList> getPointer(double _x0, double _y0){
  44.     QList<PointerList> temp;
  45.     double Vx0 = V0 * qCos(angle),
  46.            Vy0 = V0 * qSin(angle),
  47.            t0=0, T =  2 * Vy0 / g;
  48.     for(auto i = t0; i<=T;i+=0.1){
  49.         double X1 = _x0 + Vx0 * i;
  50.         double Y1 = _y0 + Vy0 * i - g * i * i / 2;
  51.         temp.append(PointerList(new double[2]{X1,Y1}));
  52.     }
  53.     return temp;
  54. }
  55. };
  56.  
  57. int main(int argc, char *argv[])
  58. {
  59.     QApplication a(argc, argv);
  60.     FlightObject point(45.0,45.0);
  61.     QLineSeries *series = new QLineSeries();
  62.     foreach(PointerList t, point.getPointer()){
  63.         series->append(t.x1,t.y1);
  64.     }
  65.     QChart *chart = new QChart();
  66.       chart->legend()->hide();
  67.       chart->addSeries(series);
  68.       chart->createDefaultAxes();
  69.       chart->setTitle("Simple line chart example");
  70.     QChartView *chartView = new QChartView(chart);
  71.     chartView->setRenderHint(QPainter::Antialiasing);
  72.     MainWindow w;
  73.     w.setCentralWidget(chartView);
  74.     w.resize(1200, 768);
  75.     w.show();
  76.     return a.exec();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement