Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include <QApplication>
- #include <QtCore/qmath.h>
- #include <QList>
- #include <QtWidgets/QApplication>
- #include <QtWidgets/QMainWindow>
- #include <QtCharts/QChartView>
- #include <QtCharts/QLineSeries>
- QT_CHARTS_USE_NAMESPACE
- class PointerList{
- public:
- double x1,y1;
- PointerList(double pts[]){
- x1=pts[0];
- y1=pts[1];
- }
- PointerList(){
- }
- };
- class FlightObject{
- private:
- double V0=0, angle=0, g=9.8;
- public:
- FlightObject(double _v0, double _angle){
- V0=_v0;
- angle=_angle;
- }
- QList<PointerList> getPointer(){
- QList<PointerList> temp;
- double Vx0 = V0 * qCos(angle),
- Vy0 = V0 * qSin(angle),
- t0=0, T = 2 * Vy0 / g;
- for(auto i = t0; i<=T;i+=0.1){
- double X1 = 0 + Vx0 * i;
- double Y1 = 0 + Vy0 * i - g * i * i / 2;
- temp.append(PointerList(new double[2]{X1,Y1}));
- }
- return temp;
- }
- QList<PointerList> getPointer(double _x0, double _y0){
- QList<PointerList> temp;
- double Vx0 = V0 * qCos(angle),
- Vy0 = V0 * qSin(angle),
- t0=0, T = 2 * Vy0 / g;
- for(auto i = t0; i<=T;i+=0.1){
- double X1 = _x0 + Vx0 * i;
- double Y1 = _y0 + Vy0 * i - g * i * i / 2;
- temp.append(PointerList(new double[2]{X1,Y1}));
- }
- return temp;
- }
- };
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- FlightObject point(45.0,45.0);
- QLineSeries *series = new QLineSeries();
- foreach(PointerList t, point.getPointer()){
- series->append(t.x1,t.y1);
- }
- QChart *chart = new QChart();
- chart->legend()->hide();
- chart->addSeries(series);
- chart->createDefaultAxes();
- chart->setTitle("Simple line chart example");
- QChartView *chartView = new QChartView(chart);
- chartView->setRenderHint(QPainter::Antialiasing);
- MainWindow w;
- w.setCentralWidget(chartView);
- w.resize(1200, 768);
- w.show();
- return a.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement