Exemple #1
0
static PyObject * rotate_vecs_about_axis(PyObject * self, PyObject * args)
{
  PyArrayObject *angles, *axes, *vecs;
  PyArrayObject *rVecs;
  int da, dax, dv;
  npy_intp na, nax0, nax1, nv0, nv1;
  double *aPtr, *axesPtr, *vecsPtr;
  double *rPtr;

  /* Parse arguments */
  if ( !PyArg_ParseTuple(args,"OOO", &angles,&axes,&vecs)) return(NULL);
  if ( angles == NULL || axes == NULL || vecs == NULL ) return(NULL);

  /* Verify shape of input arrays */
  da  = PyArray_NDIM(angles);
  dax = PyArray_NDIM(axes);
  dv  = PyArray_NDIM(vecs);
  assert( da == 1 && dax == 2 && dv == 2 );

  /* Verify dimensions of input arrays */
  na   = PyArray_DIMS(angles)[0];
  nax0 = PyArray_DIMS(axes)[0];
  nax1 = PyArray_DIMS(axes)[1];
  nv0  = PyArray_DIMS(vecs)[0];
  nv1  = PyArray_DIMS(vecs)[1];
  assert( na == 1   || na == nv0 );
  assert( nax0 == 1 || nax0 == nv0 );
  assert( nax1 == 3 && nv1 == 3 );

  /* Allocate the result vectors with appropriate dimensions and type */
  rVecs = (PyArrayObject*)PyArray_EMPTY(2,PyArray_DIMS(vecs),NPY_DOUBLE,0.0);
  assert( rVecs != NULL );

  /* Grab pointers to the various data arrays */
  aPtr    = (double*)PyArray_DATA(angles);
  axesPtr = (double*)PyArray_DATA(axes);
  vecsPtr = (double*)PyArray_DATA(vecs);
  rPtr    = (double*)PyArray_DATA(rVecs);

  /* Call the actual function */
  rotate_vecs_about_axis_cfunc(na,aPtr,nax0,axesPtr,nv0,vecsPtr,rPtr);

  return((PyObject*)rVecs);
}
void detectorXYToGvec_cfunc(long int npts, double * xy,
			    double * rMat_d, double * rMat_s,
			    double * tVec_d, double * tVec_s, double * tVec_c,
			    double * beamVec, double * etaVec,
			    double * tTh, double * eta, double * gVec_l)
{
  long int i;
  int j, k;
  double nrm, phi, bVec[3], tVec1[3], tVec2[3], dHat_l[3], n_g[3];
  double rMat_e[9];

  /* Fill rMat_e */
  makeEtaFrameRotMat_cfunc(beamVec,etaVec,rMat_e);

  /* Normalize the beam vector */
  nrm = 0.0;
  for (j=0; j<3; j++) {
    nrm += beamVec[j]*beamVec[j];
  }
  nrm = sqrt(nrm);
  if ( nrm > epsf ) {
    for (j=0; j<3; j++)
      bVec[j] = beamVec[j]/nrm;
  } else {
    for (j=0; j<3; j++)
      bVec[j] = beamVec[j];
  }

  /* Compute shift vector */
  for (j=0; j<3; j++) {
    tVec1[j] = tVec_d[j]-tVec_s[j];
    for (k=0; k<3; k++) {
      tVec1[j] -= rMat_s[3*j+k]*tVec_c[k];
    }
  }

  for (i=0; i<npts; i++) {
    /* Compute dHat_l vector */
    nrm = 0.0;
    for (j=0; j<3; j++) {
      dHat_l[j] = tVec1[j];
      for (k=0; k<2; k++) {
	dHat_l[j] += rMat_d[3*j+k]*xy[2*i+k];
      }
      nrm += dHat_l[j]*dHat_l[j];
    }
    if ( nrm > epsf ) {
      for (j=0; j<3; j++) {
	dHat_l[j] /= sqrt(nrm);
      }
    }

    /* Compute tTh */
    nrm = 0.0;
    for (j=0; j<3; j++) {
      nrm += bVec[j]*dHat_l[j];
    }
    tTh[i] = acos(nrm);

    /* Compute eta */
    for (j=0; j<2; j++) {
      tVec2[j] = 0.0;
      for (k=0; k<3; k++) {
	tVec2[j] += rMat_e[3*k+j]*dHat_l[k];
      }
    }
    eta[i] = atan2(tVec2[1],tVec2[0]);

    /* Compute n_g vector */
    nrm = 0.0;
    for (j=0; j<3; j++) {
      n_g[j] = bVec[(j+1)%3]*dHat_l[(j+2)%3]-bVec[(j+2)%3]*dHat_l[(j+1)%3];
      nrm += n_g[j]*n_g[j];
    }
    nrm = sqrt(nrm);
    for (j=0; j<3; j++) {
      n_g[j] /= nrm;
    }

    /* Rotate dHat_l vector */
    // rotateVectorAboutAxis_cfunc(tTh[i], n_g, dHat_l, &gVec_l[3*i]);
    phi = 0.5*(M_PI-tTh[i]);
    rotate_vecs_about_axis_cfunc(1, &phi, 1, n_g, 1, dHat_l, &gVec_l[3*i]);
  }
}