qreal angle(const QPointF &p1, const QPointF &p2) { static const qreal rad_factor = 180 / Q_PI; qreal _angle = 0; if (p1.x() == p2.x()) { if (p1.y() < p2.y()) _angle = 270; else _angle = 90; } else { qreal x1, x2, y1, y2; if (p1.x() <= p2.x()) { x1 = p1.x(); y1 = p1.y(); x2 = p2.x(); y2 = p2.y(); } else { x2 = p1.x(); y2 = p1.y(); x1 = p2.x(); y1 = p2.y(); } qreal m = -(y2 - y1) / (x2 - x1); _angle = qAtan(m) * rad_factor; if (p1.x() < p2.x()) _angle = 180 - _angle; else _angle = -_angle; } return _angle; }
Rpn::Operand Arctangent::calculate(FunctionCalculator *calculator, QList<Rpn::Operand> actualArguments) { Q_UNUSED(calculator); Rpn::Operand result; result.type = Rpn::OperandNumber; result.value = qAtan(actualArguments.at(0).value.value<Number>()); return result; }
/********************************************************************** * Function: get the angle from the deltax and deltay. * Parameters: deltax, deltay * Return: angle **********************************************************************/ qreal QArcItem::getAngle(qreal dDeltaX, qreal dDeltaY) const { qreal dAngle = 0.0, dK = 0.0; const qreal dDelta = 0.01; /*dDeltaX --> 0*/ if (dDeltaX > -dDelta && dDeltaX < dDelta) { if (dDeltaY > 0) { dAngle = 90; } else if (dDeltaY < 0) { dAngle = 270; } } /*dDeltaY --> 0*/ else if (dDeltaY > -dDelta && dDeltaY < dDelta) { if (dDeltaX > 0) { dAngle = 0; } else if (dDeltaX < 0) { dAngle = 180; } } else { dK = dDeltaY / dDeltaX; dAngle = qAtan(dK); dAngle *= ((PI_ANGLE * 0.5) / M_PI); /*Quadrant 2*/ if (dDeltaY > 0 && dDeltaX < 0) { dAngle += 180; } /*Quadrant 3*/ else if (dDeltaY < 0 && dDeltaX < 0) { dAngle = 270 - (90 - dAngle); } /*Quadrant 4*/ else if (dDeltaY < 0 && dDeltaX > 0) { dAngle += 360; } } return dAngle; }
void toolpath::arcToSegments(QPoint p1, QPoint p2,Path &path) { double angle; if((p1.x()-p2.x())==0) { if(p1.y()>p2.y()) angle=3.1415926/2; else angle=3.1415926*3/2; } else if((p1.y()-p2.y())==0) { if(p1.x()>p2.x()) angle=0; else angle=3.1415926; } else { angle=qAtan((p1.y()-p2.y())*1.0/(p1.x()-p2.x())); if(angle<0) { if(p1.y()>p2.y()) angle=angle+3.1415926; else angle=angle; } else { if(p2.y()<p1.y()) angle=angle; else angle=angle+3.1415926; } } double startAngle = angle; double spanAngle =3.1415926; QPoint c=(p1+p2)/2; double r=qSqrt(double(p2.x()-p1.x())*double(p2.x()-p1.x())+double(p2.y()-p1.y())*double(p2.y()-p1.y()))/2; double temp=(r-arcError)*1.0/r;//for debug double stepAngle=2*acos(temp); if(stepAngle==0)stepAngle=0.12566;//50 steps double stepNum=2*3.1415926/stepAngle; for(double a=startAngle;a>startAngle-spanAngle;a-=stepAngle) { IntPoint t; t.X=r*cos(a)+c.x(); t.Y=r*sin(a)+c.y(); path<<t; } }
// Returns the angle of the point acording to the origin // Result should be in [0, 2*PI) qreal angle(QPointF point, QPointF origin) { qreal dx = point.x() - origin.x(); qreal dy = origin.y() - point.y(); qreal result = qAtan(qAbs(dy / dx)); if (dx < 0 && dy >= 0) return PI - result; if (dx <= 0 && dy < 0) return PI + result; if (dx > 0 && dy < 0) return 2 * PI - result; if (result != result) // NaN !!! return 0; return result; }
static double line2Radians( const QPointF &p1, const QPointF &p2 ) { const QPointF p = p2 - p1; double angle; if ( p.x() == 0 ) angle = ( p.y() <= 0.0 ) ? M_PI_2 : 3 * M_PI_2; else { angle = qAtan( double( -p.y() ) / double( p.x() ) ); if ( p.x() < 0.0 ) angle += M_PI; if ( angle < 0.0 ) angle += 2 * M_PI; } return 360.0 - angle * 180.0 / M_PI; }
void dtkComposerNodeTestCase::testNumber(void) { dtkComposerNodeInteger n_int; QVERIFY(n_int.value() == 0); dtkComposerNodeReal n_real; QVERIFY(n_real.value() == 0); qlonglong v_int = 1123581321; double v_real = 4 * qAtan(1); n_int.setValue(v_int); QCOMPARE(v_int, n_int.value()); n_real.setValue(v_real); QCOMPARE(v_real, n_real.value()); dtkComposerNodeInteger n_ires; QVERIFY(n_ires.receivers().first()->connect(n_int.emitters().first())); n_int.run(); n_ires.run(); QCOMPARE(v_int, n_ires.value()); dtkComposerNodeReal n_rres; QVERIFY(n_rres.receivers().first()->connect(n_real.emitters().first())); n_real.run(); n_rres.run(); QCOMPARE(v_real, n_rres.value()); QVERIFY(n_ires.receivers().first()->disconnect(n_int.emitters().first())); QVERIFY(n_ires.receivers().first()->connect(n_real.emitters().first())); n_real.run(); n_ires.run(); QCOMPARE(static_cast<qlonglong>(v_real), n_ires.value()); QVERIFY(n_rres.receivers().first()->disconnect(n_real.emitters().first())); QVERIFY(n_rres.receivers().first()->connect(n_int.emitters().first())); n_int.run(); n_rres.run(); QCOMPARE(static_cast<double>(v_int), n_rres.value()); }
void CircleWidget::updateScene() { const qreal PI = qAtan(1.0)*4; int count=_list.size(); qreal pitch = (2*PI) / count; _scene->clear(); QRect r = ui->graphicsView->geometry(); QBrush b = QBrush(QColor(Qt::black)); QPen p = QPen(b, 4.0); qreal topleftX = r.width()/8; qreal topleftY = r.height()/8; qreal radiusX = 3*topleftX; qreal radiusY = 3*topleftY; QGraphicsEllipseItem* ellipse = _scene->addEllipse(0, 0, radiusX*2, radiusY*2, p); ellipse->setPos(topleftX, topleftY); qreal sizeX = topleftX*2; qreal sizeY = topleftY*2; int curs = 0; typedef QMap<std::string, IdentityWidget*>::const_iterator itList; for (itList it=_list.constBegin(); it!=_list.constEnd(); ++it){ QPixmap pix = it.value()->getImage(); pix = pix.scaled(sizeX, sizeY); QGraphicsPixmapItem* item = _scene->addPixmap(pix); qreal x = (qCos(curs*pitch)*radiusX)-(sizeX/2)+topleftX+radiusX; qreal y = (qSin(curs*pitch)*radiusY)-(sizeY/2)+topleftY+radiusY; item->setPos(QPointF(x, y)); QString name = it.value()->getName(); QString idKey = it.value()->keyId(); QString gxsId = it.value()->gxsId(); if (idKey == gxsId) gxsId.clear(); item->setToolTip(name.append("\n") .append(idKey).append(gxsId.isEmpty()?"":"\n") .append(gxsId)); ++curs; }//for (itList it=_list.constBegin(); it!=_list.constEnd(); ++it) emit imageUpdated(); }
double LevelOneDec::ArcCos(double x) { double result; if ((1 - x*x) < 0) { return 0; } else { if (qSqrt(1 - x*x) == 0) { return 0; } else { result = 2*qAtan(1) - atan(x / sqrt(1 - x*x)); } } return result; }
// slots void Ant::onPositionChanged(QPointF center, QPointF vector) { _center = center; float x = vector.x(); float y = vector.y(); float angleInTriangle = qAtan(y / x); float angleInRad = 0; if (x >= 0 && y >= 0) { angleInRad = angleInTriangle; } else if (x < 0 && y >= 0) { angleInRad = M_PI + angleInTriangle; } else if (x < 0 && y < 0) { angleInRad = M_PI + angleInTriangle; } else if (x >= 0 && y < 0) { angleInRad = angleInTriangle; } _direction = angleInRad * 180 / M_PI - 90; setupShape(); _mouthPosition = _center + vector * _scale * 1.5; }
void dtkComposerNodeTestCase::testNumberOperatorBinary(void) { qlonglong v_i0 = 112358; qlonglong v_i1 = 11235; dtkComposerNodeInteger n_i0; dtkComposerNodeInteger n_i1; n_i0.setValue(v_i0); n_i1.setValue(v_i1); n_i0.run(); n_i1.run(); dtkComposerNodeInteger n_iend; // EUCLIDIAN DIVISION dtkComposerNodeNumberOperatorBinaryEucldiv n_eucl; QVERIFY(n_eucl.receivers().first()->connect(n_i0.emitters().first())); QVERIFY(n_eucl.receivers().last()->connect( n_i1.emitters().first())); QVERIFY(n_iend.receivers().first()->connect(n_eucl.emitters().first())); n_eucl.run(); n_iend.run(); QCOMPARE((v_i0 / v_i1), n_iend.value()); QVERIFY(n_iend.receivers().first()->disconnect(n_eucl.emitters().first())); // MODULO dtkComposerNodeNumberOperatorBinaryModulo n_mod; QVERIFY(n_mod.receivers().first()->connect( n_i0.emitters().first())); QVERIFY(n_mod.receivers().last()->connect( n_i1.emitters().first())); QVERIFY(n_iend.receivers().first()->connect(n_mod.emitters().first())); n_mod.run(); n_iend.run(); QCOMPARE((v_i0 % v_i1), n_iend.value()); QVERIFY(n_iend.receivers().first()->disconnect(n_mod.emitters().first())); // --- double v_r0 = 4. * qAtan(1.); double v_r1 = 10. / 3.; dtkComposerNodeReal n_r0; dtkComposerNodeReal n_r1; n_r0.setValue(v_r0); n_r1.setValue(v_r1); n_r0.run(); n_r1.run(); dtkComposerNodeReal n_rend; // MIN dtkComposerNodeNumberOperatorBinaryMin n_min; QVERIFY(n_min.receivers().first()->connect(n_r0.emitters().first())); QVERIFY(n_min.receivers().last()->connect( n_r1.emitters().first())); QVERIFY(n_rend.receivers().first()->connect(n_min.emitters().first())); n_min.run(); n_rend.run(); QCOMPARE(qMin(v_r0, v_r1), n_rend.value()); QVERIFY(n_rend.receivers().first()->disconnect(n_min.emitters().first())); // MAX dtkComposerNodeNumberOperatorBinaryMax n_max; QVERIFY(n_max.receivers().first()->connect(n_r0.emitters().first())); QVERIFY(n_max.receivers().last()->connect( n_r1.emitters().first())); QVERIFY(n_rend.receivers().first()->connect(n_max.emitters().first())); n_max.run(); n_rend.run(); QCOMPARE(qMax(v_r0, v_r1), n_rend.value()); QVERIFY(n_rend.receivers().first()->disconnect(n_max.emitters().first())); // MINUS (SUBSTRACTION) dtkComposerNodeNumberOperatorBinaryMinus n_minus; QVERIFY(n_minus.receivers().first()->connect(n_r0.emitters().first())); QVERIFY(n_minus.receivers().last()->connect( n_r1.emitters().first())); QVERIFY(n_rend.receivers().first()->connect(n_minus.emitters().first())); n_minus.run(); n_rend.run(); QCOMPARE((v_r0 - v_r1), n_rend.value()); QVERIFY(n_rend.receivers().first()->disconnect(n_minus.emitters().first())); // PLUS (ADDITION) dtkComposerNodeNumberOperatorBinaryPlus n_plus; QVERIFY(n_plus.receivers().first()->connect(n_r0.emitters().first())); QVERIFY(n_plus.receivers().last()->connect( n_r1.emitters().first())); QVERIFY(n_rend.receivers().first()->connect(n_plus.emitters().first())); n_plus.run(); n_rend.run(); QCOMPARE((v_r0 + v_r1), n_rend.value()); QVERIFY(n_rend.receivers().first()->disconnect(n_plus.emitters().first())); // MULTIPLICATION dtkComposerNodeNumberOperatorBinaryMult n_mult; QVERIFY(n_mult.receivers().first()->connect(n_r0.emitters().first())); QVERIFY(n_mult.receivers().last()->connect( n_r1.emitters().first())); QVERIFY(n_rend.receivers().first()->connect(n_mult.emitters().first())); n_mult.run(); n_rend.run(); QCOMPARE((v_r0 * v_r1), n_rend.value()); QVERIFY(n_rend.receivers().first()->disconnect(n_mult.emitters().first())); // RATIO (DIVISION) dtkComposerNodeNumberOperatorBinaryRatio n_ratio; QVERIFY(n_ratio.receivers().first()->connect(n_r0.emitters().first())); QVERIFY(n_ratio.receivers().last()->connect( n_r1.emitters().first())); QVERIFY(n_rend.receivers().first()->connect(n_ratio.emitters().first())); n_ratio.run(); n_rend.run(); QCOMPARE((v_r0 / v_r1), n_rend.value()); QVERIFY(n_rend.receivers().first()->disconnect(n_ratio.emitters().first())); // Nth ROOT dtkComposerNodeNumberOperatorBinaryNthroot n_root; QVERIFY(n_root.receivers().first()->connect(n_r0.emitters().first())); QVERIFY(n_root.receivers().last()->connect( n_r1.emitters().first())); QVERIFY(n_rend.receivers().first()->connect(n_root.emitters().first())); n_root.run(); n_rend.run(); QCOMPARE(qPow(v_r0, 1. / v_r1), n_rend.value()); QVERIFY(n_rend.receivers().first()->disconnect(n_root.emitters().first())); // POWER dtkComposerNodeNumberOperatorBinaryPower n_pow; QVERIFY(n_pow.receivers().first()->connect(n_r0.emitters().first())); QVERIFY(n_pow.receivers().last()->connect( n_r1.emitters().first())); QVERIFY(n_rend.receivers().first()->connect(n_pow.emitters().first())); n_pow.run(); n_rend.run(); QCOMPARE(qPow(v_r0, v_r1), n_rend.value()); QVERIFY(n_rend.receivers().first()->disconnect(n_pow.emitters().first())); }
void dtkComposerNodeTestCase::testNumberOperatorUnary(void) { double v_r = qAtan(1); dtkComposerNodeReal n_r; n_r.setValue(v_r); n_r.run(); dtkComposerNodeReal n_end; // INCREMENT dtkComposerNodeNumberOperatorUnaryIncr n_incr; QVERIFY(n_incr.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_incr.emitters().first())); n_incr.run(); n_end.run(); QCOMPARE((v_r + 1), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_incr.emitters().first())); // DECREMENT dtkComposerNodeNumberOperatorUnaryDecr n_decr; QVERIFY(n_decr.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_decr.emitters().first())); n_decr.run(); n_end.run(); QCOMPARE((v_r - 1), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_decr.emitters().first())); // SQRT dtkComposerNodeNumberOperatorUnarySqrt n_sqrt; QVERIFY(n_sqrt.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_sqrt.emitters().first())); n_sqrt.run(); n_end.run(); QCOMPARE(qSqrt(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_sqrt.emitters().first())); // SQUARE dtkComposerNodeNumberOperatorUnarySquare n_square; QVERIFY(n_square.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_square.emitters().first())); n_square.run(); n_end.run(); QCOMPARE((v_r * v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_square.emitters().first())); // LN dtkComposerNodeNumberOperatorUnaryLn n_ln; QVERIFY(n_ln.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_ln.emitters().first())); n_ln.run(); n_end.run(); QCOMPARE(qLn(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_ln.emitters().first())); // LOG10 dtkComposerNodeNumberOperatorUnaryLog10 n_log10; QVERIFY(n_log10.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_log10.emitters().first())); n_log10.run(); n_end.run(); QCOMPARE(qLn(v_r)/qLn(10.), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_log10.emitters().first())); // EXP dtkComposerNodeNumberOperatorUnaryExp n_exp; QVERIFY(n_exp.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_exp.emitters().first())); n_exp.run(); n_end.run(); QCOMPARE(qExp(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_exp.emitters().first())); // COS dtkComposerNodeNumberOperatorUnaryCos n_cos; QVERIFY(n_cos.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_cos.emitters().first())); n_cos.run(); n_end.run(); QCOMPARE(qCos(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_cos.emitters().first())); // SIN dtkComposerNodeNumberOperatorUnarySin n_sin; QVERIFY(n_sin.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_sin.emitters().first())); n_sin.run(); n_end.run(); QCOMPARE(qSin(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_sin.emitters().first())); // TAN dtkComposerNodeNumberOperatorUnaryTan n_tan; QVERIFY(n_tan.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_tan.emitters().first())); n_tan.run(); n_end.run(); QCOMPARE(qTan(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_tan.emitters().first())); // ACOS dtkComposerNodeNumberOperatorUnaryAcos n_acos; QVERIFY(n_acos.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_acos.emitters().first())); n_acos.run(); n_end.run(); QCOMPARE(qAcos(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_acos.emitters().first())); // ASIN dtkComposerNodeNumberOperatorUnaryAsin n_asin; QVERIFY(n_asin.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_asin.emitters().first())); n_asin.run(); n_end.run(); QCOMPARE(qAsin(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_asin.emitters().first())); // ATAN dtkComposerNodeNumberOperatorUnaryAtan n_atan; QVERIFY(n_atan.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_atan.emitters().first())); n_atan.run(); n_end.run(); QCOMPARE(qAtan(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_atan.emitters().first())); // DEG2RAD dtkComposerNodeNumberOperatorUnaryDeg2Rad n_d2r; QVERIFY(n_d2r.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_d2r.emitters().first())); n_d2r.run(); n_end.run(); QCOMPARE((v_r * M_PI / 180.), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_d2r.emitters().first())); // RAD2DEG dtkComposerNodeNumberOperatorUnaryRad2Deg n_r2d; QVERIFY(n_r2d.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_r2d.emitters().first())); n_r2d.run(); n_end.run(); QCOMPARE((v_r / M_PI * 180.), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_r2d.emitters().first())); // INVERSE dtkComposerNodeNumberOperatorUnaryInv n_inv; QVERIFY(n_inv.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_inv.emitters().first())); n_inv.run(); n_end.run(); QCOMPARE((1. / v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_inv.emitters().first())); // OPPOSITE dtkComposerNodeNumberOperatorUnaryOpp n_opp; QVERIFY(n_opp.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_opp.emitters().first())); n_opp.run(); n_end.run(); QCOMPARE((-v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_opp.emitters().first())); // ABS dtkComposerNodeNumberOperatorUnaryAbs n_abs; QVERIFY(n_abs.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_abs.emitters().first())); n_abs.run(); n_end.run(); QCOMPARE(qAbs(v_r), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_abs.emitters().first())); dtkComposerNodeInteger n_iend; // CEIL dtkComposerNodeNumberOperatorUnaryCeil n_ceil; QVERIFY(n_ceil.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_iend.receivers().first()->connect(n_ceil.emitters().first())); n_ceil.run(); n_iend.run(); QCOMPARE(qCeil(v_r), static_cast<int>(n_iend.value())); QVERIFY(n_iend.receivers().first()->disconnect(n_ceil.emitters().first())); // FLOOR dtkComposerNodeNumberOperatorUnaryFloor n_floor; QVERIFY(n_floor.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_iend.receivers().first()->connect(n_floor.emitters().first())); n_floor.run(); n_iend.run(); QCOMPARE(qFloor(v_r), static_cast<int>(n_iend.value())); QVERIFY(n_iend.receivers().first()->disconnect(n_floor.emitters().first())); // ROUND dtkComposerNodeNumberOperatorUnaryRound n_round; QVERIFY(n_round.receivers().first()->connect(n_r.emitters().first())); QVERIFY(n_iend.receivers().first()->connect(n_round.emitters().first())); n_round.run(); n_iend.run(); QCOMPARE(qRound(v_r), static_cast<int>(n_iend.value())); QVERIFY(n_iend.receivers().first()->disconnect(n_round.emitters().first())); }
void Vehicle::show(QPainter &painter) { // Точки для рисования полигона static QPointF polygonPoints[3]; if(body != NULL) { b2Vec2 position = body -> GetPosition(); float32 angle = body -> GetAngle(); for(int i = 0; i < pointsNum; ++i) { vehicleBrush.setColor(QColor(vectors[i].r, vectors[i].g, vectors[i].b)); painter.setBrush(vehicleBrush); polygonPoints[0].setX((vectors[i].length * qCos(angle + vectors[i].angle) + position.x) * 100); polygonPoints[0].setY((vectors[i].length * qSin(angle + vectors[i].angle) + position.y) * 100); polygonPoints[1].setX((vectors[(i == pointsNum - 1) ? 0 : (i + 1)].length * qCos(angle + vectors[(i == pointsNum - 1) ? 0 : (i + 1)].angle) + position.x) * 100); polygonPoints[1].setY((vectors[(i == pointsNum - 1) ? 0 : (i + 1)].length * qSin(angle + vectors[(i == pointsNum - 1) ? 0 : (i + 1)].angle) + position.y) * 100); polygonPoints[2].setX((position.x) * 100); polygonPoints[2].setY((position.y) * 100); painter.drawPolygon(polygonPoints, 3); } // Рисование колёс vehicleBrush.setColor(Qt::gray); painter.setBrush(vehicleBrush); int currentWheel = 0; for(int i = 0; i < pointsNum; ++i) { if(vectors[i].wheel) { b2Vec2 position = wheelsBodies[currentWheel] -> GetPosition(); float32 angle = wheelsBodies[currentWheel] -> GetAngle(); float32 radius = vectors[i].radius; painter.drawEllipse((position.x - radius) * 100, (position.y - radius) * 100, 200 * radius, 200 * radius); painter.drawLine(position.x * 100, position.y * 100, (position.x + radius * cos(angle)) * 100, (position.y + radius * sin(angle)) * 100); ++currentWheel; } } // Рисование пружин b2Vec2 position1, position2; float deltaLength; float currentLength; float springAngle; currentWheel = 0; for(int i = 0; i < pointsNum; ++i) { if(vectors[i].wheel) { position2 = wheelsBodies[currentWheel] -> GetPosition(); position1.Set(vectors[i].length * qCos(angle + vectors[i].angle) + position.x, vectors[i].length * qSin(angle + vectors[i].angle) + position.y); deltaLength = (position2 - position1).Length() / (springSegmentsNum + 2); springAngle = qAtan((position2 - position1).y / (position2 - position1).x); if((position2 - position1).x < 0.0f) { springAngle -= M_PI; } // Рисование части пружины возле машины currentLength = deltaLength * 0.5 + vectors[i].length; position2.Set(currentLength * qCos(angle + vectors[i].angle) + position.x, currentLength * qSin(angle + vectors[i].angle) + position.y); painter.drawLine(position1.x * 100, position1.y * 100, position2.x * 100, position2.y * 100); currentLength += deltaLength * 0.5; position1 = position2; position2.x = qCos(springAngle) * deltaLength * 0.5 + qSin(springAngle) * springWidth * 0.5; position2.y = qSin(springAngle) * deltaLength * 0.5 - qCos(springAngle) * springWidth * 0.5; position2 += position1; painter.drawLine(position1.x * 100, position1.y * 100, position2.x * 100, position2.y * 100); position1 = position2; position2.x = -qSin(springAngle) * springWidth; position2.y = qCos(springAngle) * springWidth; position2 += position1; painter.drawLine(position1.x * 100, position1.y * 100, position2.x * 100, position2.y * 100); for(int j = 0; j < springSegmentsNum; ++j) { position1 = position2; currentLength += deltaLength; position2.x = qCos(springAngle) * deltaLength + qSin(springAngle) * springWidth; position2.y = qSin(springAngle) * deltaLength - qCos(springAngle) * springWidth; position2 += position1; painter.drawLine(position1.x * 100, position1.y * 100, position2.x * 100, position2.y * 100); position1 = position2; position2.x = -qSin(springAngle) * springWidth; position2.y = qCos(springAngle) * springWidth; position2 += position1; painter.drawLine(position1.x * 100, position1.y * 100, position2.x * 100, position2.y * 100); } // Рисование части пружины возле колеса position1 = position2; currentLength += deltaLength; position2.x = qCos(springAngle) * deltaLength * 0.5 + qSin(springAngle) * springWidth * 0.5; position2.y = qSin(springAngle) * deltaLength * 0.5 - qCos(springAngle) * springWidth * 0.5; position2 += position1; painter.drawLine(position1.x * 100, position1.y * 100, position2.x * 100, position2.y * 100); position1 = position2; position2.x = qCos(springAngle) * deltaLength * 0.5; position2.y = qSin(springAngle) * deltaLength * 0.5; position2 += position1; painter.drawLine(position1.x * 100, position1.y * 100, position2.x * 100, position2.y * 100); ++currentWheel; } } } else { for(int i = 0; i < bodyParts.size(); ++i) { vehicleBrush.setColor(QColor(vectors[i].r, vectors[i].g, vectors[i].b)); painter.setBrush(vehicleBrush); b2Vec2 position = bodyParts[i] -> GetPosition(); float32 angle = bodyParts[i] -> GetAngle(); polygonPoints[0].setX((vectors[i].length * qCos(angle + vectors[i].angle) + position.x) * 100); polygonPoints[0].setY((vectors[i].length * qSin(angle + vectors[i].angle) + position.y) * 100); polygonPoints[1].setX((vectors[(i == pointsNum - 1) ? 0 : (i + 1)].length * qCos(angle + vectors[(i == pointsNum - 1) ? 0 : (i + 1)].angle) + position.x) * 100); polygonPoints[1].setY((vectors[(i == pointsNum - 1) ? 0 : (i + 1)].length * qSin(angle + vectors[(i == pointsNum - 1) ? 0 : (i + 1)].angle) + position.y) * 100); polygonPoints[2].setX((position.x) * 100); polygonPoints[2].setY((position.y) * 100); painter.drawPolygon(polygonPoints, 3); } // Рисование колёс vehicleBrush.setColor(Qt::gray); painter.setBrush(vehicleBrush); int currentWheel = 0; for(int j = 0; j < pointsNum; ++j) { if(vectors[j].wheel) { b2Vec2 position = wheelsBodies[currentWheel] -> GetPosition(); float32 angle = wheelsBodies[currentWheel] -> GetAngle(); float32 radius = vectors[j].radius; painter.drawEllipse((position.x - radius) * 100, (position.y - radius) * 100, 200 * radius, 200 * radius); painter.drawLine(position.x * 100, position.y * 100, (position.x + radius * cos(angle)) * 100, (position.y + radius * sin(angle)) * 100); ++currentWheel; } } } }
void Matrix::getRotation(const cv::Point &massCenter, EndoscopeData &angleBefore, EndoscopeData &angleAfter, EndoscopeData &motor) const { if(qSqrt(square(massCenter.x - center.x()) + square(massCenter.y - center.y())) <= 125*cols/1920) return; EndoscopeData angle; angle.rotation = qAtan(static_cast<double>(qAbs(massCenter.x-center.x()))/static_cast<double>(qAbs(massCenter.y-center.y()))) * 180/M_PI; //Angle_Rot // Identifikation des Quadranten, in dem sich der POI befindet if(massCenter.x >= center.x()) //rechte hälfte { if(massCenter.y <= center.y()) { //rechts oben (1) angleAfter.quadrant = 1; //if (angleBefore.quadrant == 4 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.rotation = angleBefore.rotation + angle.rotation/12; if(angleAfter.rotation < -34) { angleAfter.rotation = -34; } else if(angleAfter.rotation > 34) { angleAfter.rotation = 34; } motor.rotation = -17.755*angleAfter.rotation + 2810; } else { //rechts unten (4) angleAfter.quadrant = 4; //if (angleBefore.quadrant == 1 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.rotation = angleBefore.rotation - angle.rotation/12; if(angleAfter.rotation < -34) { angleAfter.rotation = -34; } else if(angleAfter.rotation > 34) { angleAfter.rotation = 34; } motor.rotation = -17.755*angleAfter.rotation + 2810; } } else //linke hälfte { if(massCenter.y <= center.y()) { //links oben (2) angleAfter.quadrant = 2; //if (angleBefore.quadrant == 3 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.rotation = angleBefore.rotation - angle.rotation/12; if(angleAfter.rotation < -34) { angleAfter.rotation = -34; } else if(angleAfter.rotation > 34) { angleAfter.rotation = 34; } motor.rotation = -17.755*angleAfter.rotation + 2810; } else //links unten (3) { angleAfter.quadrant = 3; //if (angleBefore.quadrant == 2 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.rotation = angleBefore.rotation + angle.rotation/12; if(angleAfter.rotation < -34) { angleAfter.rotation = -34; } else if(angleAfter.rotation > 34) { angleAfter.rotation = 34; } motor.rotation = -17.755*angleAfter.rotation + 2810; } } angleBefore.rotation = angleAfter.rotation; }
void dtkComposerNodeNumberOperatorUnaryAtan::run(void) { double *value = d->receiver.data<double>(); *value = qAtan(*value); d->emitter.setData<double>(value); }
return angle1 < angle2; }); // 3) Compute the intersection int i = 0; foreach(QObject* line, lines) { #ifdef CARPENTER_DEBUG qDebug() << "SketchJoint: #" << i << ":" << line->property("identifier").toInt(); #endif i++; } // List of vertices of the joint mesh QList<QVector2D> vertices; double preconditionAngle = qRadiansToDegrees(2*qAtan(SketchLine::radius/SketchLine::edgeShortcut)); #ifdef CARPENTER_DEBUG qDebug() << "SketchJoint: preconditionAngle: " << preconditionAngle; #endif for(int lineIndex = 0; lineIndex < lines.size(); lineIndex++) { /** * Line 1 is characterized by A = (x1,y1) and B = (x2,y2) * Line 2 is characterized by C = (x3,y3) and D = (x4,y4) */ QObject* line1 = lines.at(lineIndex); QObject* line2 = lines.at((lineIndex + 1) % lines.size()); #ifdef CARPENTER_DEBUG
double CCD::getActualFOVy(Telescope *telescope, Lens *lens) const { const double lens_multipler = (lens != NULL ? lens->multipler() : 1.0f); double fovY = RADIAN_TO_DEGREES * 2 * qAtan(this->chipWidth() /(2.0 * telescope->focalLength() * lens_multipler)); return fovY; }
void SunMenuItemView::reinitializeDisplayedItemPosition() { qint32 maxWidth = width(); qint32 maxHeight; QGraphicsItem* gi = displayedItem()->graphicsItem(); //default gi->resetTransform(); // Calculate maxHeight as smaller chord(only for small sweepLengths) if (sweepLength() <= 90) { qreal biggerChord = 2 * (innerRadius() + maxWidth) * /*qAbs*/(qSin((M_PI / 180) * sweepLength() / 2)); qreal smallerChord = 2 * innerRadius() * /*qAbs*/(qSin((M_PI / 180) * sweepLength() / 2)); maxHeight = (0.2 * smallerChord + 1.4 * biggerChord) / 2; } else maxHeight = displayedItem()->maximumHeight(); //hide item if it too small if (maxWidth < 10 || maxHeight < 5) { gi->hide(); return; } QRectF graphicsItemRect; if (sweepLength() == 360 && innerRadius() == 0) { displayedItem()->setMaximumSize(2 * maxWidth /*diameter*/, maxHeight); graphicsItemRect = gi->boundingRect(); gi->setPos(-graphicsItemRect.width() / 2, -graphicsItemRect.height() / 2); gi->show(); return; } displayedItem()->setMaximumSize(maxWidth - 10, maxHeight); graphicsItemRect = gi->boundingRect(); ///////////////////////////////////////////////////////////////////////////////// //positioning mDisplayedItem (rotation and coordinates). qreal rotationAngle = startAngle() + sweepLength() / 2; // Getting distance and angle (polar coordinates) + some centering adjustments // We assume that (0,0) item's coordinate is it's top left corner //(like QGraphicsSimpleTextItem and QGraphicsProxyWidget). qreal angle, distance; if (rotationAngle >= 270 || rotationAngle <= 90) { distance = innerRadius() + maxWidth / 2 - graphicsItemRect.width() / 2; angle = rotationAngle + (180 / M_PI) * qAtan(graphicsItemRect.height() / (2 * distance)); } else { distance = innerRadius() + maxWidth / 2 + graphicsItemRect.width() / 2; angle = rotationAngle - (180 / M_PI) * qAtan(graphicsItemRect.height() / (2 * distance)); rotationAngle -= 180; } gi->setPos(distance * qCos((M_PI / 180) * angle), -distance * qSin((M_PI / 180) * angle)); gi->setRotation(-rotationAngle); //minus - because this function rotates clockwise. gi->show(); /////////////////////////////////////////////////////////////////////////////////// }
void Matrix::getRotationAndBending(const cv::Point &massCenter, EndoscopeData &angleBefore, EndoscopeData &angleAfter, EndoscopeData &motor) const { if(qSqrt(square(massCenter.x - center.x()) + square(massCenter.y - center.y())) >= 125*cols/1920) return; EndoscopeData angle; angle.rotation = qAtan(static_cast<double>(qAbs(massCenter.x-center.x()))/static_cast<double>(qAbs(massCenter.y-center.y()))) * 180/M_PI; //Angle_Rot // Identifikation des Quadranten, in dem sich der POI befindet if(massCenter.x >= center.x()) //rechte hälfte { if(massCenter.y <= center.y()) { //rechts oben (1) angleAfter.quadrant = 1; if (angleBefore.quadrant == 4 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.rotation = angleBefore.rotation + angle.rotation/3; if(angleAfter.rotation < -34) { angleAfter.rotation = -34; } else if(angleAfter.rotation > 34) { angleAfter.rotation = 34; } motor.rotation = -17.755*angleAfter.rotation + 2810; } else { //rechts unten (4) angleAfter.quadrant = 4; if (angleBefore.quadrant == 1 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.rotation = angleBefore.rotation - angle.rotation/3; if(angleAfter.rotation < -34) { angleAfter.rotation = -34; } else if(angleAfter.rotation > 34) { angleAfter.rotation = 34; } motor.rotation = -17.755*angleAfter.rotation + 2810; } } else //linke hälfte { if(massCenter.y <= center.y()) { //links oben (2) angleAfter.quadrant = 2; if (angleBefore.quadrant == 3 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.rotation = angleBefore.rotation - angle.rotation/3; if(angleAfter.rotation < -34) { angleAfter.rotation = -34; } else if(angleAfter.rotation > 34) { angleAfter.rotation = 34; } motor.rotation = -17.755*angleAfter.rotation + 2810; } else //links unten (3) { angleAfter.quadrant = 3; if (angleBefore.quadrant == 2 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.rotation = angleBefore.rotation + angle.rotation/3; if(angleAfter.rotation < -34) { angleAfter.rotation = -34; } else if(angleAfter.rotation > 34) { angleAfter.rotation = 34; } motor.rotation = -17.755*angleAfter.rotation + 2810; } } int alpha = angleBefore.rotation - angleAfter.rotation; double k = 900; //Koeffizent für Abstand zwischen Endoskop und Nasenhöhle double y = qAbs(qSin((alpha+90)*M_PI/180.0)*(massCenter.x-center.x()) + cos((alpha+90)*M_PI/180.0)*(center.y()-massCenter.y)); angle.bending = qAtan(y/k) * 180.0/M_PI; //Substitute with calculation(absolute value) switch (angleAfter.quadrant) { case 1: angleAfter.bending = angleBefore.bending - angle.bending; if(angleAfter.bending < -60) { angleAfter.bending = -60; } else if(angleAfter.bending > 60) { angleAfter.bending = 60; } motor.bending = 5.75*angleAfter.bending + 2384; break; case 2: angleAfter.bending = angleBefore.bending - angle.bending; if(angleAfter.bending < -60) { angleAfter.bending = -60; } else if(angleAfter.bending > 60) { angleAfter.bending = 60; } motor.bending = 5.75*angleAfter.bending + 2384; break; case 3: angleAfter.bending = angleBefore.bending + angle.bending; if(angleAfter.bending < -60) { angleAfter.bending = -60; } else if(angleAfter.bending > 60) { angleAfter.bending = 60; } motor.bending = 5.432*angleAfter.bending + 2415; break; case 4: angleAfter.bending = angleBefore.bending + angle.bending; if(angleAfter.bending < -60) { angleAfter.bending = -60; } else if(angleAfter.bending > 60) { angleAfter.bending = 60; } motor.bending = 5.432*angleAfter.bending + 2415; break; default: break; } angleBefore = angleAfter; }
void Matrix::getBending(const cv::Point &massCenter, EndoscopeData &angleBefore, EndoscopeData &angleAfter, EndoscopeData &motor) const { if(qSqrt(square(massCenter.x - center.x()) + square(massCenter.y - center.y())) <= 125*cols/1920) return; double k = 2000; //Koeffizent für Abstand zwischen Endoskop und Nasenhöhle EndoscopeData angle; angle.bending = qAtan(static_cast<double>(qAbs(massCenter.y - center.y()))/k) * 180.0/M_PI; //Angle_Bend // Identifikation des Quadranten, in dem sich der POI befindet if(massCenter.x >= center.x()) //rechte hälfte { if(massCenter.y <= center.y()) //rechts oben(1) { angleAfter.quadrant = 1; if (angleBefore.quadrant == 4 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.bending = angleBefore.bending - angle.bending; if(angleAfter.bending < -60) { angleAfter.bending = -60; } else if(angleAfter.bending > 60) { angleAfter.bending = 60; } motor.bending = 5.75*angleAfter.bending + 2384; } else //rechts unten(4) { angleAfter.quadrant = 4; if (angleBefore.quadrant == 1 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.bending = angleBefore.bending + angle.bending; if(angleAfter.bending < -60) { angleAfter.bending = -60; } else if(angleAfter.bending > 60) { angleAfter.bending = 60; } motor.bending = 5.432*angleAfter.bending + 2415; } } else //linke hälfte { if(massCenter.y <= center.y()) //links oben(2) { angleAfter.quadrant = 2; if (angleBefore.quadrant == 3 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.bending = angleBefore.bending - angle.bending; if(angleAfter.bending < -60) { angleAfter.bending = -60; } else if(angleAfter.bending > 60) { angleAfter.bending = 60; } motor.bending = 5.75*angleAfter.bending + 2384; } else //links unten(3) { angleAfter.quadrant = 3; if (angleBefore.quadrant == 2 && qAbs(massCenter.y - center.y()) < 125*rows/1080) return; angleAfter.bending = angleBefore.bending + angle.bending; if(angleAfter.bending < -60) { angleAfter.bending = -60; } else if(angleAfter.bending > 60) { angleAfter.bending = 60; } motor.bending = 5.432*angleAfter.bending + 2415; } } angleBefore = angleAfter; }
void dtkComposerNodeTestCase::testNumberComparator(void) { double v_0 = 4. * qAtan(1.); double v_1 = 4. * qAtan(1.) + 0.00000000000001 ; dtkComposerNodeReal n_0; dtkComposerNodeReal n_1; n_0.setValue(v_0); n_1.setValue(v_1); n_0.run(); n_1.run(); dtkComposerNodeBoolean n_end; // EQUAL dtkComposerNodeNumberComparatorEqual n_equal; QVERIFY(n_equal.receivers().first()->connect(n_0.emitters().first())); QVERIFY(n_equal.receivers().last()->connect( n_1.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_equal.emitters().first())); n_equal.run(); n_end.run(); QCOMPARE((v_0 == v_1), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_equal.emitters().first())); // NOT EQUAL dtkComposerNodeNumberComparatorNotequal n_notequal; QVERIFY(n_notequal.receivers().first()->connect(n_0.emitters().first())); QVERIFY(n_notequal.receivers().last()->connect( n_1.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_notequal.emitters().first())); n_notequal.run(); n_end.run(); QCOMPARE((v_0 != v_1), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_notequal.emitters().first())); // GREATER THAN dtkComposerNodeNumberComparatorGt n_gt; QVERIFY(n_gt.receivers().first()->connect(n_0.emitters().first())); QVERIFY(n_gt.receivers().last()->connect( n_1.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_gt.emitters().first())); n_gt.run(); n_end.run(); QCOMPARE((v_0 > v_1), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_gt.emitters().first())); // LESSER THAN dtkComposerNodeNumberComparatorLt n_lt; QVERIFY(n_lt.receivers().first()->connect(n_0.emitters().first())); QVERIFY(n_lt.receivers().last()->connect( n_1.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_lt.emitters().first())); n_lt.run(); n_end.run(); QCOMPARE((v_0 < v_1), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_lt.emitters().first())); // GREATER THAN OR EQUAL dtkComposerNodeNumberComparatorGte n_gte; QVERIFY(n_gte.receivers().first()->connect(n_0.emitters().first())); QVERIFY(n_gte.receivers().last()->connect( n_1.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_gte.emitters().first())); n_gte.run(); n_end.run(); QCOMPARE((v_0 >= v_1), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_gte.emitters().first())); // LESSER THAN OR EQUAL dtkComposerNodeNumberComparatorLte n_lte; QVERIFY(n_lte.receivers().first()->connect(n_0.emitters().first())); QVERIFY(n_lte.receivers().last()->connect( n_1.emitters().first())); QVERIFY(n_end.receivers().first()->connect(n_lte.emitters().first())); n_lte.run(); n_end.run(); QCOMPARE((v_0 <= v_1), n_end.value()); QVERIFY(n_end.receivers().first()->disconnect(n_lte.emitters().first())); }
/********************************************************************************* * Function: get the keypoints of end-arrow. * Parameters: k, end-point, key-point1, key-point2 * Return: none ********************************************************************************/ void SamDrawItemBase::getEndArrowKeypoints(const qreal &dK, const QPointF &qpEndPt, LINE_KEY_POINT_T &stKeyppoints, const qreal dXdirect, const qreal dYdirect) { const qreal dL = 12.0; qreal dKFactor = 0.0; qreal dVAngle = 0.0; const qreal dDelta = 0.01; QPointF qpKpt0, qpKpt1, qpKpt2, qpKpt3, qpKpt4, qpKpt5; /*K factor -1 or +1*/ if (qFabs(dK) > 0) { dKFactor = qFabs(dK) / dK; } else { dKFactor = 1.0; } /*The angle according to K value*/ qreal dAngle = qAtan(dK); /*Calculate the key point0*/ if (dKFactor > 0) { qpKpt0.rx() = qpEndPt.x() - dKFactor * dXdirect * (dL * qCos(dAngle)); qpKpt0.ry() = qpEndPt.y() - dKFactor * dYdirect * (dL * qSin(dAngle)); } else { qpKpt0.rx() = qpEndPt.x() + dKFactor * dXdirect * (dL * qCos(dAngle)); qpKpt0.ry() = qpEndPt.y() - dKFactor * dYdirect * (dL * qSin(dAngle)); } /*The angle according to the K value of vertical line*/ if (dK >= 99999) { dVAngle = 90; } else if (dK > dDelta || dK < -dDelta) { dVAngle = qAtan(-1 / dK); } else if (dK > -dDelta && dK < dDelta) { dVAngle = 0; } /*Calculate the key point1 and key point2*/ qpKpt1.rx() = qpKpt0.x() - ((dL/2) * qCos(dVAngle)); qpKpt1.ry() = qpKpt0.y() - ((dL/2) * qSin(dVAngle)); qpKpt2.rx() = qpKpt0.x() + ((dL/2) * qCos(dVAngle)); qpKpt2.ry() = qpKpt0.y() + ((dL/2) * qSin(dVAngle)); QPointF qpCenter; qpCenter.rx() = (qpEndPt.x() + qpKpt0.x()) / 2; qpCenter.ry() = (qpEndPt.y() + qpKpt0.y()) / 2; /* qpKpt3.rx() = qpCenter.x() - ((2*dL/3) * qCos(dVAngle)); qpKpt3.ry() = qpCenter.y() - ((2*dL/3) * qSin(dVAngle)); qpKpt4.rx() = qpCenter.x() + ((2*dL/3) * qCos(dVAngle)); qpKpt4.ry() = qpCenter.y() + ((2*dL/3) * qSin(dVAngle)); */ qpKpt3.rx() = qpCenter.x() - (dL * qCos(dVAngle)); qpKpt3.ry() = qpCenter.y() - (dL * qSin(dVAngle)); qpKpt4.rx() = qpCenter.x() + (dL * qCos(dVAngle)); qpKpt4.ry() = qpCenter.y() + (dL * qSin(dVAngle)); qpKpt5.rx() = (qpCenter.x() + qpKpt0.x()) / 2; qpKpt5.ry() = (qpCenter.y() + qpKpt0.y()) / 2; stKeyppoints.qpKeyPoint0 = qpKpt0; stKeyppoints.qpKeyPoint1 = qpKpt1; stKeyppoints.qpKeyPoint2 = qpKpt2; stKeyppoints.qpKeyPoint3 = qpKpt3; stKeyppoints.qpKeyPoint4 = qpKpt4; stKeyppoints.qpKeyPoint5 = qpKpt5; }
struct myRect toolpath::trackToMyRect(struct track t, qint64 offset) { struct myRect r; QPoint p1; double k,ki; double angle; t.width+=offset; if((t.pointend.x()-t.pointstart.x())==0)//vertical track { p1.setX(t.width/2); p1.setY(0); if(t.pointend.y()>t.pointstart.y()) { r.p1=t.pointstart-p1; r.p2=t.pointend-p1; r.p3=t.pointend+p1; r.p4=t.pointstart+p1; } else { r.p1=t.pointstart+p1; r.p2=t.pointend+p1; r.p3=t.pointend-p1; r.p4=t.pointstart-p1; } } else if((t.pointend.y()-t.pointstart.y())==0)//horizontal track { p1.setX(0); p1.setY(t.width/2); if(t.pointend.x()>t.pointstart.x()) { r.p1=t.pointstart+p1; r.p2=t.pointend+p1; r.p3=t.pointend-p1; r.p4=t.pointstart-p1; } else { r.p1=t.pointstart-p1; r.p2=t.pointend-p1; r.p3=t.pointend+p1; r.p4=t.pointstart+p1; } } else { k=(t.pointend.y()-t.pointstart.y())*1.0/(t.pointend.x()-t.pointstart.x()); ki=-1/k; angle=qAtan(ki); //if(angle<0) //angle+=3.1415926;//3.1415926 p1.setX(t.width/2*qCos(angle)); p1.setY(t.width/2*qSin(angle)); if(t.pointstart.y()>t.pointend.y()) { r.p1=t.pointstart+p1; r.p2=t.pointend+p1; r.p3=t.pointend-p1; r.p4=t.pointstart-p1; } else { r.p1=t.pointstart-p1; r.p2=t.pointend-p1; r.p3=t.pointend+p1; r.p4=t.pointstart+p1; } } return r; }
void QFilter::MakeWindow(int wtype, int size, float *window) { int i, j, midn, midp1, midm1; float freq, rate, sr1, angle, expn, expsum, cx, two_pi; midn = size / 2; midp1 = (size + 1) / 2; midm1 = (size - 1) / 2; two_pi = 8.0f * qAtan(1.0); freq = two_pi / size; rate = 1.0 / midn; angle = 0.0; expn = log(2.0) / midn + 1.0; expsum = 1.0; switch (wtype) { case 1: // RECTANGULAR_WINDOW for (i = 0; i < size; i++) window[i] = 1.0; break; case 2: // HANNING_WINDOW for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq) window[j] = (window[i] = 0.5 - 0.5 * cos(angle)); break; case 3: // WELCH_WINDOW for (i = 0, j = size - 1; i <= midn; i++, j--) window[j] = (window[i] = 1.0 - (float)sqrt((float)((i - midm1) / midp1))); break; case 4: // PARZEN_WINDOW for (i = 0, j = size - 1; i <= midn; i++, j--) window[j] = (window[i] = 1.0 - ((float)fabs((float)(i - midm1) / midp1))); break; case 5: // BARTLETT_WINDOW for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += rate) window[j] = (window[i] = angle); break; case 6: // HAMMING_WINDOW for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq) window[j] = (window[i] = 0.5F - 0.46 * cos(angle)); break; case 7: // BLACKMAN2_WINDOW for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq) { cx = cos(angle); window[j] = (window[i] = (.34401 + (cx * (-.49755 + (cx * .15844))))); } break; case 8: // BLACKMAN3_WINDOW for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq) { cx = cos(angle); window[j] = (window[i] = (.21747 + (cx * (-.45325 + (cx * (.28256 - (cx * .04672))))))); } break; case 9: // BLACKMAN4_WINDOW for (i = 0, j = size - 1, angle = 0.0; i <= midn; i++, j--, angle += freq) { cx = cos(angle); window[j] = (window[i] = (.084037 + (cx * (-.29145 + (cx * (.375696 + (cx * (-.20762 + (cx * .041194))))))))); } break; case 10: // EXPONENTIAL_WINDOW for (i = 0, j = size - 1; i <= midn; i++, j--) { window[j] = (window[i] = expsum - 1.0); expsum *= expn; } break; case 11: // RIEMANN_WINDOW sr1 = two_pi / size; for (i = 0, j = size - 1; i <= midn; i++, j--) { if (i == midn) window[j] = (window[i] = 1.0); else { cx = sr1 * (midn - i); window[i] = sin(cx) / cx; window[j] = window[i]; } } break; case 12: // BLACKMANHARRIS_WINDOW { float a0 = 0.35875f, a1 = 0.48829f, a2 = 0.14128f, a3 = 0.01168f; for (i = 0; i < size; i++) { window[i] = a0 - a1* qCos(TWOPI * (i+0.5)/size) + a2* qCos(2.0 * TWOPI * (i+0.5)/size) - a3* qCos(3.0 * TWOPI * (i+0.5)/size); } } break; default: return; } }
qreal PI() { return 4 * qAtan(1); }