本文整理汇总了C++中qAtan2函数的典型用法代码示例。如果您正苦于以下问题:C++ qAtan2函数的具体用法?C++ qAtan2怎么用?C++ qAtan2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qAtan2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qMin
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();
}
示例2: qAtan2
/**
* @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;
}
示例3: qMin
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();
}
示例4: point
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
}
示例5: qMin
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();
}
示例6: qAtan2
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;
}
示例7: cursor_moved
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);
}
示例8: qAtan2
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;
}
示例9: while
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);
}
示例10: width
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;
}
示例11: Q_Q
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);
}
示例12: qMax
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;
}
示例13: ShotEntity
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;
}
}
示例14: Q_UNUSED
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;
}
}
示例15: Q_UNUSED
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);
}