Advertisement
sNow_32

Rhombus

Oct 6th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #ifndef QCUSTOMRHOMBUS_H
  2. #define QCUSTOMRHOMBUS_H
  3.  
  4. #include "qcustomquadrangle.h"
  5. class QDebug;
  6.  
  7. class QCustomRhombus : public QCustomQuadrangle
  8. {
  9. public:
  10.     QCustomRhombus(QCustomPlot *parent);
  11.  
  12.     bool isRhombus();
  13.  
  14.     int CheckOrtogonal(QPointF _p1, QPointF _p2,
  15.                        QPointF _p3, QPointF _p4 );
  16. };
  17.  
  18. #endif // QCUSTOMRHOMBUS_H
  19.  
  20. //-----------------------------------
  21.  
  22. #include "qcustomrhombus.h"
  23.  
  24. QCustomRhombus::QCustomRhombus(QCustomPlot *parent)
  25.     : QCustomQuadrangle(parent) {
  26. }
  27.  
  28. bool QCustomRhombus::isRhombus() {
  29.     if ( CheckOrtogonal(getPoint_1(), getPoint_2(), getPoint_3(), getPoint_4()) == 0 ) {
  30.         if ( getDiagonal_AC() != getDiagonal_BD() ) {
  31.             if ( getPerimeter() == getAB() * 4 ) {
  32.                 return true;
  33.             }
  34.         }
  35.     } else return false;
  36.     return false;
  37. }
  38.  
  39. int QCustomRhombus::CheckOrtogonal(QPointF _p1, QPointF _p2, QPointF _p3, QPointF _p4)
  40. {
  41.     return (_p3.x() - _p1.x() ) * (_p3.x() - _p1.x() )
  42.             + ( _p4.y() - _p2.y() ) * ( _p4.y() - _p2.y() );
  43. }
  44. //----------------------------------------
  45.  
  46. // Rhombus
  47.     r = new QCustomRhombus(ui->plot);
  48.     r->setData(x, y);
  49.     if ( r->isRhombus() ) {
  50.         QMessageBox::information(this, tr("Информация"),
  51.                                  tr("Это ромб!"));
  52.         qDebug() << "THIS IS ROMB";
  53.         isRhombus = true;
  54.     } else {
  55.         isRhombus = false;
  56.         qDebug() << "THIS IS NO ROMB";
  57.     }
  58.     // Rhombus
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement