Exemplo n.º 1
0
AsemanSensorsResItem AsemanSensors::analizeItem(qreal x, qreal y, qreal z, bool ambiguity)
{
    AsemanSensorsResItem res;
    res.beta = 0;
    res.newX = 0;

    const qreal f = qPow(x*x+z*z,0.5);
    if( f == 0 )
        return res;

    const qreal al = qAsin(z/f);

    const qreal g   = EARTH_GRAVITY;
    const qreal gxz = x==0 && y==0? 0 : pow( (x*x*g*g+z*z*y*y)/(x*x+y*y), 0.5 );

    const qreal sinb = z/gxz;
    const qreal bt_p = qAsin( sinb>1?1:(sinb<-1?-1:sinb) );
    const qreal bt   = ambiguity? M_PI-bt_p : bt_p;
    const qreal nx   = x - gxz*qCos(bt);

    res.beta = bt;
    res.newX = nx;
    res.f = f;
    res.g = gxz;
    res.alpha = al;

    return res;
}
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;
}
Exemplo n.º 3
0
void KinematicPoints::SetS4C4()
{
    s[4] = s234 * c23 - c234 * s23;
    c[4] = c234*c23 + s234*s23;
    fi[4] = qFabs(c[4])>qFabs(s[4])? qAsin(s[4]) : qAcos(c[4]);
    //if(fi[4]!=fi[4]) {emit outOfRange(); return;}

}
Exemplo n.º 4
0
float WireCreator::calcMinimumAngle(QVector3D point, QPair<QVector3D, QVector3D> box)
{
    float maxY=qMax(box.first.y(),box.second.y())+0.3f;
    if(point.length()<maxY) return 0;
    float angle=qAsin(maxY/point.length());
    return angle;

}
Exemplo n.º 5
0
void KinematicPoints::SetS5C5()
{
    s[5] = ctheta * (spsi * c[1] - cpsi * s[1]);
    c[5] = delta5 * qSqrt(1 - qPow(s[5], 2));
    fi[5] = qFabs(c[5])>qFabs(s[5])? qAsin(s[5]) : qAcos(c[5]);
    //if(fi[5]!=fi[5]) {emit outOfRange(); return;}

}
Exemplo n.º 6
0
Rpn::Operand Arcsine::calculate(FunctionCalculator *calculator, QList<Rpn::Operand> actualArguments)
{
	Q_UNUSED(calculator);

	Rpn::Operand result;
	result.type = Rpn::OperandNumber;
	result.value = qAsin(actualArguments.at(0).value.value<Number>());

	return result;
}
Exemplo n.º 7
0
bool VerticalPerspectiveProjection::geoCoordinates( const int x, const int y,
                                          const ViewportParams *viewport,
                                          qreal& lon, qreal& lat,
                                          GeoDataCoordinates::Unit unit ) const
{
    Q_D(const VerticalPerspectiveProjection);
    d->calculateConstants(viewport->radius());
    const qreal P = d->m_P;
    const qreal rx = ( - viewport->width()  / 2 + x );
    const qreal ry = (   viewport->height() / 2 - y );
    const qreal p2 = rx*rx + ry*ry;

    if (p2 == 0) {
        lon = viewport->centerLongitude();
        lat = viewport->centerLatitude();
        return true;
    }

    const qreal pP = p2*d->m_pPfactor;

    if ( pP > 1) return false;

    const qreal p = qSqrt(p2);
    const qreal fract = d->m_perspectiveRadius*(P-1)/p;
    const qreal c = qAsin((P-qSqrt(1-pP))/(fract+1/fract));
    const qreal sinc = qSin(c);

    const qreal centerLon = viewport->centerLongitude();
    const qreal centerLat = viewport->centerLatitude();
    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;
}
Exemplo n.º 8
0
void KinematicPoints::SetS2C2()
{
    double zr = regionalPoint.z();

    s[2] = 1/(qPow(a, 2) + qPow(zr,2)) * (zr * b + delta2 * a * qSqrt(qPow(a, 2) + qPow(zr,2) - qPow(b,2)));
    c[2] = 1/(qPow(a, 2) + qPow(zr,2)) * (a * b - delta2 * zr * qSqrt(qPow(a, 2) + qPow(zr,2) - qPow(b,2)) );
    fi[2] = qFabs(c[2])>qFabs(s[2])? qAsin(s[2]) : qAcos(c[2]);

    //if(fi[2]!=fi[2]) {emit outOfRange(); return;}

}
Exemplo n.º 9
0
void KinematicPoints::SetS3C3()
{
    double zr = regionalPoint.z();

   s[3] = 1/l[3] * ( zr*c[2] - a*s[2] );
   c[3] = 1/l[3]* (a*c[2]+zr*s[2] - l[2]) ;
   fi[3] = qFabs(c[3])>qFabs(s[3])? qAsin(s[3]) : qAcos(c[3]);

   //if(fi[3]!=fi[3]) {emit outOfRange(); return;}

}
uint ColorCalculator::getRadialPixel(int x, int y, int cx, int cy){
    int dx=x-cx;
    int dy=y-cy;

    qreal radius=qSqrt(dx*dx+dy*dy);
    qreal sinus=0;
    if(radius>0)sinus=qreal(dy)/radius;
    qreal angle=qAsin(sinus);

    if(dx<0)angle=M_PI-angle;
    if(angle<0)angle+=M_PI*2;

    engine.globalObject().setProperty("r",radius);
    engine.globalObject().setProperty("a",angle);

    return getPixel();
}
Exemplo n.º 11
0
void KinematicPoints::CalculateMachineCoordinates(QVector3D toolPoint)
{
    SetToolPoint(toolPoint);
    SetTransitionalPoint();
    SetS1C1();
    SetS5C5();
    SetS234C234();
    SetRegionalPoint();
    SetAB();
    SetS2C2();
    SetS3C3();
    SetS23C23();
    SetS4C4();
    SetJointPoints();
    SetCalculatedJointPoints();

   static bool ok = true;
   for(int i=0; i<5; ++i)
   {
      fi[i] = c[i]>s[i]? qAsin(s[i]) : qAcos(c[i]);
      if(fi[i]!=fi[i])
      {
         if(ok)
         {
             ok = false;
             emit outOfRange();
             return;
         }

        else
         {
             ok = true;
             return;
         }
        }
   }

    if(lastValidPoint != toolPoint)
        emit statusOK();

    lastValidPoint = toolPoint;

}
Exemplo n.º 12
0
void GraphicsCardSelectionScene::calculateScene()
{
    // check if there is a view this scene is drawn in
    if(views().isEmpty()) return;
    QGraphicsView *view = views().first();

    int n = items().count();
    if(n < 1) return; 

    qreal w, h, xoffset;
    qreal f = 1.0;

    do {
        w = view->viewport()->width() * f * 0.8; // the width of the arc
        h = view->viewport()->height() * f * 0.6; // the height of the arc
        xoffset = w / n;
        f -= 0.1;
    } while(xoffset >= 45.0 && f > 0.1);

    qreal x = - xoffset * ((n == 1) ? 0 : (n / 2)); // starting position
    qreal r = (w*w + h*h) / (2 * h); // the radius of the circle as a function of w and h

    if(n % 2) x -= xoffset / 2;

    for(int i = 0; i < n; ++i)
    {
        GraphicsGameCardItem *item;
        item = static_cast<GraphicsGameCardItem*>(items().at(i));

        qreal y = r + qSqrt(r*r - x*x); // the y offset for this card on the arc

        item->setOffset(x, -y);
        item->setTransformOriginPoint(item->offset());
        item->setRotation(360 * qAsin(x/r) / (2 * M_PI)); // the card's rotation angle as degrees
        x += xoffset;
    }

    QRectF rect = sceneRect();
    setSceneRect(rect.x(), rect.y() -50.0, rect.width(), rect.height() +50.0);
}
Exemplo n.º 13
0
void Meteor::init(const float& radiantAlpha, const float& radiantDelta,
		  const float& speed, const QList<ColorPair> colors)
{
	// meteor velocity in km/s
	m_speed = speed;

	// find the radiant in horizontal coordinates
	Vec3d radiantAltAz;
	StelUtils::spheToRect(radiantAlpha, radiantDelta, radiantAltAz);
	radiantAltAz = m_core->j2000ToAltAz(radiantAltAz);
	float radiantAlt, radiantAz;
	// S is zero, E is 90 degrees (SDSS)
	StelUtils::rectToSphe(&radiantAz, &radiantAlt, radiantAltAz);

	// meteors won't be visible if radiant is below 0degrees
	if (radiantAlt < 0.f)
	{
		return;
	}

	// define the radiant coordinate system
	// rotation matrix to align z axis with radiant
	m_matAltAzToRadiant = Mat4d::zrotation(radiantAz) * Mat4d::yrotation(M_PI_2 - radiantAlt);

	// select a random initial meteor altitude in the horizontal system [MIN_ALTITUDE, MAX_ALTITUDE]
	float initialAlt = MIN_ALTITUDE + (MAX_ALTITUDE - MIN_ALTITUDE) * ((float) qrand() / ((float) RAND_MAX + 1));

	// calculates the max z-coordinate for the currrent radiant
	float maxZ = meteorZ(M_PI_2 - radiantAlt, initialAlt);

	// meteor trajectory
	// select a random xy position in polar coordinates (radiant system)

	float xyDist = maxZ * ((double) qrand() / ((double) RAND_MAX + 1)); // [0, maxZ]
	float theta = 2 * M_PI * ((double) qrand() / ((double) RAND_MAX + 1)); // [0, 2pi]

	// initial meteor coordinates (radiant system)
	m_position[0] = xyDist * qCos(theta);
	m_position[1] = xyDist * qSin(theta);
	m_position[2] = maxZ;
	m_posTrain = m_position;

	// store the initial z-component (radiant system)
	m_initialZ = m_position[2];

	// find the initial meteor coordinates in the horizontal system
	Vec3d positionAltAz = m_position;
	positionAltAz.transfo4d(m_matAltAzToRadiant);

	// find the angle from horizon to meteor
	float meteorAlt = qAsin(positionAltAz[2] / positionAltAz.length());

	// this meteor should not be visible if it is above the maximum altitude
	// or if it's below the horizon!
	if (positionAltAz[2] > MAX_ALTITUDE || meteorAlt <= 0.f)
	{
		return;
	}

	// determine the final z-component and the min distance between meteor and observer
	if (radiantAlt < 0.0262f) // (<1.5 degrees) earth grazing meteor ?
	{
		// earth-grazers are rare!
		// introduce a probabilistic factor just to make them a bit harder to occur
		float prob = ((float) qrand() / ((float) RAND_MAX + 1));
		if (prob > 0.3f) {
			return;
		}

		// limit lifetime to 12sec
		m_finalZ = -m_position[2];
		m_finalZ = qMax(m_position[2] - m_speed * 12.f, (double) m_finalZ);

		m_minDist = xyDist;
	}
	else
	{
		// limit lifetime to 12sec
		m_finalZ = meteorZ(M_PI_2 - meteorAlt, MIN_ALTITUDE);
		m_finalZ = qMax(m_position[2] - m_speed * 12.f, (double) m_finalZ);

		m_minDist = qSqrt(m_finalZ * m_finalZ + xyDist * xyDist);
	}

	// a meteor cannot hit the observer!
	if (m_minDist < MIN_ALTITUDE) {
		return;
	}

	// select random magnitude [-3; 4.5]
	float Mag = (float) qrand() / ((float) RAND_MAX + 1) * 7.5f - 3.f;

	// compute RMag and CMag
	RCMag rcMag;
	m_core->getSkyDrawer()->computeRCMag(Mag, &rcMag);
	m_absMag = rcMag.radius <= 1.2f ? 0.f : rcMag.luminance;
	if (m_absMag == 0.f) {
		return;
	}

	// most visible meteors are under about 184km distant
	// scale max mag down if outside this range
	float scale = qPow(184.0 / m_minDist, 2);
	m_absMag *= qMin(scale, 1.0f);

	// build the color vector
	buildColorVectors(colors);

	m_alive = true;
}
void dtkComposerNodeNumberOperatorUnaryAsin::run(void)
{
    double *value = d->receiver.data<double>();
    *value = qAsin(*value);
    d->emitter.setData<double>(value);
}
Exemplo n.º 15
0
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()));
    
}
Exemplo n.º 16
0
static T getRoll(const QQuaternion &q)
{
	return qAsin(2 * q.scalar() * q.y() - 2 * q.x() * q.z());
}
Exemplo n.º 17
0
QVector2D SphereGenerator::uvCoord(QVector3D xyz, double radius)
{
    xyz /= radius;
    return QVector2D(0.5 + qAtan2(xyz.z(), xyz.x()) / (2 * M_PI),
                     0.5 - qAsin(xyz.y()) / M_PI);
}