Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. degrees, radians can't learn to use them

degrees, radians can't learn to use them

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 337 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • timob256T Offline
    timob256T Offline
    timob256
    wrote on last edited by
    #1

    trying to draw a circle with vertices

    #ifndef KRUG_QT_H
    #define KRUG_QT_H
    
    #include <QMainWindow>
    #include <QDebug>
    #include <QPainter>
    #include <QPen>
    #include <QFont>
    #include <QtMath>
    #include <QPointF>
    
    
    class Krug_qt : public QMainWindow
    {
        Q_OBJECT
    
    public:
        Krug_qt(QWidget *parent = 0);
        ~Krug_qt();
    
        void fillVertexArray();
    
        float R;        // радиус
        int p;          // Количество продольных срезов. Number of longitudinal slices.
        int q;          // Количество широтных срезов. Number of latitudinal slices.
        int kol_toch;
    
        QVector<float> integerVector;
    
    protected:
        void paintEvent(QPaintEvent *event);
    //     void keyPressEvent(QKeyEvent *event);
    };
    
    #endif // KRUG_QT_H
    
    #include "krug_qt.h"
    
    Krug_qt::Krug_qt(QWidget *parent)
        : QMainWindow(parent)
    {
        R = 90.0;
        q = 24;
        p = 24;
    
        kol_toch = 180;
    }
    
    Krug_qt::~Krug_qt()
    {
    
    }
    
    void Krug_qt::fillVertexArray()
    {
        float grad = 360.0/kol_toch;
        float grad_kol_toch = 0.0;
        // градусы*M_PI/180 = радианы
        int j;
        for (j = 0; j <= kol_toch; ++j){
            integerVector.append(R * cos(grad_kol_toch*M_PI/180.0));
            integerVector.append(R * sin(grad_kol_toch*M_PI/180.0));
            grad_kol_toch = grad_kol_toch + grad;
        }
    }
    
    void Krug_qt::paintEvent(QPaintEvent *event)
    {
        integerVector.clear();
        QPainter painter(this);                                   // Создаём объект отрисовщика
        QPen pen_abris(Qt::black, 2, Qt::SolidLine, Qt::FlatCap); // кисть обрисовки (компаса)
        painter.setRenderHint(QPainter::Antialiasing);            // убираем резкие кубики
        painter.setPen(pen_abris);                                // Устанавливаем кисть обрисовки
        fillVertexArray();                                        // Набираем массив
        painter.translate(this->width()/2, this->height()/2);     // смещение отрисовки
    
        qDebug() << integerVector.size();
    
        int f = 0;
        for(int i =0; i<integerVector.size()/2; ++i)
        {
            i++; f++;
            painter.drawPoint(QPointF(integerVector[--i],integerVector[i]));
            qDebug() << "f :"<<f;
        }
    }
    

    I don't know what I'm doing wrong

    here is the geometry of the points

    void Krug_qt::fillVertexArray()
    {
        float grad = 360.0/kol_toch;
        float grad_kol_toch = 0.0;
        // градусы*M_PI/180 = радианы
        int j;
        for (j = 0; j <= kol_toch; ++j){
            integerVector.append(R * cos(grad_kol_toch*M_PI/180.0));
            integerVector.append(R * sin(grad_kol_toch*M_PI/180.0));
            grad_kol_toch = grad_kol_toch + grad;
        }
    }
    

    and

    qDebug() << integerVector.size();
    
    int f = 0;
    for(int i =0; i<integerVector.size()/2; ++i)
    {
        i++; f++;
        painter.drawPoint(QPointF(integerVector[--i],integerVector[i]));
        qDebug() << "f :"<<f;
    }
    

    Screenshot_20211021_153501.png

    1 Reply Last reply
    0
    • timob256T Offline
      timob256T Offline
      timob256
      wrote on last edited by
      #2

      understood. it should have been like this

      int f = 0; int tocka_1 = 0; int tocka_2 = 0;
         for(int i =0; i<kol_toch; ++i)
         {
             tocka_2 =  tocka_1+1;
             painter.drawPoint(QPointF(integerVector[tocka_1],integerVector[tocka_2]));
             tocka_1 = tocka_1 +2;
             qDebug() << "i :"<<i;
         }
      

      Screenshot_20211021_165351.png

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mchinand
        wrote on last edited by
        #3

        @timob256 said in degrees, radians can't learn to use them:

        for(int i =0; i<integerVector.size()/2; ++i)
        {
        i++; f++;
        painter.drawPoint(QPointF(integerVector[--i],integerVector[i]));
        qDebug() << "f :"<<f;
        }

        You're not traversing all of integerVector.
        One way to do it would be:

        for(int i = 0; i < integerVector.size()/2; ++i) {
             f++;
             painter.drawPoint(QPointF(integerVector[2 * i], integerVector[2 * i + 1]));
             qDebug() << "f :" << f;
         }
        

        Your first loop could also be simplified by using the loop variable in your equations that populate integerVector (which doesn't contain integers) and use grad in your loop-increment statement.

        1 Reply Last reply
        1
        • JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          degrees, radians can't learn to use them

          Radians are for mathematicians, maybe physicists. Degrees are for the rest of us :)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved