コード例 #1
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    double c, *vObsFrame, *vObjInFrame, *vObjRef;
    mxArray *retMATLAB;
    size_t i, numVec;

    if(nrhs!=2) {
        mexErrMsgTxt("Incorrect number of inputs.");
        return;
    }

    if(nlhs>1) {
        mexErrMsgTxt("Wrong number of outputs.");
        return;
    }

    numVec=mxGetN(prhs[0]);
    if(numVec!=mxGetN(prhs[1])||mxGetM(prhs[0])!=3||mxGetM(prhs[1])!=3) {
        mexErrMsgTxt("The input vectors have the wrong dimensionality.");
        return;
    }

    checkRealDoubleArray(prhs[0]);
    vObsFrame=(double*)mxGetData(prhs[0]);
    checkRealDoubleArray(prhs[1]);
    vObjInFrame=(double*)mxGetData(prhs[1]);

    c=getScalarMatlabClassConst("Constants","speedOfLight");

    //Allocate space for the return values.
    retMATLAB=mxCreateDoubleMatrix(3,numVec,mxREAL);
    vObjRef=(double*)mxGetData(retMATLAB);

    for(i=0; i<numVec; i++) {
        relVecAddC(c,vObsFrame+3*i,vObjInFrame+3*i,vObjRef+3*i);
    }

    plhs[0]=retMATLAB;
}
コード例 #2
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    double *vOrig;
    double *obsVel;
    mxArray *retMATLAB;
    double c, *retVec;
    size_t numVec;
    
    if(nrhs<2||nrhs>3) {
        mexErrMsgTxt("Incorrect number of inputs.");
        return;
    }
    
    if(nlhs>1) {
        mexErrMsgTxt("Wrong number of outputs.");
        return;
    }

    numVec=mxGetN(prhs[0]);
    if(numVec!=mxGetN(prhs[1])||mxGetM(prhs[0])!=3||mxGetM(prhs[1])!=3) {
        mexErrMsgTxt("The input vectors have the wrong dimensionality.");
        return;
    }
    
    checkRealDoubleArray(prhs[0]);
    vOrig=(double*)mxGetData(prhs[0]);
    checkRealDoubleArray(prhs[1]);
    obsVel=(double*)mxGetData(prhs[1]);
    
    c=getScalarMatlabClassConst("Constants","speedOfLight");
    
    //Allocate space for the return values.
    retMATLAB=mxCreateDoubleMatrix(3,numVec,mxREAL);
    retVec=(double*)mxGetData(retMATLAB);
    
    //If the third parameter is provided, then use the algorithm from the IAU.
    if(nrhs>2) {
        double AU, *sunDist;
        size_t curVec;
        
        //Needed to convert units.
        AU=getScalarMatlabClassConst("Constants","AstronomialUnit");
        
        //If the dimensionality is wrong.
        if(!((mxGetM(prhs[2])==1&&mxGetN(prhs[2])==numVec)||(mxGetM(prhs[2])==numVec&&mxGetN(prhs[2])==1))) {
            mxDestroyArray(retMATLAB);
            mexErrMsgTxt("The input vectors have the wrong dimensionality.");
            return;
        }
        checkRealDoubleArray(prhs[0]);
        sunDist=(double*)mxGetData(prhs[2]);

        for(curVec=0;curVec<numVec;curVec++) {
            double vecMag,unitVec[3];
            double v[3];
            double s;
            double bm1;
            
            //Get a unit direction vector and magnitude.
            iauPn(vOrig+3*curVec, &vecMag, unitVec);
            
            //Convert the velocity to units of the speed of light.
            v[0]=obsVel[3*curVec]/c;
            v[1]=obsVel[3*curVec+1]/c;
            v[2]=obsVel[3*curVec+2]/c;
            
            //The distance to the sun in AU.
            s=sunDist[curVec]/AU;
            //The reciprocal of the Lorentz factor.
            bm1=sqrt(1-(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]));
            
            //Perform the correction with the IAU's function.
            iauAb(unitVec, v, s, bm1,retVec+3*curVec);
            
            //Set the magnitude back to what it was.
            retVec[3*curVec]*=vecMag;
            retVec[3*curVec+1]*=vecMag;
            retVec[3*curVec+2]*=vecMag;
        }
    } else {
    //If the distance to the sun is not given, then just perform a normal
    //special relativistic correction.
        size_t curVec;
        
        for(curVec=0;curVec<numVec;curVec++) {
            double vecMag,lightVec[3];
            
            //Get a unit direction vector and magnitude.
            iauPn(vOrig+3*curVec, &vecMag, lightVec);
            
            //The light is in direction lightVec with speed c
            lightVec[0]*=c;
            lightVec[1]*=c;
            lightVec[2]*=c;
            
            //The light travels at speed c with true direction uPosition.
            //Add the velocity vector of the observer to that of light.
            relVecAddC(c,obsVel+3*curVec,lightVec,retVec+3*curVec);
            //Because one vector had a magnitude of c, the returned vector
            //must have the same magnitude. Restore the previous magnitude.
            retVec[3*curVec]*=vecMag/c;
            retVec[3*curVec+1]*=vecMag/c;
            retVec[3*curVec+2]*=vecMag/c;
        }
    }

    //Set the return value.
    plhs[0]=retMATLAB;
}