QColor ColorWheel::posColor(const QPoint &point) { if( ! wheel.rect().contains(point) ) return QColor(); if(inWheel){ qreal hue = 0; int r = qMin(width(), height()) / 2; if( point.x() > r ){ if(point.y() < r ){ //1 hue = 90 - (qAtan2( (point.x() - r) , (r - point.y()) ) / 3.14 / 2 * 360); }else{ //4 hue = 270 + (qAtan2( (point.x() - r) , (point.y() - r ) ) / 3.14 / 2 * 360); } }else{ if(point.y() < r ){ //2 hue = 90 + (qAtan2( (r - point.x()) , (r - point.y()) ) / 3.14 / 2 * 360); }else{ //3 hue = 270 - (qAtan2( (r - point.x()) , (point.y() - r )) / 3.14 / 2 * 360); } } hue = hue>359?359:hue; hue = hue<0?0:hue; return QColor::fromHsv(hue, current.saturation(), current.value()); } return QColor(); }
/** * @param x x coordinate * @param y y coordinate */ void CanvasView::moveDrag(int x, int y) { const int dx = _dragx - x; const int dy = _dragy - y; if(_isdragging==DRAG_ROTATE) { qreal preva = qAtan2( width()/2 - _dragx, height()/2 - _dragy ); qreal a = qAtan2( width()/2 - x, height()/2 - y ); setRotation(rotation() + qRadiansToDegrees(preva-a)); } else if(_isdragging==DRAG_ZOOM) { if(dy!=0) { float delta = qBound(-1.0, dy / 100.0, 1.0); if(delta>0) { setZoom(_zoom * (1+delta)); } else if(delta<0) { setZoom(_zoom / (1-delta)); } } } else if(_isdragging==DRAG_QUICKADJUST1) { if(dy!=0) { float delta = qBound(-2.0, dy / 10.0, 2.0); doQuickAdjust1(delta); } } else { QScrollBar *ver = verticalScrollBar(); ver->setSliderPosition(ver->sliderPosition()+dy); QScrollBar *hor = horizontalScrollBar(); hor->setSliderPosition(hor->sliderPosition()+dx); } _dragx = x; _dragy = y; }
QColor NQColorWheel::colorFromPosition(const QPoint &point) { if (!pixmapWheel_.rect().contains(point)) return QColor(); if (insideWheel_) { qreal hue = 0; int r = qMin(width(), height()) / 2; if (point.x() > r) { if (point.y() < r) { //1 hue = 90 - (qAtan2((point.x() - r) , (r - point.y()) ) / 3.14 / 2 * 360); } else { //4 hue = 270 + (qAtan2( (point.x() - r) , (point.y() - r ) ) / 3.14 / 2 * 360); } } else { if (point.y() < r) { //2 hue = 90 + (qAtan2( (r - point.x()) , (r - point.y()) ) / 3.14 / 2 * 360); } else { //3 hue = 270 - (qAtan2( (r - point.x()) , (point.y() - r )) / 3.14 / 2 * 360); } } hue = hue>359?359:hue; hue = hue<0?0:hue; return QColor::fromHsv(hue, currentColor_.saturation(), currentColor_.value()); } if (insideSquare_) { // region of the widget int w = qMin(width(), height()); // radius of outer circle qreal r = w/2-margin_; // radius of inner circle qreal ir = r-wheelWidth_; // left corner of square qreal m = w/2.0-ir/qSqrt(2); QPoint p = point - QPoint(m, m); qreal SquareWidth = 2*ir/qSqrt(2); qreal s = p.x()/SquareWidth; if (s<0) s = 0.0; if (s>1) s = 1.0; //if (s<minimumS_) s = minimumS_; qreal v = p.y()/SquareWidth; if (v<0) v = 0.0; if (v>1) v = 1.0; return QColor::fromHsvF(currentColor_.hueF(), minimumS_ + s*(1.0-minimumS_), v); } return QColor(); }
void DrawingPolylineItem::render(QPainter* painter, const DrawingStyleOptions& styleOptions) { DrawingItemPoint* point0 = point(0); DrawingItemPoint* point1 = point(numberOfPoints() - 1); QList<DrawingItemPoint*> lPoints = points(); QPolygonF polygon; DrawingItemPoint* otherPoint; qreal theta; // Polyline for(auto pointIter = lPoints.begin(); pointIter != lPoints.end(); pointIter++) polygon.append((*pointIter)->pos()); setupPainter(painter, styleOptions, pen()); painter->drawPolyline(polygon); // Arrows if (pen().style() != Qt::NoPen) { QPen arrowPen = pen(); arrowPen.setStyle(Qt::SolidLine); setupPainter(painter, styleOptions, arrowPen, styleOptions.outputBrush(DrawingStyleOptions::Background)); otherPoint = point(1); if (otherPoint) { theta = qAtan2(otherPoint->y() - point0->y(), otherPoint->x() - point0->x()) * 180.0 / 3.1414592654; if (Drawing::magnitude(otherPoint->pos() - point0->pos()) > startArrowSize()) startArrow().render(painter, point0->pos(), theta); } otherPoint = point(numberOfPoints() - 2); if (otherPoint) { theta = qAtan2(otherPoint->y() - point1->y(), otherPoint->x() - point1->x()) * 180.0 / 3.1414592654; if (Drawing::magnitude(otherPoint->pos() - point1->pos()) > endArrowSize()) endArrow().render(painter, point1->pos(), theta); } } #ifdef DEBUG_DRAW_ITEM_SHAPE painter->setBrush(Qt::magenta); painter->setPen(QPen(Qt::magenta, 1)); painter->drawPath(shape()); #endif }
QColor ColorWheel::posColor(const QPoint& point) { if (! this->rect().contains(point)) return QColor(); if (inWheel_) { qreal hue = 0; int r = qMin(width(), height()) / 2; if (point.x() > r) { if (point.y() < r) { //1 hue = 90 - (qAtan2((point.x() - r), (r - point.y())) / 3.14 / 2 * 360); } else { //4 hue = 270 + (qAtan2((point.x() - r), (point.y() - r)) / 3.14 / 2 * 360); } } else { if (point.y() < r) { //2 hue = 90 + (qAtan2((r - point.x()), (r - point.y())) / 3.14 / 2 * 360); } else { //3 hue = 270 - (qAtan2((r - point.x()), (point.y() - r)) / 3.14 / 2 * 360); } } int hueI = clamp(static_cast<int>(hue), 0, 359); return QColor::fromHsv(hueI, currentColor_.saturation(), currentColor_.value()); } if (inSquare_) { // region of the widget int w = qMin(width(), height()); // radius of outer circle qreal r = w/2-margin_; // radius of inner circle qreal ir = r-wheelWidth_; // left corner of square qreal m = w/2.0 - ir/qSqrt(2); QPoint p = point - QPoint(m, m); qreal SquareWidth = (ir * qSqrt(2)); return QColor::fromHsv(currentColor_.hueF(), clamp(static_cast<int>(p.x() / SquareWidth * 255.0), 0, 255), clamp(static_cast<int>(p.y() / SquareWidth * 255.0), 0, 255)); } return QColor(); }
double ArcStyle::endValueFromPoint(qreal x, qreal y) { qreal theta = qAtan2(x,-y); qreal angle = fmod((theta * M_180_D_PI) + 360,360); double v = qFloor(angle) * m_scale; return v; }
void RLIDisplayWidget::moveCoursor(const QPoint& pos, bool repaint, RadarScale* curscale) { QPointF cen = _controlsEngine->getCenterPos(); float scale = (_rli_scale.len*1852.f) / _maskEngine->getRadius(); QVector2D cursor_coords = RLIMath::pos_to_coords(QVector2D(12.5000f, -81.6000f), cen, pos, scale); emit cursor_moved(cursor_coords); const char * dist_fmt = NULL; if(repaint) _controlsEngine->setCursorPos(pos); float peleng = 90.0 * qAtan2(pos.x() - cen.x(), - pos.y() + cen.y()) / acos(0); if (peleng < 0) peleng = 360 + peleng; float distance = sqrt(pow(pos.y() - cen.y(), 2) + pow(pos.x() - cen.x(), 2)); float ratio = 1; if(curscale) { const rli_scale_t * scale = curscale->getCurScale(); if(scale) { ratio = scale->len / maskEngine()->getRadius(); dist_fmt = scale->val_fmt; } } distance *= ratio; emit cursor_moved(peleng, distance, dist_fmt); }
QPainterPath CharLineRecord::painterPath(qreal width_factor) { QPainterPath path; qreal radius = width * width_factor / 2.0; qreal sx = xs, sy = ys; qreal ex = xe, ey = ye; qreal dx = ex - sx, dy = ey - sy; qreal a = qAtan2(dy, dx); qreal rsina = radius * qSin(a), rcosa = radius * qCos(a); path.moveTo(sx + rsina, -(sy - rcosa)); path.lineTo(sx - rsina, -(sy + rcosa)); path.lineTo(ex - rsina, -(ey + rcosa)); path.lineTo(ex + rsina, -(ey - rcosa)); path.closeSubpath(); if (shape == R) { path.addEllipse(QPointF(sx, -sy), radius, radius); path.addEllipse(QPointF(ex, -ey), radius, radius); } else { qreal radius2 = radius * 2; path.addRect(sx-radius, -sy-radius, radius2, radius2); path.addRect(ex-radius, -ey-radius, radius2, radius2); } return path; }
double OsmAnd::Model::Road::getDirectionDelta( uint32_t originIdx, bool forward, float distance ) const { auto itPoint = (_points.begin() + originIdx); const auto itOriginPoint = itPoint; float scannedDistance = 0.0; do { if(forward) { itPoint++; if(itPoint == _points.end()) { itPoint--; break; } } else { if(itPoint == _points.begin()) break; itPoint--; } // translate into meters scannedDistance += Utilities::x31toMeters(qAbs((int64_t)itPoint->x - (int64_t)itOriginPoint->x)) + Utilities::y31toMeters(qAbs((int64_t)itPoint->y - (int64_t)itOriginPoint->y)); } while ( scannedDistance < distance ); return -qAtan2(itOriginPoint->x - itPoint->x, itOriginPoint->y - itPoint->y); }
Qt::ArrowType ArrowDiscWidget::arrowUnderMouse(const QPoint &position) const { const int min_radius_pow2 = 5*5; const int max_radius_pow2 = 28*28; // mouse coordinates relative to widget topleft int mx = position.x(); int my = position.y(); // center coordinates relative to widget topleft int cx = width()/2; int cy = height()/2; int px = mx - cx; int py = my - cy; int const distance_pow2 = px*px + py*py; if ( distance_pow2 >= min_radius_pow2 && distance_pow2 <= max_radius_pow2 ) { int const angle = int( qAtan2( py, px ) * RAD2DEG ); Q_ASSERT( -180 <= angle && angle <= 180 ); if ( angle >= 135 || angle < -135 ) { return Qt::LeftArrow; } else if ( angle < -45 ) { return Qt::UpArrow; } else if ( angle < 45 ) { return Qt::RightArrow; } else { return Qt::DownArrow; } } return Qt::NoArrow; }
int QDialPrivate::valueFromPoint(const QPoint &p) const { Q_Q(const QDial); double yy = (double)q->height()/2.0 - p.y(); double xx = (double)p.x() - q->width()/2.0; double a = (xx || yy) ? qAtan2(yy, xx) : 0; if (a < Q_PI / -2) a = a + Q_PI * 2; int dist = 0; int minv = minimum, maxv = maximum; if (minimum < 0) { dist = -minimum; minv = 0; maxv = maximum + dist; } int r = maxv - minv; int v; if (wrapping) v = (int)(0.5 + minv + r * (Q_PI * 3 / 2 - a) / (2 * Q_PI)); else v = (int)(0.5 + minv + r* (Q_PI * 4 / 3 - a) / (Q_PI * 10 / 6)); if (dist > 0) v -= dist; return !invertedAppearance ? bound(v) : maximum - bound(v); }
bool LambertAzimuthalProjection::geoCoordinates( const int x, const int y, const ViewportParams *viewport, qreal& lon, qreal& lat, GeoDataCoordinates::Unit unit ) const { const qint64 radius = viewport->radius(); // Calculate how many degrees are being represented per pixel. const qreal centerLon = viewport->centerLongitude(); const qreal centerLat = viewport->centerLatitude(); const qreal rx = ( - viewport->width() / 2 + x ); const qreal ry = ( viewport->height() / 2 - y ); const qreal p = qMax( qSqrt( rx*rx + ry*ry ), qreal(0.0001) ); // ensure we don't divide by zero const qreal c = 2 * qAsin( p / (qSqrt(2) * radius) ); const qreal sinc = qSin(c); lon = centerLon + qAtan2( rx*sinc , ( p*qCos( centerLat )*qCos( c ) - ry*qSin( centerLat )*sinc ) ); while ( lon < -M_PI ) lon += 2 * M_PI; while ( lon > M_PI ) lon -= 2 * M_PI; lat = qAsin( qCos(c)*qSin(centerLat) + (ry*sinc*qCos(centerLat))/p ); if ( unit == GeoDataCoordinates::Degree ) { lon *= RAD2DEG; lat *= RAD2DEG; } return true; }
BurstShot::BurstShot(GameState *game, int x, int y, float angle, polarType polarity): ShotEntity(game,x,y,polarity) { // this->game = game; // this->x = x; // this->y = y; // this->polarity = polarity; this->angle = angle; this->dmg = 10; shotSpeed = 750; rotatesSpeed = 1080; type = BURST; // ticker = 0; // ticks = 0; // lastTick = 0; // angle = 90; trail.prepend(Point(x,y)); target.rx() = getX(); target.ry() = getY()-1000; targetAngle = qRadiansToDegrees(qAtan2(target.x()-getX(),target.y()-getY())); angleDistance = targetAngle - angle; if (angleDistance > 180) { angleDistance -= 360; } else if (angleDistance < -180) { angleDistance += 360; } }
void BurstShot::doLogic(double delta) { Q_UNUSED(delta); //set target to point directly above shot target.rx() = getX(); target.ry() = getY()-1000; targetDistance = pos.distanceTo(target); //target closest enemy if exists if(game->getEnemyEntities().size() > 0){ for(e_ptr enemy: game->getEnemyEntities()){ if(enemy->getType() == ENEMY){//if the target is not a bullet if(pos.distanceTo(enemy->getPos()) < targetDistance){ //if distance to enemy is shorter than current target //set it as new target target.rx() = enemy->getX(); target.ry() = enemy->getY(); targetDistance = pos.distanceTo( target); } } } } angle = fmod((angle + 360),360.0f);//bind range between 0 and 360 targetAngle = qRadiansToDegrees(qAtan2(target.x()-getX(),target.y()-getY())); angleDistance = targetAngle - angle; if (angleDistance > 180) { angleDistance -= 360; } else if (angleDistance < -180) { angleDistance += 360; } }
void Connexion::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->save(); //MODIFICATION DES COORDONNEES DE DESSINS qreal angle = qRadiansToDegrees(qAtan2(n1.y()-n2.y(),n1.x()-n2.x()))+90; painter->rotate(angle); painter->translate(0, n1.getRadius()); //DESSIN DE LA CONNEXION painter->save(); QColor c1 = n1.getOwner() != 0 ? n1.getOwner()->getColor() : VACANT_COLOR; QColor c2 = n2.getOwner() != 0 ? n2.getOwner()->getColor() : VACANT_COLOR; QLinearGradient linearGrad(0, 0, 0, distance); linearGrad.setColorAt(0, c1); linearGrad.setColorAt(1, c2); painter->setPen(Qt::NoPen); painter->fillRect(-2, 0, 4, distance, linearGrad); painter->restore(); //DESSIN DES SQUADS foreach(Squad *s, lstSquad1To2) { squadPatern(painter, s); }
/*! \brief Set the scrolling mode and direction Called by QwtAbstractSlider \param pos Point in question \param scrollMode Scrolling mode \param direction Direction */ void QwtKnob::getScrollMode( const QPoint &pos, QwtAbstractSlider::ScrollMode &scrollMode, int &direction ) const { const int r = d_data->knobRect.width() / 2; const int dx = d_data->knobRect.x() + r - pos.x(); const int dy = d_data->knobRect.y() + r - pos.y(); if ( ( dx * dx ) + ( dy * dy ) <= ( r * r ) ) // point is inside the knob { scrollMode = QwtAbstractSlider::ScrMouse; direction = 0; } else // point lies outside { scrollMode = QwtAbstractSlider::ScrTimer; double arc = qAtan2( double( -dx ), double( dy ) ) * 180.0 / M_PI; if ( arc < d_data->angle ) direction = -1; else if ( arc > d_data->angle ) direction = 1; else direction = 0; } }
bool QQuickFrictionAffector::affectParticle(QQuickParticleData *d, qreal dt) { if (!m_factor) return false; qreal curVX = d->curVX(); qreal curVY = d->curVY(); if (!curVX && !curVY) return false; qreal newVX = curVX + (curVX * m_factor * -1 * dt); qreal newVY = curVY + (curVY * m_factor * -1 * dt); if (!m_threshold) { if (sign(curVX) != sign(newVX)) newVX = 0; if (sign(curVY) != sign(newVY)) newVY = 0; } else { qreal curMag = qSqrt(curVX*curVX + curVY*curVY); if (curMag <= m_threshold + epsilon) return false; qreal newMag = qSqrt(newVX*newVX + newVY*newVY); if (newMag <= m_threshold + epsilon || //went past the threshold, stop there instead sign(curVX) != sign(newVX) || //went so far past maybe it came out the other side! sign(curVY) != sign(newVY)) { qreal theta = qAtan2(curVY, curVX); newVX = m_threshold * qCos(theta); newVY = m_threshold * qSin(theta); } } d->setInstantaneousVX(newVX); d->setInstantaneousVY(newVY); return true; }
QColor ColorWheel::pickColor(const QPoint& point) { if ( ! m_wheelPixmap.rect().contains(point) ) { return QColor(); } if (m_isInWheel) { qreal hue = 0; int r = qMin(width(), height()) / 2; QString strDebug = ""; strDebug += QString("Radius=%1").arg(r); QPoint center(width() / 2, height() / 2); QPoint diff = point - center; strDebug += QString(" Atan2=%1").arg(qAtan2(diff.x(), diff.y())); hue = qAtan2( diff.x(), diff.y() ) / M_PI * 180; hue = hue + 180; // shift -180~180 to 0~360 strDebug += QString(" Hue=%1").arg(hue); //qDebug() << strDebug; hue = (hue > 359) ? 359 : hue; hue = (hue < 0) ? 0 : hue; return QColor::fromHsv(hue, m_currentColor.saturation(), m_currentColor.value()); } else if (m_isInSquare) { QRect rect = m_squareRegion.boundingRect(); QPoint p = point - rect.topLeft(); //qDebug("TopRight(%d, %d) Point(%d, %d)", rect.topRight().x(), rect.topRight().y(), point.x(), point.y()); QSizeF regionSize = rect.size() - QSizeF(1, 1); //qDebug("p(%d, %d), Region(%.1f, %.1f)", p.x(), p.y(), regionSize.width(), regionSize.height()); return QColor::fromHsvF( m_currentColor.hueF(), p.x() / regionSize.width(), 1.0 - (p.y() / regionSize.height())); } return QColor(); }
double CvHelper::orientation(cv::Point2f front, cv::Point2f back) { cv::Point2f diff = front - back; //return qAtan2(diff.x, diff.y); // need to check the origin of coorindiates return qAtan2(diff.x, diff.y) + CV_PI / 2.0; }
void DistortionFXFilter::polarCoordinatesMultithreaded(const Args& prm) { int Width = prm.orgImage->width(); int Height = prm.orgImage->height(); uchar* data = prm.orgImage->bits(); bool sixteenBit = prm.orgImage->sixteenBit(); int bytesDepth = prm.orgImage->bytesDepth(); uchar* pResBits = prm.destImage->bits(); int nHalfW = Width / 2; int nHalfH = Height / 2; double lfXScale = 1.0; double lfYScale = 1.0; double lfAngle, lfRadius, lfRadMax; double nh, nw, tw; if (Width > Height) { lfYScale = (double)Width / (double)Height; } else if (Height > Width) { lfXScale = (double)Height / (double)Width; } lfRadMax = (double)qMax(Height, Width) / 2.0; double th = lfYScale * (double)(prm.h - nHalfH); for (int w = prm.start; runningFlag() && (w < prm.stop); ++w) { tw = lfXScale * (double)(w - nHalfW); if (prm.Type) { // now, we get the distance lfRadius = qSqrt(th * th + tw * tw); // we find the angle from the center lfAngle = qAtan2(tw, th); // now we find the exact position's x and y nh = lfRadius * (double) Height / lfRadMax; nw = lfAngle * (double) Width / (2 * M_PI); nw = (double)nHalfW + nw; } else { lfRadius = (double)(prm.h) * lfRadMax / (double)Height; lfAngle = (double)(w) * (2 * M_PI) / (double) Width; nw = (double)nHalfW - (lfRadius / lfXScale) * qSin(lfAngle); nh = (double)nHalfH - (lfRadius / lfYScale) * qCos(lfAngle); } setPixelFromOther(Width, Height, sixteenBit, bytesDepth, data, pResBits, w, prm.h, nw, nh, prm.AntiAlias); } }
QPainterPath PolygonRecord::painterPath(void) { QPainterPath path; qreal lx, ly; lx = xbs; ly = ybs; path.moveTo(lx, -ly); for (QList<SurfaceOperation*>::iterator it = operations.begin(); it != operations.end(); ++it) { SurfaceOperation* op = *it; if (op->type == SurfaceOperation::SEGMENT) { lx = op->x; ly = op->y; path.lineTo(lx, -ly); } else if (op->type == SurfaceOperation::CURVE) { qreal sx = lx, sy = ly; qreal ex = op->xe, ey = op->ye; qreal cx = op->xc, cy = op->yc; qreal sax = sx - cx, say = sy - cy; qreal eax = ex - cx, eay = ey - cy; qreal r = qSqrt(sax * sax + say * say); qreal sa = qAtan2(say, sax); qreal ea = qAtan2(eay, eax); if (op->cw) { if (sa <= ea) { sa += 2 * M_PI; } } else { if (ea <= sa) { ea += 2 * M_PI; } } path.arcTo(QRectF(cx -r, -cy -r, r *2, r *2), sa * R2D, (ea - sa) * R2D); path.lineTo(ex, -ey); lx = ex; ly = ey; } } path.closeSubpath(); return path; }
void qTransformToTemplateTransform(const QTransform& in, TemplateTransform* out) { out->template_x = qRound(1000 * in.m31()); out->template_y = qRound(1000 * in.m32()); out->template_rotation = qAtan2(-in.m21(), in.m11()); out->template_scale_x = in.m11() / qCos(out->template_rotation); out->template_scale_y = in.m22() / qCos(out->template_rotation); }
QColor ColorWheel::posColor(const QPoint &point) { if( ! wheel.rect().contains(point) ) return QColor(); if(inWheel){ qreal hue = 0; int r = qMin(width(), height()) / 2; if( point.x() > r ){ if(point.y() < r ){ //1 hue = 90 - (qAtan2( (point.x() - r) , (r - point.y()) ) / 3.14 / 2 * 360); }else{ //4 hue = 270 + (qAtan2( (point.x() - r) , (point.y() - r ) ) / 3.14 / 2 * 360); } }else{ if(point.y() < r ){ //2 hue = 90 + (qAtan2( (r - point.x()) , (r - point.y()) ) / 3.14 / 2 * 360); }else{ //3 hue = 270 - (qAtan2( (r - point.x()) , (point.y() - r )) / 3.14 / 2 * 360); } } hue = hue>359?359:hue; hue = hue<0?0:hue; return QColor::fromHsv(hue, current.saturation(), current.value() ); } if(inSquare){ // region of the widget int w = qMin(width(), height()); // radius of outer circle qreal r = w/2-margin; // radius of inner circle qreal ir = r-wheelWidth; // left corner of square qreal m = w/2.0-ir/qSqrt(2); QPoint p = point - QPoint(m, m); qreal SquareWidth = 2*ir/qSqrt(2); return QColor::fromHsvF( current.hueF(), p.x()/SquareWidth, p.y()/SquareWidth ); } return QColor(); }
QColor ColorWheel::colorPosition(const QPoint &point) { if( ! wheel.rect().contains(point) ) return QColor(); if(selectedWheel){ qreal hue = 0; int r = qMin(width(), height()) / 2; if( point.x() > r ){ if(point.y() < r ){ //1 hue = 90 - (qAtan2( (point.x() - r) , (r - point.y()) ) / 3.14 / 2 * 360); }else{ //4 hue = 270 + (qAtan2( (point.x() - r) , (point.y() - r ) ) / 3.14 / 2 * 360); } }else{ if(point.y() < r ){ //2 hue = 90 + (qAtan2( (r - point.x()) , (r - point.y()) ) / 3.14 / 2 * 360); }else{ //3 hue = 270 - (qAtan2( (r - point.x()) , (point.y() - r )) / 3.14 / 2 * 360); } } hue = hue>359?359:hue; hue = hue<0?0:hue; return QColor::fromHsv(hue, start.saturation(), start.value()); } if(selected){ int w = qMin(width(), height()); qreal r = w/2-margin; qreal ir = r-wWidth; qreal m = w/2.0-ir/qSqrt(2); QPoint p = point - QPoint(m, m); qreal SquareWidth = 2*ir/qSqrt(2); return QColor::fromHsvF( start.hueF(), p.x()/SquareWidth, p.y()/SquareWidth); } return QColor(); }
void AutoFindPath::onTimeout() { qreal x1 = tempPointF_.x(); qreal y1 = tempPointF_.y(); qreal x2 = toPointF_.x(); qreal y2 = toPointF_.y(); qreal xNegative = (x2 - x1) > 0 ? 1.0 : -1.0; qreal yNegative = (y2 - y1) > 0 ? 1.0 : -1.0; xNegative = 1.0; yNegative = 1.0; qreal fromDistance = qSqrt(qPow(x2-x1, 2) + qPow(y2-y1, 2)); qreal xdif = xNegative * pace_ * (x2 - x1) / fromDistance; qreal ydif = yNegative * pace_ * (y2 - y1) / fromDistance; qreal x3 = x1 + xdif; qreal y3 = y1 + ydif; qreal toDistance = qSqrt(qPow(x3-x2, 2) + qPow(y3-y2, 2)); // qDebug() << tempPointF_ << toPointF_<< xNegative << yNegative<<fromDistance<<toDistance<< xdif << ydif; tempPointF_.setX(x3); tempPointF_.setY(y3); if (toDistance <= radius_) { // qDebug() << "STOP!"; timer_.stop(); if (rolePathMap_.contains(role_)) { rolePathMap_.remove(role_); } this->deleteLater(); } qreal ration = qAtan2(ydif, xdif); qreal degree = qRadiansToDegrees(ration); // qDebug() << ration << degree; role_->setRotation(degree + 90); // setRotation(rotation() + dx); role_->setPos(tempPointF_); // role_->setEyeDirection(); // role_->update(); // QRectF rect = role_->mapRectToScene(role_->boundingRect()); QPointF pos = role_->mapToScene(role_->pos()); QRectF rect; rect.setTopLeft(pos); rect.setWidth(20); rect.setHeight(20); role_->scene()->invalidate(); }
// arc for GCode G2, G3 Arc3D::Arc3D(uint8_t p, bool dir, QVector3D s, QVector3D e, QVector3D o, uint8_t r, bool h) : plane(p), cw(dir), pstart(s), pend(e), poffset(o), nrevol(r), // not used !! helix(h), pcenter(pstart + poffset), color(Qt::darkGreen), /// green linewidth(1), feedrate(SPEED_DEFAULT) { // no paths interpolated = false; path.clear(); //diag("GArc start ==> sx, sy, sz = %f, %f, %f", pstart.x(), pstart.y(), pstart.z()); //diag("GArc end ==> ex, ey, ez = %f, %f, %f", pend.x(), pend.y(), pend.z()); //diag("GArc offset ==> lx, ly, lz = %f, %f, %f", poffset.x(), poffset.y(), poffset.z()); //diag("GArc center ==> cx, cy, cz = %f, %f, %f", pcenter.x(), pcenter.y(), pcenter.z()); /// plane selection double t2(0) , u2(0); /// axes ? //diag("Arc plane = %d", plane); switch (plane) { case PLANE_XY_G17 : /// XY G17 pcenter.setZ(pstart.z()) ; t2 = qPow(pstart.x() - pcenter.x(), 2.0) ; //diag("sx , cx = %f, %f", pstart.x(), pcenter.x()); u2 = qPow(pstart.y() - pcenter.y() , 2.0) ; // diag("sy , cy = %f, %f", pstart.y(), pcenter.y()); // diag("XY : t2 , u2 = %f, %f" , t2, u2); // angles astart = qAtan2(pstart.y()- pcenter.y(), pstart.x()- pcenter.x() ); aend = qAtan2(pend.y()- pcenter.y(), pend.x()- pcenter.x() ); // diag("as , ae = %f, %f", astart, aend); break; case PLANE_ZX_G19 : /// ZX G18 pcenter.setY(pstart.y()) ; t2 = qPow(pstart.x() - pcenter.x(), 2.0) ; u2 = qPow(pstart.z() - pcenter.z(), 2.0) ; // diag("XZ : t2 , u2 = %f, %f" , t2, u2); // astart = qAtan2(pstart.z()- pcenter.z(), pstart.x()- pcenter.x() ); aend = qAtan2(pend.z()- pcenter.z(), pend.x()- pcenter.x() ); break; case PLANE_YZ_G18: /// YZ G19 pcenter.setX(pstart.x()); t2 = qPow(pstart.y() - pcenter.y(), 2.0) ; u2 = qPow(pstart.z() - pcenter.z(), 2.0) ; // diag("YZ : t2 , u2 = %f, %f" , t2, u2); // astart = qAtan2(pstart.z()- pcenter.z(), pstart.y()- pcenter.y() ); aend = qAtan2(pend.z()- pcenter.z(), pend.y()- pcenter.y() ); break; default : ; } /// radius into plane radius = qSqrt( t2 + u2 ); //diag("radius = %f", radius); //diag("astart , aend = %f, %f", astart, aend); }
/** * @param x x coordinate * @param y y coordinate */ void CanvasView::moveDrag(int x, int y) { const int dx = _dragx - x; const int dy = _dragy - y; if(_isdragging==ROTATE) { qreal preva = qAtan2( width()/2 - _dragx, height()/2 - _dragy ); qreal a = qAtan2( width()/2 - x, height()/2 - y ); setRotation(rotation() + qRadiansToDegrees(preva-a)); } else { QScrollBar *ver = verticalScrollBar(); ver->setSliderPosition(ver->sliderPosition()+dy); QScrollBar *hor = horizontalScrollBar(); hor->setSliderPosition(hor->sliderPosition()+dx); } _dragx = x; _dragy = y; // notify of scene change sceneChanged(); }
OiVec Reading::toPolar(double x, double y, double z){ OiVec g(4); double azimuth = qAtan2(y,x); double s = qSqrt(x*x+y*y+z*z); double zenith = acos(z/s); g.setAt( 0, azimuth); g.setAt( 1, zenith); g.setAt( 2, s); g.setAt( 3, 1.0 ); return g; }
void BrushEngine::paint(const QPointF& point, float pressure) { QPainter painter(eraser > 50 ? canvasItem->getPixmap() : canvasBuffer->getPixmap()); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(Qt::NoPen); if (eraser > 50) { painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); } color.setAlpha(qRound(255 * flow / 100.0)); QColor pressureColor = color; pressureColor.setAlpha(qRound(color.alpha() * pressure)); QColor alphaColor = color; alphaColor.setAlpha(0); QRadialGradient radialGradient; radialGradient.setRadius(size / 2.0); radialGradient.setColorAt(0, pressureColor); radialGradient.setColorAt(1, alphaColor); radialGradient.setColorAt(hardness / 100.0, pressureColor); painter.setBrush(QBrush(radialGradient)); if (startPoint.isNull()) { startPoint = QPointF(point); lastPoint = QPointF(point); topleft = QPoint(0, 0); bottomright = QPoint(canvasBuffer->getPixmap()->width(), canvasBuffer->getPixmap()->height()); paintDab(point, painter); } else { qreal length = qSqrt(qPow(lastPoint.x() - point.x(), 2) + qPow(lastPoint.y() - point.y(), 2)); qreal delta = size * spacing / 2.0 / 100.0; if (length >= delta) { int dabs = qRound(length / delta); qreal angle = qAtan2(point.x() - lastPoint.x(), point.y() - lastPoint.y()); qreal deltaX = delta * qSin(angle); qreal deltaY = delta * qCos(angle); QPointF betweenPoint; for (int i = 1; i <= dabs; i++) { qreal x = lastPoint.x() + deltaX * i + (10000 - qrand() % 20000) / 10000.0 * size * jitter / 100; qreal y = lastPoint.y() + deltaY * i + (10000 - qrand() % 20000) / 10000.0 * size * jitter / 100; betweenPoint = QPointF(x, y); paintDab(betweenPoint, painter); } lastPoint = betweenPoint; } } }
QHash<QPoint, QPair<qreal, qreal> > EdgeDetection::gradientValues(QImage *image) { QHash<QPoint, QPair<qreal, qreal> > gradient; QList<QPair<QPoint, QPair<int, int> > > x_y_struct; x_y_struct.append( qMakePair(QPoint(-1,-1), QPair<int,int>(-1, 1) )); x_y_struct.append( qMakePair(QPoint(-1,0), QPair<int,int>(-2, 0) )); x_y_struct.append( qMakePair(QPoint(-1,1), QPair<int,int>(-1,-1) )); x_y_struct.append( qMakePair(QPoint(0,-1), QPair<int,int>(0,2) )); x_y_struct.append( qMakePair(QPoint(0,0), QPair<int,int>(0,0) )); x_y_struct.append( qMakePair(QPoint(0,1), QPair<int,int>(0,-2) )); x_y_struct.append( qMakePair(QPoint(1,-1), QPair<int,int>(1,1) )); x_y_struct.append( qMakePair(QPoint(1,0), QPair<int,int>(2,0) )); x_y_struct.append( qMakePair(QPoint(1,1), QPair<int,int>(1, -1) )); for( int y=0; y < image->height(); y++ ) { for( int x=0; x < image->width(); x++ ) { QPoint point(x,y); int x_sum = 0; int y_sum = 0; int count = 0; //Perform Convolution on X for (int i=0; i < x_y_struct.size(); i++) { QPoint offset = x_y_struct.at(i).first; QPair<int,int> multiplier = x_y_struct.at(i).second; //Only convolve real pixels int pixel_x = offset.x() + x; int pixel_y = offset.y() + y; QRgb color; if ( pixel_x < 0 || pixel_x >= image->width() || pixel_y < 0 || pixel_y >= image->height() ) { color = qRgb(128, 128, 128); } else { color = image->pixel(QPoint(pixel_x, pixel_y)); } int gray_val = qGray(color); x_sum += gray_val * multiplier.first; y_sum += gray_val * multiplier.second; count++; } //Orientation qreal magnitude = qSqrt(qPow(x_sum / 8, 2) + qPow(y_sum / 8, 2)); qreal orientation = qAtan2(y_sum/count, x_sum/count); gradient.insert(point, qMakePair(magnitude, orientation)); } } return gradient; }