Example #1
0
static inline void CorrectHKLsLatC(double LatC[6], double **hklsIn,int nhkls,double **hkls)
{
	double a=LatC[0],b=LatC[1],c=LatC[2],alpha=LatC[3],beta=LatC[4],gamma=LatC[5];
	int hklnr;
	for (hklnr=0;hklnr<nhkls;hklnr++){
		double ginit[3]; ginit[0] = hklsIn[hklnr][0]; ginit[1] = hklsIn[hklnr][1]; ginit[2] = hklsIn[hklnr][2];
		double SinA = sind(alpha), SinB = sind(beta), SinG = sind(gamma), CosA = cosd(alpha), CosB = cosd(beta), CosG = cosd(gamma);
		double GammaPr = acosd((CosA*CosB - CosG)/(SinA*SinB)), BetaPr  = acosd((CosG*CosA - CosB)/(SinG*SinA)), SinBetaPr = sind(BetaPr);
		double Vol = (a*(b*(c*(SinA*(SinBetaPr*(SinG)))))), APr = b*c*SinA/Vol, BPr = c*a*SinB/Vol, CPr = a*b*SinG/Vol;
		double B[3][3]; B[0][0] = APr; B[0][1] = (BPr*cosd(GammaPr)), B[0][2] = (CPr*cosd(BetaPr)), B[1][0] = 0,
			B[1][1] = (BPr*sind(GammaPr)), B[1][2] = (-CPr*SinBetaPr*CosA), B[2][0] = 0, B[2][1] = 0, B[2][2] = (CPr*SinBetaPr*SinA);
		double GCart[3];
		MatrixMult(B,ginit,GCart);
		double Ds = 1/(sqrt((GCart[0]*GCart[0])+(GCart[1]*GCart[1])+(GCart[2]*GCart[2])));
		hkls[hklnr][0] = ginit[0];hkls[hklnr][1] = ginit[1];hkls[hklnr][2] = ginit[2];
        hkls[hklnr][3] = Ds;
        hkls[hklnr][4] = 0;
        hkls[hklnr][5] = GCart[0];
        hkls[hklnr][6] = GCart[1];
        hkls[hklnr][7] = GCart[2];
	}
}
Example #2
0
static void astro_sun_RA_dec(double d, double *RA, double *dec, double *r)
{
	double lon, obl_ecl, x, y, z;

	/* Compute Sun's ecliptical coordinates */
	astro_sunpos(d, &lon, r);

	/* Compute ecliptic rectangular coordinates (z=0) */
	x = *r * cosd(lon);
	y = *r * sind(lon);

	/* Compute obliquity of ecliptic (inclination of Earth's axis) */
	obl_ecl = 23.4393 - 3.563E-7 * d;

	/* Convert to equatorial rectangular coordinates - x is unchanged */
	z = y * sind(obl_ecl);
	y = y * cosd(obl_ecl);

	/* Convert to spherical coordinates */
	*RA = atan2d(y, x);
	*dec = atan2d(z, sqrt(x*x + y*y));
}
Example #3
0
void ObservationPointSet(long double NS,long double EW,long double ro)
{
			if (NS <  -90) NS =  -90;
			if (NS >   90) NS =  -90;
			if (EW < -180) EW = -180;
			if (EW >  180) EW =  180;

			longitude = EW;
			LAT = NS - 0.19241666667 * sind(NS * 2);	/* 天文緯度 */
			RLT = ((0.998327112 + 0.001676399 * cosd(NS * 2) - 0.000003519 * cosd(NS * 4)) * 6378140 + ro) / 6371012;
			if (RLT < 0) RLT = 0;
			return;
}
Example #4
0
void Meteor::Draw( TCanvas *Canvs ) {
  TPoint temp;
  TPoint points[10];
  int i;


  temp = TPoint( radius[0]*sind(angle[0]+currentAngle),
				radius[0]*cosd(angle[0]+currentAngle) );
  ResetBoundingRect();
  temp = TPoint(temp.x+origin.x,temp.y+origin.y );
  ExpandBoundingRect( temp);
  points[0]= temp;
//  dc.MoveTo( origin+temp );
  for (i=1;i<=count;i++) {
	temp = TPoint( radius[i%count]*sind(angle[i%count]+currentAngle),
				   radius[i%count]*cosd(angle[i%count]+currentAngle) );
	temp = TPoint(temp.x+origin.x,temp.y+origin.y );
	ExpandBoundingRect( temp );
	points[i] = temp;
//    dc.LineTo( origin+temp );
  }
  points[count]=points[0];
  Canvs->Polyline( points, count);
}
Example #5
0
void fldpnt_azm(double mlat,double mlon,double nlat,double nlon,double *az) {
   
  double api;
  double aside,bside,cside;
  double Aangl,Bangl,arg;

  api=4*atan(1.0);
  aside=90-nlat;
  cside=90-mlat;
 
  Bangl=nlon-mlon;
  
  arg=cosd(aside)*cosd(cside)+sind(aside)*sind(cside)*cosd(Bangl);
  bside=acosd(arg);
  
  arg=(cosd(aside)-cosd(bside)*cosd(cside))/
      (sind(bside)*sind(cside));
  
  Aangl=acosd(arg);

  if (Bangl<0) Aangl=-Aangl;
  *az=Aangl;
 
} 
Example #6
0
struct PolygonData *MapCircleClip(float step) {
  float p[2],r;
  struct PolygonData *clip;
  
  clip=PolygonMake(2*sizeof(float),PolygonXYbbox);
  if (clip==NULL) return NULL;
  PolygonAddPolygon(clip,1);
  if (step<1) step=1; 
  if (step>45) step=45;
  for (r=0;r<360;r+=step) {
    p[0]=0.5+0.5*cosd(r);
    p[1]=0.5+0.5*sind(r);
    PolygonAdd(clip,p);
  } 
  return clip;
}
Example #7
0
static void drawPolygon(double x,double y,double z, double r, int n) {
	int i;
	double d, xi,yi, xf,yf;
	
	for(i = 0; i < n; i++) {
		xi = xf;
		yi = yf;
		
		d = i*360./(n-1);
		xf = x + r*cosd(d);
		yf = y - r*sind(d);

		if(i > 0)
			drawTriangle0(xi,yi,z,0,0, xf,yf,z,0,0, x,y,z,0,0);
	}
}
Example #8
0
/*******************\
|* hapgood_matrix  *|  defines a rotation matrix for a given angle & axis
\*******************|
 *
 * Rotation matrices are a special case.  They can be defined by two 
 * parameters: an axis about which to rotate (X, Y, Z) and an angle.
 * Given those two, we can fill in all nine elements of a 3x3 matrix.
 *
 * See http://sspg1.bnsc.rl.ac.uk/Share/Coordinates/matrix.htm
 */
void hapgood_matrix(const double theta, int axis, Mat mat)
{
  int i,j;

  /* 1.calculate sin(zeta) and cos(zeta),  */
  double sin_theta = sind(theta);
  double cos_theta = cosd(theta);

  /* compute the indices for the other two axes (e.g., "X,Z" for Y) */
  int t1 = (axis+1) % 3;
  int t2 = (axis+2) % 3;
  if (t1 > t2) {
    int tmp;
    tmp = t1;
    t1  = t2;
    t2  = tmp;
  }
    

  /*
  ** 4.set the remaining off-diagonal terms to zero.
  */
  for (i=0; i<3; i++)
    for (j=0; j<3; j++)
      mat[i][j] = 0.0;

  /*
  ** 2.determine the matrix diagonal:
  **   1.put 1 in the Nth term, where N=1 if the rotation axis is X, etc
  **   2.put cos(zeta) in the other two terms
  */
  mat[axis][axis] = 1.0;
  mat[t1][t1]     = cos_theta;
  mat[t2][t2]     = cos_theta;

  /*
  ** 3.locate the two off-diagonal terms in the same columns and rows as 
  **   the cos(zeta) terms - put sin(zeta) in the term above the diagonal
  **   and -sin(zeta) in the term below,
  */
  mat[t1][t2]     =  sin_theta;
  mat[t2][t1]     = -sin_theta;
}
Example #9
0
// Draw a cylinder oriented along the Z axis, centered on the origin
void ArmGLWidget::drawCylinder(float radius, float length)
{
    glPushMatrix();
    glScalef(radius, radius, length);
    glBegin(GL_TRIANGLE_FAN);

    // Front Face
    glNormal3f(0, 0, 1);
    for (int i = 0; i<SIDES; i++)
    {
        glVertex3f(sind((i+.5)*360/SIDES), cosd((i+.5)*360/SIDES), .5);
    }
    glEnd();

    // Back Face
    glBegin(GL_TRIANGLE_FAN);
    glNormal3f(0, 0, -1);
    for (int i = 0; i<SIDES; i++)
    {
        glVertex3f(sind((i+.5)*360/SIDES), cosd((i+.5)*360/SIDES), -.5);

    }
    glEnd();

    // Tube part
    glBegin(GL_QUADS);

    for (int i = 0; i<SIDES; i++)
    {
        glNormal3f(sind((i+.5)*360/SIDES), cosd((i+.5)*360/SIDES), 0);
        glVertex3f(sind((i+.5)*360/SIDES), cosd((i+.5)*360/SIDES), -.5);
        glVertex3f(sind((i+.5)*360/SIDES), cosd((i+.5)*360/SIDES), 0.5);
        i++;
        glVertex3f(sind((i+.5)*360/SIDES), cosd((i+.5)*360/SIDES), 0.5);
        glVertex3f(sind((i+.5)*360/SIDES), cosd((i+.5)*360/SIDES), -.5);
        i--;
    }
    glEnd();

    glPopMatrix();

    return;
}
Example #10
0
void glbthor(int iopt,double lat,double lon,
             double *rx,double *ry,double *rz,
             double *tx,double *ty,double *tz) {
   double sx,sy,sz,lax;
   if (iopt>0) {
     sx=cosd(lon)**rx+sind(lon)**ry;
     sy=-sind(lon)**rx+cosd(lon)**ry;
     sz=*rz;
     lax=90-lat;
     *tx=cosd(lax)*sx-sind(lax)*sz;
     *ty=sy;
     *tz=sind(lax)*sx+cosd(lax)*sz;
   } else {
     lax=90-lat;
     sx=cosd(lax)**tx+sind(lax)**tz;
     sy=*ty;
     sz=-sind(lax)**tx+cosd(lax)**tz;
     *rx=cosd(lon)*sx-sind(lon)*sy;
     *ry=sind(lon)*sx+cosd(lon)*sy;
     *rz=sz;
   }

}
Example #11
0
void RPosCubicGS(int center,int bcrd,int rcrd,
		   struct RadarSite *pos,
		   int frang,int rsep,int rxrise,double height,
           double *x,double *y,double *z) {
   
    /* returns cartesian cubic co-ordinates */
  double rx;
  double psi,d; 
  double rho,lat,lng;
  double re=6356.779;
  double offset=0;
  double bm_edge=0;
  double range_edge=0;

  if (center==0) {
    bm_edge=-pos->bmsep*0.5;
    range_edge=-0.5*rsep*20/3;
  }

  if (rxrise==0) rx=pos->recrise;
  else rx=rxrise;

  offset=pos->maxbeam/2.0-0.5;
  psi=pos->bmsep*(bcrd-offset)+bm_edge;

  d=slant_range(frang,rsep,rx,range_edge,rcrd+1)/2;
  if (height < 90) height=-re+sqrt((re*re)+2*d*re*sind(height)+(d*d));
  fldpnth_gs(pos->geolat,pos->geolon,psi,pos->boresite,
	      height,d,&rho,&lat,&lng);  

  /* convert to x,y,z (normalized to the unit sphere) */

  lng=90-lng;
  *x=rho*cos(lng*PI/180.0)*cos(lat*PI/180.0)/re;
  *y=rho*sin(lat*PI/180.0)/re;
  *z=rho*sin(lng*PI/180.0)*cos(lat*PI/180.0)/re;

} 
Example #12
0
static void rotateVecAboutAxis(double* vec, double angle, double* axis) {
	//http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/
		
	double
		a = 0,
		b = 0,
		c = 0,
		x = vec[0],
		y = vec[1],
		z = vec[2],
		u = axis[0],
		v = axis[1],
		w = axis[2],
		L = u*u + v*v + w*w,
		sqL = sqrt(L),
		co = cosd(angle),
		si = sind(angle),
		uxvywz = -u*x - v*y - w*z;
		
	vec[0] = (( -u*uxvywz )*(1-co) + L*x*co + sqL*(-w*y + v*z)*si) / L;
	vec[1] = (( -v*uxvywz )*(1-co) + L*y*co + sqL*(w*x - u*z)*si) / L;
	vec[2] = (( -w*uxvywz )*(1-co) + L*z*co + sqL*(-v*x + u*y)*si) / L;
}
Example #13
0
//axis is an array of length 3
//angle is in degrees
//code adapted from Fall 2015 Computer Graphics
static double* rotateAboutAxis(double *mat, double angle, double* axis) {
  double x, y, z, c, omc, s;
  double normAxis[3];
  normAxis[0] = axis[0];
  normAxis[1] = axis[1];
  normAxis[2] = axis[2];

  normalizeModify(normAxis, 3);

  c = cosd( angle );
  omc = 1.0 - c;
  s = sind( angle );

  x = normAxis[0];
  y = normAxis[1];
  z = normAxis[2];
   
  mat[0] = x*x*omc + c; 
  mat[1] = x*y*omc - z*s;
  mat[2] = x*z*omc + y*s;
  mat[3] = 0;
  
  mat[4] = x*y*omc + z*s;
  mat[5] = y*y*omc + c;
  mat[6] = y*z*omc - x*s;
  mat[7] = 0;
  
  mat[8] = x*z*omc - y*s;
  mat[9] = y*z*omc + x*s;
  mat[10] = z*z*omc + c;
  mat[11] = 0;
  
  mat[12] = mat[13] = mat[14] = 0;
  mat[15] = 1;
    
    return mat;
}
Example #14
0
void fldpnth_gs(double gdlat,double gdlon,double psi,double bore,
			 double fh,double r,double *frho,double *flat,
	                 double *flon) {

  double rrad,rlat,rlon,del;
  double tan_azi,azi,rel,xel,fhx,xal,rrho,ral,xh;
  double dum,dum1,dum2,dum3;
  double frad;  
 
  if (fh<=150) xh=fh;
  else {
    if (r<=300) xh=115;
    else if ((r>300) && (r<500)) xh=(r-300)/200*(fh-115)+115;
    else xh=fh;
  }

  if (r<150) xh=(r/150.0)*115.0;
  geodtgc(1,&gdlat,&gdlon,&rrad,&rlat,&rlon,&del);
  rrho=rrad;
  frad=rrad;
 

  do {
    *frho=frad+xh;
  
    rel=asind( ((*frho**frho) - (rrad*rrad) - (r*r)) / (2*rrad*r));
    xel=rel;
    if (((cosd(psi)*cosd(psi))-(sind(xel)*sind(xel)))<0) tan_azi=1e32;
      else tan_azi=sqrt( (sind(psi)*sind(psi))/
                ((cosd(psi)*cosd(psi))-(sind(xel)*sind(xel))));
    if (psi>0) azi=atand(tan_azi)*1.0;
      else azi=atand(tan_azi)*-1.0;
    xal=azi+bore;
    geocnvrt(gdlat,gdlon,xal,xel,&ral,&dum);

    fldpnt(rrho,rlat,rlon,ral,rel,r,frho,flat,flon);
    geodtgc(-1,&dum1,&dum2,&frad,flat,flon,&dum3);
    fhx=*frho-frad; 
  } while(fabs(fhx-xh) > 0.5);
} 
Example #15
0
void LineMove::setRotation(double rot)
{
	m_bounds.setSize(length() * QSizeF(cosd(rot), sind(rot)));
}
Example #16
0
void CreateMode::mouseMoveEvent(QMouseEvent *m)
{
	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
	modifiers = m->modifiers();
	
	double newX, newY;
	PageItem *currItem;
	QPoint np, np2, mop;
	QPainter p;
	QRect tx;
	m->accept();
//	qDebug() << "legacy mode move:" << m->x() << m->y() << m_canvas->globalToCanvas(m->globalPos()).x() << m_canvas->globalToCanvas(m->globalPos()).y();
//	emit MousePos(m->x()/m_canvas->scale(),// + m_doc->minCanvasCoordinate.x(), 
//				  m->y()/m_canvas->scale()); // + m_doc->minCanvasCoordinate.y());

	if (commonMouseMove(m))
		return;
	if (GetItem(&currItem))
	{
		newX = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x());
		newY = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y());
		
		if (m_doc->DragP)
			return;
	}
	else
	{
		if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
		{
			newX = mousePointDoc.x();
			newY = mousePointDoc.y();
			if (createObjectMode == modeDrawLine)
			{
				if (m_doc->SnapGrid)
				{
					newX = qRound(newX / m_doc->guidesPrefs().minorGridSpacing) * m_doc->guidesPrefs().minorGridSpacing;
					newY = qRound(newY / m_doc->guidesPrefs().minorGridSpacing) * m_doc->guidesPrefs().minorGridSpacing;
				}
				if (m->modifiers() & Qt::ControlModifier)
				{
					QRectF bounds(QPointF(createObjectPos.x(), createObjectPos.y()), QPointF(newX, newY));
					double newRot = xy2Deg(bounds.width(), bounds.height());
					if (newRot < 0.0)
						newRot += 360;
					newRot = constrainAngle(newRot, m_doc->opToolPrefs().constrain);
					double len = qMax(0.01, distance(bounds.width(), bounds.height()));
					bounds.setSize(len * QSizeF(cosd(newRot), sind(newRot)));
					newX = bounds.right();
					newY = bounds.bottom();
				}
			}
			//CB: #8099: Readd snapping for drag creation of lines by commenting this else..
			//else
			//{
				FPoint np2 = m_doc->ApplyGridF(FPoint(newX, newY));
				double nx = np2.x();
				double ny = np2.y();
				m_doc->ApplyGuides(&nx, &ny);
				m_doc->ApplyGuides(&nx, &ny,true);
				if(nx!=np2.x())
					xSnap = nx;
				if(ny!=np2.y())
					ySnap = ny;
				// #8959 : suppress qRound here as this prevent drawing line with angle constrain
				// precisely and does not allow to stick precisely to grid or guides
				newX = /*qRound(*/nx/*)*/;
				newY = /*qRound(*/ny/*)*/;
			//}

			canvasCurrCoord.setXY(newX, newY);
			m_view->HaveSelRect = true;

			double wSize = canvasCurrCoord.x() - createObjectPos.x();
			double hSize = canvasCurrCoord.y() - createObjectPos.y();
			QRectF createObjectRect(createObjectPos.x(), createObjectPos.y(), wSize, hSize);
			createObjectRect = createObjectRect.normalized();
			if (createObjectMode != modeDrawLine)
			{
				if (modifiers == Qt::ControlModifier)
					hSize = wSize;
				m_canvas->displaySizeHUD(m->globalPos(), wSize, hSize, false);
			}
			else
			{
				double angle = -xy2Deg(wSize, hSize);
				if (angle < 0.0)
					angle = angle + 360;
				double trueLength = sqrt(pow(createObjectRect.width(), 2) + pow(createObjectRect.height(), 2));
				m_canvas->displaySizeHUD(m->globalPos(), trueLength, angle, true);
			}

			// Necessary for drawControls to be called
			m_canvas->repaint();
		}
		else
			m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
	}
}
Example #17
0
static void moon_coords(double jd, double *ra, double *dec)
{
  double T, lambda, beta, pi, theta, l, m, n, r ;
  double x, y, z, xt, yt, zt, rt, jt ;

  T = (jd - 2451545.0) / 36525.0 ;

  lambda =  218.32 + 481267.883 * T
            +6.29*sind(134.9+477198.85*T)-1.27*sind(259.2-413335.38*T)
            +0.66*sind(235.7+890534.23*T)+0.21*sind(269.9+954397.70*T)
            -0.19*sind(357.5+35999.05*T)-0.11*sind(186.6+966404.05*T);

  beta = 5.13*sind(93.3+483202.03*T)+0.28*sind(228.2+960400.87*T)
        -0.28*sind(318.3+6003.18*T)+0.17*sind(217.6-407332.20*T);

  pi = 0.9508
        +0.0518*cosd(134.9+477198.85*T)+0.0095*cosd(259.2-413335.38*T)
        +0.0078*cosd(235.7+890534.23*T)+0.0028*cosd(269.9+954397.70*T) ;

  l = cosd(beta) * cosd(lambda) ;
  m = 0.9175*cosd(beta)*sind(lambda)-0.3978*sind(beta);
  n = 0.3978*cosd(beta)*sind(lambda)+0.9175*sind(beta);
  r = 1.0 / sind(pi) ;

  *ra = F * atan2(m,l) ;
  *dec = F * asin(n) ;

  x = r * cosd(*dec) * cosd(*ra) ;
  y = r * cosd(*dec) * sind(*ra) ;
  z = r * n ;

  jt = jd + 0.5 ;
  jt -= floor(jt) ;

  theta = 100.46 + 36000.77 * T + longitude + 360.0 * jt ;

  xt = x - cosd(latitude) * cosd(theta) ;
  yt = y - cosd(latitude) * sind(theta) ;
  zt = z - sind(latitude) ;

  rt = sqrt(xt*xt+yt*yt+zt*zt) ;

  *ra = F * atan2(yt, xt) ;
  *dec = F * asin(zt / rt) ;

  return ;
}
Example #18
0
int spcx2s(
   struct spcprm *spc,
   int nx,
   int sx,
   int sspec,
   const double x[],
   double spec[],
   int stat[])

{
   int statP2S, status = 0, statX2P;
   double beta;
   register int ix;
   register int *statp;
   register const double *xp;
   register double *specp;


   /* Initialize. */
   if (spc == 0) return 1;
   if (spc->flag == 0) {
      if (spcset(spc)) return 2;
   }

   /* Convert intermediate world coordinate x to X. */
   xp = x;
   specp = spec;
   statp = stat;
   for (ix = 0; ix < nx; ix++, xp += sx, specp += sspec) {
      *specp = spc->w[1] + (*xp)*spc->w[2];
      *(statp++) = 0;
   }

   /* If X is the grism parameter then convert it to wavelength. */
   if (spc->isGrism) {
      specp = spec;
      for (ix = 0; ix < nx; ix++, specp += sspec) {
         beta = atand(*specp) + spc->w[3];
         *specp = (sind(beta) + spc->w[4]) * spc->w[5];
      }
   }

   /* Apply the non-linear step of the algorithm chain to convert the    */
   /* X-type spectral variable to P-type intermediate spectral variable. */
   if (spc->spxX2P != 0) {
      if (statX2P = spc->spxX2P(spc->w[0], nx, sspec, sspec, spec, spec,
                                stat)) {
         if (statX2P == 4) {
            status = 3;
         } else {
            return statX2P;
         }
      }
   }

   /* Apply the linear step of the algorithm chain to convert P-type  */
   /* intermediate spectral variable to the required S-type variable. */
   if (spc->spxP2S != 0) {
      if (statP2S = spc->spxP2S(spc->w[0], nx, sspec, sspec, spec, spec,
                                stat)) {
         if (statP2S == 4) {
            status = 3;
         } else {
            return statP2S;
         }
      }
   }

   return status;
}
Example #19
0
/**
 * Note: timestamp = unixtimestamp (NEEDS to be 00:00:00 UT)
 *       Eastern longitude positive, Western longitude negative
 *       Northern latitude positive, Southern latitude negative
 *       The longitude value IS critical in this function!
 *       altit = the altitude which the Sun should cross
 *               Set to -35/60 degrees for rise/set, -6 degrees
 *               for civil, -12 degrees for nautical and -18
 *               degrees for astronomical twilight.
 *         upper_limb: non-zero -> upper limb, zero -> center
 *               Set to non-zero (e.g. 1) when computing rise/set
 *               times, and to zero when computing start/end of
 *               twilight.
 *        *rise = where to store the rise time
 *        *set  = where to store the set  time
 *                Both times are relative to the specified altitude,
 *                and thus this function can be used to compute
 *                various twilight times, as well as rise/set times
 * Return value:  0 = sun rises/sets this day, times stored at
 *                    *trise and *tset.
 *               +1 = sun above the specified "horizon" 24 hours.
 *                    *trise set to time when the sun is at south,
 *                    minus 12 hours while *tset is set to the south
 *                    time plus 12 hours. "Day" length = 24 hours
 *               -1 = sun is below the specified "horizon" 24 hours
 *                    "Day" length = 0 hours, *trise and *tset are
 *                    both set to the time when the sun is at south.
 *
 */
int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit)
{
	double  d,  /* Days since 2000 Jan 0.0 (negative before) */
	sr,         /* Solar distance, astronomical units */
	sRA,        /* Sun's Right Ascension */
	sdec,       /* Sun's declination */
	sradius,    /* Sun's apparent radius */
	t,          /* Diurnal arc */
	tsouth,     /* Time when Sun is at south */
	sidtime;    /* Local sidereal time */
	timelib_time *t_utc;
	timelib_sll   timestamp, old_sse;

	int rc = 0; /* Return cde from function - usually 0 */

	/* Normalize time */
	old_sse = t_loc->sse;
	t_loc->h = 12;
	t_loc->i = t_loc->s = 0;
	timelib_update_ts(t_loc, NULL);

	/* Calculate TS belonging to UTC 00:00 of the current day */
	t_utc = timelib_time_ctor();
	t_utc->y = t_loc->y;
	t_utc->m = t_loc->m;
	t_utc->d = t_loc->d;
	t_utc->h = t_utc->i = t_utc->s = 0;
	timelib_update_ts(t_utc, NULL);

	/* Compute d of 12h local mean solar time */
	timestamp = t_loc->sse;
	d = timelib_ts_to_juliandate(timestamp) - lon/360.0;

	/* Compute local sidereal time of this moment */
	sidtime = astro_revolution(astro_GMST0(d) + 180.0 + lon);

	/* Compute Sun's RA + Decl at this moment */
	astro_sun_RA_dec( d, &sRA, &sdec, &sr );

	/* Compute time when Sun is at south - in hours UT */
	tsouth = 12.0 - astro_rev180(sidtime - sRA) / 15.0;

	/* Compute the Sun's apparent radius, degrees */
	sradius = 0.2666 / sr;

	/* Do correction to upper limb, if necessary */
	if (upper_limb) {
		altit -= sradius;
	}

	/* Compute the diurnal arc that the Sun traverses to reach */
	/* the specified altitude altit: */
	{
		double cost;
		cost = (sind(altit) - sind(lat) * sind(sdec)) / (cosd(lat) * cosd(sdec));
		*ts_transit = t_utc->sse + (tsouth * 3600);
		if (cost >= 1.0) {
			rc = -1;
			t = 0.0;       /* Sun always below altit */

			*ts_rise = *ts_set = t_utc->sse + (tsouth * 3600);
		} else if (cost <= -1.0) {
			rc = +1;
			t = 12.0;      /* Sun always above altit */

			*ts_rise = t_loc->sse - (12 * 3600);
			*ts_set  = t_loc->sse + (12 * 3600);
		} else {
			t = acosd(cost) / 15.0;   /* The diurnal arc, hours */

			/* Store rise and set times - as Unix Timestamp */
			*ts_rise = ((tsouth - t) * 3600) + t_utc->sse;
			*ts_set  = ((tsouth + t) * 3600) + t_utc->sse;

			*h_rise = (tsouth - t);
			*h_set  = (tsouth + t);
		}
	}

	/* Kill temporary time and restore original sse */
	timelib_time_dtor(t_utc);
	t_loc->sse = old_sse;

	return rc;
}
Example #20
0
void draw()
{
	int j;
	
	glClear(GL_COLOR_BUFFER_BIT);
	
	// draw white circle (large)
	glColor3f(1.0, 1.0, 1.0);
	glBegin(GL_TRIANGLE_FAN);
		glVertex2f(0.0, 0.0);
		for(j = 0; j <= 360; j += 5)
		{
			glVertex2f(cosd(j) * RING_WIDTH / 2.0, sind(j) * RING_WIDTH / 2.0);
		}
	glEnd();
	
	// draw black circle
	glColor3f(0.05, 0.05, 0.05);
	glBegin(GL_TRIANGLE_FAN);
		glVertex2f(0.0, 0.0);
		for(j = 0; j <= 360; j += 5)
		{
			glVertex2f(cosd(j) * RING_INNER_WIDTH / 2.0, 
				sind(j) * RING_INNER_WIDTH / 2.0);
		}
	glEnd();
	
	// draw Shikiri Lines
	glColor3f(0.5, 0.164, 0.164);
	glBegin(GL_QUADS);
		glVertex2f(10.0, -10.0);
		glVertex2f(10.0, 10.0);
		glVertex2f(12.0, 10.0);
		glVertex2f(12.0, -10.0);
		glVertex2f(-10.0, -10.0);
		glVertex2f(-10.0, 10.0);
		glVertex2f(-12.0, 10.0);
		glVertex2f(-12.0, -10.0);
	glEnd();
	
	// draw robots
	for(j = 0; j < robots_size; j++)
	{
		glPushMatrix();
		glTranslatef(robots[j].pos.x, robots[j].pos.y, 0.0);
		glRotatef(robots[j].rot, 0.0, 0.0, 1.0);
		glColor3f(0.9, 0.9, 0.9);
		glBegin(GL_QUADS);
			glVertex2f(-robots[j].width / 2.0, -robots[j].width / 2.0);
			glVertex2f(-robots[j].width / 2.0, robots[j].width / 2.0);
			glVertex2f(robots[j].width / 2.0, robots[j].width / 2.0);
			glVertex2f(robots[j].width / 2.0, -robots[j].width / 2.0);
		glEnd();
		glColor3ubv(&robots[j].color.r);
		glBegin(GL_TRIANGLES);
			glVertex2f(-robots[j].width / 2.0, robots[j].width / 2.0);
			glVertex2f(robots[j].width / 2.0, 0.0);
			glVertex2f(-robots[j].width / 2.0, -robots[j].width / 2.0);
		glEnd();
		glPopMatrix();
	}
	
	glFlush();
}
Example #21
0
void GridTableMap(struct GridTable *ptr,struct RadarScan *scan,
                struct RadarSite *pos,int tlen,int iflg,double alt) {
  double freq=0,noise=0;
  double variance=0;
  double tm;
  int inx,cnt=0;
  int n,r,b;

  double v_e,p_l_e,w_l_e;

  struct GridBm *bm=NULL;

  tm=(scan->st_time+scan->ed_time)/2.0;

  if (ptr->status==0) {
     ptr->status=1;
     ptr->noise.mean=0;
     ptr->noise.sd=0;
     ptr->freq=0;
     ptr->nscan=0;
     GridTableZero(ptr->pnum,ptr->pnt);
     ptr->st_time=tlen*( (int) (tm/tlen)); 
     ptr->ed_time=ptr->st_time+tlen;
     ptr->st_id=scan->stid;
  }

  for (n=0;n<scan->num;n++) {
    if (scan->bm[n].bm==-1) continue;
    b=GridTableFindBeam(ptr,&scan->bm[n]);
    if (b==-1) {
      /* map a new beam */
      b=GridTableAddBeam(ptr,pos,alt,tm,&scan->bm[n]);
      if (b==-1) continue;
    }
    bm=&ptr->bm[b];

    for (r=0;r<scan->bm[n].nrang;r++) {
      if (scan->bm[n].sct[r]==0) continue;              
        v_e=scan->bm[n].rng[r].v_e;
        p_l_e=scan->bm[n].rng[r].p_l_e;
        w_l_e=scan->bm[n].rng[r].w_l_e;
    
        if (v_e<v_e_min) v_e=v_e_min;
        if (p_l_e<p_l_e_min) p_l_e=p_l_e_min;
        if (w_l_e<w_l_e_min) w_l_e=w_l_e_min;
 
        
	inx=bm->inx[r];
        
        ptr->pnt[inx].azm+=bm->azm[r];

        if (iflg !=0) { 
	  ptr->pnt[inx].vel.median_n+=
	    -(scan->bm[n].rng[r].v+bm->ival[r])*
	    1/(v_e*v_e)*cosd(bm->azm[r]);
	  ptr->pnt[inx].vel.median_e+=
	    -(scan->bm[n].rng[r].v+bm->ival[r])*
	    1/(v_e*v_e)*sind(bm->azm[r]);
	} else { 
          ptr->pnt[inx].vel.median_n+=-scan->bm[n].rng[r].v*cosd(bm->azm[r])/(v_e*v_e);
          ptr->pnt[inx].vel.median_e+=-scan->bm[n].rng[r].v*sind(bm->azm[r])/(v_e*v_e);
	}
        ptr->pnt[inx].pwr.median+=scan->bm[n].rng[r].p_l*1/(p_l_e*p_l_e);
        ptr->pnt[inx].wdt.median+=scan->bm[n].rng[r].w_l*1/(w_l_e*w_l_e);

        ptr->pnt[inx].vel.sd+=1/(v_e*v_e);
        ptr->pnt[inx].pwr.sd+=1/(p_l_e*p_l_e);
        ptr->pnt[inx].wdt.sd+=1/(w_l_e*w_l_e);
        ptr->pnt[inx].cnt++;
    }
  }

  for (n=0;n<scan->num;n++) {
    if (scan->bm[n].bm==-1) continue;
    ptr->prog_id=scan->bm[n].cpid;
    freq+=scan->bm[n].freq;
    noise+=scan->bm[n].noise;
    cnt++;
  }

  freq=freq/cnt;
  noise=noise/cnt;
  
  for (n=0;n<scan->num;n++) {
    if (scan->bm[n].bm==-1) continue;
    variance+=(scan->bm[n].noise-noise)*(scan->bm[n].noise-noise);
  }
  ptr->noise.mean+=noise;
  ptr->noise.sd+=sqrt(variance/cnt);
  ptr->freq+=freq;
  ptr->nscan++;
}
Example #22
0
/***********************************************************************//**
 * @brief Generic spherical-to-Cartesian projection
 *
 * @param[in] nphi Longitude vector length.
 * @param[in] ntheta Latitude vector length (0=no replication).
 * @param[in] spt Input vector step.
 * @param[in] sxy Output vector step.
 * @param[in] phi Longitude vector of the projected point in native spherical
 *                coordinates [deg].
 * @param[in] theta Latitude vector of the projected point in native spherical
 *                  coordinates [deg].
 * @param[out] x Vector of projected x coordinates.
 * @param[out] y Vector of projected y coordinates.
 * @param[out] stat Status return value for each vector element (always 0)
 *
 * Project native spherical coordinates (phi,theta) to Cartesian (x,y)
 * coordinates in the plane of projection.
 *
 * This method has been adapted from the wcslib function prj.c::cars2x().
 * The interface follows very closely that of wcslib. In contrast to the
 * wcslib routine, however, the method assumes that the projection has been
 * setup previsouly (as this will be done by the constructor).
 ***************************************************************************/
void GWcsSTG::prj_s2x(int nphi, int ntheta, int spt, int sxy,
                      const double* phi, const double* theta,
                      double* x, double* y, int* stat) const
{
    // Initialize projection if required
    if (!m_prjset)
        prj_set();

    // Set value replication length mphi,mtheta
    int mphi;
    int mtheta;
    if (ntheta > 0) {
        mphi   = nphi;
        mtheta = ntheta;
    } 
    else {
        mphi   = 1;
        mtheta = 1;
        ntheta = nphi;
    }

    // Initialise status code and statistics
    int status    = 0;
    int n_invalid = 0;
    
    // Do phi dependence
    const double* phip   = phi;
    int           rowoff = 0;
    int           rowlen = nphi * sxy;
    for (int iphi = 0; iphi < nphi; ++iphi, rowoff += sxy, phip += spt) {
        double sinphi;
        double cosphi;
        sincosd(*phip, &sinphi, &cosphi);
        double* xp = x + rowoff;
        double* yp = y + rowoff;
        for (int itheta = 0; itheta < mtheta; ++itheta) {
            *xp = sinphi;
            *yp = cosphi;
            xp += rowlen;
            yp += rowlen;
        }
    }

    // Do theta dependence
    const double* thetap = theta;
    double*       xp     = x;
    double*       yp     = y;
    int*          statp  = stat;
    for (int itheta = 0; itheta < ntheta; ++itheta, thetap += spt) {
        
        // Compute sine of Theta
        double s = 1.0 + sind(*thetap);
        
        // If 1+sine is zero we cannot proceed. Set all pixels to (0,0) and flag
        // them as being bad
        if (s == 0.0) {
            for (int iphi = 0; iphi < mphi; ++iphi, xp += sxy, yp += sxy) {
                *xp        = 0.0;
                *yp        = 0.0;
                *(statp++) = 1;
                n_invalid++;
            }
            status = 4;
        }
        
        // ... otherwise proceed, but if strict bound checking has been requested
        // then flag all pixels as bad that have negative sin(theta)
        else {
            double r = m_w[0] * cosd(*thetap)/s;
            for (int iphi = 0; iphi < mphi; ++iphi, xp += sxy, yp += sxy) {
                *xp        =  r*(*xp) - m_x0;
                *yp        = -r*(*yp) - m_y0;
                *(statp++) = 0;
            }
        }
    }
  
    // Handle status code
    if (status == 4)
        throw GException::wcs_invalid_phi_theta(G_PRJ_S2X, n_invalid);
    
    // Return
    return;
}
Example #23
0
void sphtocar(double r,double theta,double phi,double *x,double *y,double *z) {
  *x=r*sind(90.0-theta)*cosd(phi);
  *y=r*sind(90.0-theta)*sind(phi);
  *z=r*cosd(90.0-theta);
}
Example #24
0
int __sunriset__( long year, long month, long day, double lon, double lat,
                 double altit, int upper_limb, double *trise, double *tset )
/***************************************************************************/
/* Note: year,month,date = calendar date, 1801-2099 only.             */
/*       Eastern longitude positive, Western longitude negative       */
/*       Northern latitude positive, Southern latitude negative       */
/*       The longitude value IS critical in this function!            */
/*       altit = the altitude which the Sun should cross              */
/*               Set to -35/60 degrees for rise/set, -6 degrees       */
/*               for civil, -12 degrees for nautical and -18          */
/*               degrees for astronomical twilight.                   */
/*         upper_limb: non-zero -> upper limb, zero -> center         */
/*               Set to non-zero (e.g. 1) when computing rise/set     */
/*               times, and to zero when computing start/end of       */
/*               twilight.                                            */
/*        *rise = where to store the rise time                        */
/*        *set  = where to store the set  time                        */
/*                Both times are relative to the specified altitude,  */
/*                and thus this function can be used to comupte       */
/*                various twilight times, as well as rise/set times   */
/* Return value:  0 = sun rises/sets this day, times stored at        */
/*                    *trise and *tset.                               */
/*               +1 = sun above the specified "horizon" 24 hours.     */
/*                    *trise set to time when the sun is at south,    */
/*                    minus 12 hours while *tset is set to the south  */
/*                    time plus 12 hours. "Day" length = 24 hours     */
/*               -1 = sun is below the specified "horizon" 24 hours   */
/*                    "Day" length = 0 hours, *trise and *tset are    */
/*                    both set to the time when the sun is at south.  */
/*                                                                    */
/**********************************************************************/
{
    double  d,  /* Days since 2000 Jan 0.0 (negative before) */
    sr,         /* Solar distance, astronomical units */
    sRA,        /* Sun's Right Ascension */
    sdec,       /* Sun's declination */
    sradius,    /* Sun's apparent radius */
    t,          /* Diurnal arc */
    tsouth,     /* Time when Sun is at south */
    sidtime;    /* Local sidereal time */
    
    int rc = 0; /* Return cde from function - usually 0 */
    
    /* Compute d of 12h local mean solar time */
    d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
    
    /* Compute local sideral time of this moment */
    sidtime = revolution( GMST0(d) + 180.0 + lon );
    
    /* Compute Sun's RA + Decl at this moment */
    sun_RA_dec( d, &sRA, &sdec, &sr );
    
    /* Compute time when Sun is at south - in hours UT */
    tsouth = 12.0 - rev180(sidtime - sRA)/15.0;
    
    /* Compute the Sun's apparent radius, degrees */
    sradius = 0.2666 / sr;
    
    /* Do correction to upper limb, if necessary */
    if ( upper_limb )
        altit -= sradius;
    
    /* Compute the diurnal arc that the Sun traverses to reach */
    /* the specified altitide altit: */
    {
        double cost;
        cost = ( sind(altit) - sind(lat) * sind(sdec) ) /
        ( cosd(lat) * cosd(sdec) );
        if ( cost >= 1.0 )
            rc = -1, t = 0.0;       /* Sun always below altit */
        else if ( cost <= -1.0 )
            rc = +1, t = 12.0;      /* Sun always above altit */
        else
            t = acosd(cost)/15.0;   /* The diurnal arc, hours */
    }
    
    /* Store rise and set times - in hours UT */
    *trise = tsouth - t;
    *tset  = tsouth + t;
    
    return rc;
}  /* __sunriset__ */
Example #25
0
void fps_camera::rotateYaw (float direction)
{
   yaw += 3*direction*rotateSpeed;
   ref.x = sind(yaw);
   ref.z = -cosd(yaw);
}
Example #26
0
double __daylen__( long year, long month, long day, double lon, double lat,
                  double altit, int upper_limb )
/**********************************************************************/
/* Note: year,month,date = calendar date, 1801-2099 only.             */
/*       Eastern longitude positive, Western longitude negative       */
/*       Northern latitude positive, Southern latitude negative       */
/*       The longitude value is not critical. Set it to the correct   */
/*       longitude if you're picky, otherwise set to to, say, 0.0     */
/*       The latitude however IS critical - be sure to get it correct */
/*       altit = the altitude which the Sun should cross              */
/*               Set to -35/60 degrees for rise/set, -6 degrees       */
/*               for civil, -12 degrees for nautical and -18          */
/*               degrees for astronomical twilight.                   */
/*         upper_limb: non-zero -> upper limb, zero -> center         */
/*               Set to non-zero (e.g. 1) when computing day length   */
/*               and to zero when computing day+twilight length.      */
/**********************************************************************/
{
    double  d,  /* Days since 2000 Jan 0.0 (negative before) */
    obl_ecl,    /* Obliquity (inclination) of Earth's axis */
    sr,         /* Solar distance, astronomical units */
    slon,       /* True solar longitude */
    sin_sdecl,  /* Sine of Sun's declination */
    cos_sdecl,  /* Cosine of Sun's declination */
    sradius,    /* Sun's apparent radius */
    t;          /* Diurnal arc */
    
    /* Compute d of 12h local mean solar time */
    d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
    
    /* Compute obliquity of ecliptic (inclination of Earth's axis) */
    obl_ecl = 23.4393 - 3.563E-7 * d;
    
    /* Compute Sun's position */
    sunpos( d, &slon, &sr );
    
    /* Compute sine and cosine of Sun's declination */
    sin_sdecl = sind(obl_ecl) * sind(slon);
    cos_sdecl = sqrt( 1.0 - sin_sdecl * sin_sdecl );
    
    /* Compute the Sun's apparent radius, degrees */
    sradius = 0.2666 / sr;
    
    /* Do correction to upper limb, if necessary */
    if ( upper_limb )
        altit -= sradius;
    
    /* Compute the diurnal arc that the Sun traverses to reach */
    /* the specified altitide altit: */
    {
        double cost;
        cost = ( sind(altit) - sind(lat) * sin_sdecl ) /
        ( cosd(lat) * cos_sdecl );
        if ( cost >= 1.0 )
            t = 0.0;                      /* Sun always below altit */
        else if ( cost <= -1.0 )
            t = 24.0;                     /* Sun always above altit */
        else  t = (2.0/15.0) * acosd(cost); /* The diurnal arc, hours */
    }
    return t;
}  /* __daylen__ */
Example #27
0
int spcset(struct spcprm *spc)

{
  static const char *function = "spcset";

  char   ctype[9], ptype, xtype;
  int    restreq, status;
  double alpha, beta_r, crvalX, dn_r, dXdS, epsilon, G, m, lambda_r, n_r,
         t, restfrq, restwav, theta;
  struct wcserr **err;

  if (spc == 0x0) return SPCERR_NULL_POINTER;
  err = &(spc->err);

  if (undefined(spc->crval)) {
    return wcserr_set(WCSERR_SET(SPCERR_BAD_SPEC_PARAMS),
      "Spectral crval is undefined");
  }

  memset((spc->type)+4, 0, 4);
  spc->code[3] = '\0';
  wcsutil_blank_fill(4, spc->type);
  wcsutil_blank_fill(3, spc->code);
  spc->w[0] = 0.0;


  /* Analyse the spectral axis type. */
  memset(ctype, 0, 9);
  strncpy(ctype, spc->type, 4);
  if (*(spc->code) != ' ') {
    sprintf(ctype+4, "-%s", spc->code);
  }
  restfrq = spc->restfrq;
  restwav = spc->restwav;
  if ((status = spcspxe(ctype, spc->crval, restfrq, restwav, &ptype, &xtype,
                        &restreq, &crvalX, &dXdS, &(spc->err)))) {
    return status;
  }

  /* Satisfy rest frequency/wavelength requirements. */
  if (restreq) {
    if (restreq == 3 && restfrq == 0.0 && restwav == 0.0) {
      /* VRAD-V2F, VOPT-V2W, and ZOPT-V2W require the rest frequency or */
      /* wavelength for the S-P and P-X transformations but not for S-X */
      /* so supply a phoney value. */
      restwav = 1.0;
    }

    if (restfrq == 0.0) {
      restfrq = C/restwav;
    } else {
      restwav = C/restfrq;
    }

    if (ptype == 'F') {
      spc->w[0] = restfrq;
    } else if (ptype != 'V') {
      spc->w[0] = restwav;
    } else {
      if (xtype == 'F') {
        spc->w[0] = restfrq;
      } else {
        spc->w[0] = restwav;
      }
    }
  }

  spc->w[1] = crvalX;
  spc->w[2] = dXdS;


  /* Set pointers-to-functions for the linear part of the transformation. */
  if (ptype == 'F') {
    if (strcmp(spc->type, "FREQ") == 0) {
      /* Frequency. */
      spc->flag = FREQ;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "AFRQ") == 0) {
      /* Angular frequency. */
      spc->flag = AFRQ;
      spc->spxP2S = freqafrq;
      spc->spxS2P = afrqfreq;

    } else if (strcmp(spc->type, "ENER") == 0) {
      /* Photon energy. */
      spc->flag = ENER;
      spc->spxP2S = freqener;
      spc->spxS2P = enerfreq;

    } else if (strcmp(spc->type, "WAVN") == 0) {
      /* Wave number. */
      spc->flag = WAVN;
      spc->spxP2S = freqwavn;
      spc->spxS2P = wavnfreq;

    } else if (strcmp(spc->type, "VRAD") == 0) {
      /* Radio velocity. */
      spc->flag = VRAD;
      spc->spxP2S = freqvrad;
      spc->spxS2P = vradfreq;
    }

  } else if (ptype == 'W') {
    if (strcmp(spc->type, "WAVE") == 0) {
      /* Vacuum wavelengths. */
      spc->flag = WAVE;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "VOPT") == 0) {
      /* Optical velocity. */
      spc->flag = VOPT;
      spc->spxP2S = wavevopt;
      spc->spxS2P = voptwave;

    } else if (strcmp(spc->type, "ZOPT") == 0) {
      /* Redshift. */
      spc->flag = ZOPT;
      spc->spxP2S = wavezopt;
      spc->spxS2P = zoptwave;
    }

  } else if (ptype == 'A') {
    if (strcmp(spc->type, "AWAV") == 0) {
      /* Air wavelengths. */
      spc->flag = AWAV;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;
    }

  } else if (ptype == 'V') {
    if (strcmp(spc->type, "VELO") == 0) {
      /* Relativistic velocity. */
      spc->flag = VELO;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "BETA") == 0) {
      /* Velocity ratio (v/c). */
      spc->flag = BETA;
      spc->spxP2S = velobeta;
      spc->spxS2P = betavelo;
    }
  }


  /* Set pointers-to-functions for the non-linear part of the spectral */
  /* transformation.                                                   */
  spc->isGrism = 0;
  if (xtype == 'F') {
    /* Axis is linear in frequency. */
    if (ptype == 'F') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'W') {
      spc->spxX2P = freqwave;
      spc->spxP2X = wavefreq;

    } else if (ptype == 'A') {
      spc->spxX2P = freqawav;
      spc->spxP2X = awavfreq;

    } else if (ptype == 'V') {
      spc->spxX2P = freqvelo;
      spc->spxP2X = velofreq;
    }

    spc->flag += F2S;

  } else if (xtype == 'W' || xtype == 'w') {
    /* Axis is linear in vacuum wavelengths. */
    if (ptype == 'F') {
      spc->spxX2P = wavefreq;
      spc->spxP2X = freqwave;

    } else if (ptype == 'W') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'A') {
      spc->spxX2P = waveawav;
      spc->spxP2X = awavwave;

    } else if (ptype == 'V') {
      spc->spxX2P = wavevelo;
      spc->spxP2X = velowave;
    }

    if (xtype == 'W') {
      spc->flag += W2S;
    } else {
      /* Grism in vacuum. */
      spc->isGrism = 1;
      spc->flag += GRI;
    }

  } else if (xtype == 'A' || xtype == 'a') {
    /* Axis is linear in air wavelengths. */
    if (ptype == 'F') {
      spc->spxX2P = awavfreq;
      spc->spxP2X = freqawav;

    } else if (ptype == 'W') {
      spc->spxX2P = awavwave;
      spc->spxP2X = waveawav;

    } else if (ptype == 'A') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'V') {
      spc->spxX2P = awavvelo;
      spc->spxP2X = veloawav;
    }

    if (xtype == 'A') {
      spc->flag += A2S;
    } else {
      /* Grism in air. */
      spc->isGrism = 2;
      spc->flag += GRA;
    }

  } else if (xtype == 'V') {
    /* Axis is linear in relativistic velocity. */
    if (ptype == 'F') {
      spc->spxX2P = velofreq;
      spc->spxP2X = freqvelo;

    } else if (ptype == 'W') {
      spc->spxX2P = velowave;
      spc->spxP2X = wavevelo;

    } else if (ptype == 'A') {
      spc->spxX2P = veloawav;
      spc->spxP2X = awavvelo;

    } else if (ptype == 'V') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;
    }

    spc->flag += V2S;
  }


  /* Check for grism axes. */
  if (spc->isGrism) {
    /* Axis is linear in "grism parameter"; work in wavelength. */
    lambda_r = crvalX;

    /* Set defaults. */
    if (undefined(spc->pv[0])) spc->pv[0] = 0.0;
    if (undefined(spc->pv[1])) spc->pv[1] = 0.0;
    if (undefined(spc->pv[2])) spc->pv[2] = 0.0;
    if (undefined(spc->pv[3])) spc->pv[3] = 1.0;
    if (undefined(spc->pv[4])) spc->pv[4] = 0.0;
    if (undefined(spc->pv[5])) spc->pv[5] = 0.0;
    if (undefined(spc->pv[6])) spc->pv[6] = 0.0;

    /* Compute intermediaries. */
    G       = spc->pv[0];
    m       = spc->pv[1];
    alpha   = spc->pv[2];
    n_r     = spc->pv[3];
    dn_r    = spc->pv[4];
    epsilon = spc->pv[5];
    theta   = spc->pv[6];

    t = G*m/cosd(epsilon);
    beta_r = asind(t*lambda_r - n_r*sind(alpha));

    t -= dn_r*sind(alpha);

    spc->w[1] = -tand(theta);
    spc->w[2] *= t / (cosd(beta_r)*cosd(theta)*cosd(theta));
    spc->w[3] = beta_r + theta;
    spc->w[4] = (n_r - dn_r*lambda_r)*sind(alpha);
    spc->w[5] = 1.0 / t;
  }

  return 0;
}
Example #28
0
int spcx2s(
  struct spcprm *spc,
  int nx,
  int sx,
  int sspec,
  const double x[],
  double spec[],
  int stat[])

{
  static const char *function = "spcx2s";

  int statP2S, status = 0, statX2P;
  double beta;
  register int ix;
  register int *statp;
  register const double *xp;
  register double *specp;
  struct wcserr **err;

  /* Initialize. */
  if (spc == 0x0) return SPCERR_NULL_POINTER;
  err = &(spc->err);

  if (spc->flag == 0) {
    if ((status = spcset(spc))) return status;
  }

  /* Convert intermediate world coordinate x to X. */
  xp = x;
  specp = spec;
  statp = stat;
  for (ix = 0; ix < nx; ix++, xp += sx, specp += sspec) {
    *specp = spc->w[1] + (*xp)*spc->w[2];
    *(statp++) = 0;
  }

  /* If X is the grism parameter then convert it to wavelength. */
  if (spc->isGrism) {
    specp = spec;
    for (ix = 0; ix < nx; ix++, specp += sspec) {
      beta = atand(*specp) + spc->w[3];
      *specp = (sind(beta) + spc->w[4]) * spc->w[5];
    }
  }

  /* Apply the non-linear step of the algorithm chain to convert the    */
  /* X-type spectral variable to P-type intermediate spectral variable. */
  if (spc->spxX2P) {
    if ((statX2P = spc->spxX2P(spc->w[0], nx, sspec, sspec, spec, spec,
                               stat))) {
      if (statX2P == SPXERR_BAD_INSPEC_COORD) {
        status = SPCERR_BAD_X;
      } else if (statX2P == SPXERR_BAD_SPEC_PARAMS) {
        return wcserr_set(WCSERR_SET(SPCERR_BAD_SPEC_PARAMS),
          "Invalid spectral parameters: Frequency or wavelength is 0");
      } else {
        return wcserr_set(SPC_ERRMSG(spc_spxerr[statX2P]));
      }
    }
  }

  /* Apply the linear step of the algorithm chain to convert P-type  */
  /* intermediate spectral variable to the required S-type variable. */
  if (spc->spxP2S) {
    if ((statP2S = spc->spxP2S(spc->w[0], nx, sspec, sspec, spec, spec,
                               stat))) {
      if (statP2S == SPXERR_BAD_INSPEC_COORD) {
        status = SPCERR_BAD_X;
      } else if (statP2S == SPXERR_BAD_SPEC_PARAMS) {
        return wcserr_set(WCSERR_SET(SPCERR_BAD_SPEC_PARAMS),
          "Invalid spectral parameters: Frequency or wavelength is 0");
      } else {
        return wcserr_set(SPC_ERRMSG(spc_spxerr[statP2S]));
      }
    }
  }

  if (status) {
    wcserr_set(SPC_ERRMSG(status));
  }
  return status;
}
Example #29
0
int main (int argc, char *argv[]){
	if (argc != 2){
		printf("Give a parameter file.\n");
		exit(1);
	}
	int SpaceGrp;
	double LatC[6], wl, Lsd, MaxRingRad;
	char *ParamFN;
    FILE *fileParam;
    ParamFN = argv[1];
    char aline[1000];
    fileParam = fopen(ParamFN,"r");
    char *str, dummy[1000];
    int LowNr;
    while (fgets(aline,1000,fileParam)!=NULL){
        str = "SpaceGroup ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %d", dummy, &SpaceGrp);
            continue;
        }
        str = "LatticeConstant ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf %lf %lf %lf %lf %lf", dummy, &LatC[0],
					&LatC[1], &LatC[2], &LatC[3], &LatC[4], &LatC[5]);
            continue;
        }
        str = "LatticeParameter ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf %lf %lf %lf %lf %lf", dummy, &LatC[0],
					&LatC[1], &LatC[2], &LatC[3], &LatC[4], &LatC[5]);
            continue;
        }
        str = "Wavelength ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &wl);
            continue;
        }
        str = "Lsd ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &Lsd);
            continue;
        }
        str = "MaxRingRad ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &MaxRingRad);
            continue;
        }
	}
	printf("%f %f %f %d %f %f %f %f %f %f\n",wl,Lsd,MaxRingRad,SpaceGrp,LatC[0],LatC[1],LatC[2],LatC[3],LatC[4],LatC[5]);
	int h, k, l, iList, restriction, M, i, j;
	int Minh, Mink, Minl;
	int CCMx_PL[9], deterCCMx_LP = 0;
	double Epsilon = 0.0001;
	int Families[50000][3];
	T_SgInfo *SgInfo;
	char SgName[200]; 
	int F_Convention='A';
	const T_TabSgName *tsgn; 
	
	printf("Generating hkl's\n");
	if((SgInfo = (T_SgInfo *)malloc(sizeof(T_SgInfo)))==NULL){
		printf("Unable to allocate SgInfo\n");
		printf("Aborting\n");
		exit(1);
	}
	SgInfo->GenOption = 0;
	SgInfo->MaxList   = 192;
	if((SgInfo->ListSeitzMx = (T_RTMx*)malloc(SgInfo->MaxList * sizeof(T_RTMx)))==NULL){
		printf("Unable to allocate (SgInfo.ListSeitzMx\n");
		printf("Aborting\n");
		exit(1);
	}
	SgInfo->ListRotMxInfo = NULL;
	InitSgInfo(SgInfo);
	sprintf(SgName,"%d",SpaceGrp);
	tsgn = FindTabSgNameEntry(SgName, F_Convention);
	if (tsgn == NULL){
		printf("Error: Unknown Space Group Symbol\n");
		printf("Aborting\n");
		exit(1);
	}
	sprintf(SgName,"%s",tsgn->HallSymbol);
	SgInfo->TabSgName = tsgn;
	if (tsgn) SgInfo->GenOption = 1;
	{
		int pos_hsym;
		pos_hsym = ParseHallSymbol(SgName, SgInfo);
		
		if (SgError != NULL) {
			printf("Error: Unknown Space Group Symbol\n");
			printf("Aborting\n");
			exit(1);
		}
	}
	if(CompleteSgInfo(SgInfo)!=0) {
		printf("Error in Complete\n");
		printf("Aborting\n");
		exit(1);
	}
	if (SgInfo->LatticeInfo->Code != 'P')
	{
		deterCCMx_LP = deterRotMx(SgInfo->CCMx_LP);
		InverseRotMx(SgInfo->CCMx_LP, CCMx_PL);
		if (deterCCMx_LP < 1) {
			printf("deterCMM failed.\n");
			return 0;
		}
	}
	int Maxh, Maxk, Maxl;
	int nrFilled=0;
	Maxh = 10;
	Maxk = 10;
	Maxl = 10;
	SetListMin_hkl(SgInfo, Maxk, Maxl, &Minh, &Mink, &Minl);
	printf("Will go from %d to %d in h; %d to %d in k; %d to %d in l.\n",Minh, Maxh, Mink, Maxk, Minl, Maxl);
	for (h = Minh; h <= Maxh; h++){
		for (k = Mink; k <= Maxk; k++){
			for (l = Minl; l <= Maxl; l++){
				if (h==0 && k==0 && l==0){
					continue;
				}
				iList = IsSysAbsent_hkl(SgInfo, h, k, l, &restriction);
				if (SgError != NULL) {
					printf("IsSysAbsent_hkl failed.\n");
					return 0;
				}
				if (iList == 0){
					if ((iList = IsSuppressed_hkl(SgInfo, Minh, Mink, Minl,
						Maxk, Maxl, h, k, l)) != 0) {/* Suppressed reflections */
					} else {
						//printf("New plane.\n");
						T_Eq_hkl Eq_hkl;
						M = BuildEq_hkl(SgInfo, &Eq_hkl, h, k, l);
						if (SgError != NULL){
							return 0;
						}
						for (i=0;i<Eq_hkl.N;i++){
							for (j=-1;j<=1;j+=2){
								//printf("%d %d %d\n",Eq_hkl.h[i]*j,Eq_hkl.k[i]*j,Eq_hkl.l[i]*j);
								Families[nrFilled][0] = Eq_hkl.h[i]*j;
								Families[nrFilled][1] = Eq_hkl.k[i]*j;
								Families[nrFilled][2] = Eq_hkl.l[i]*j;
								nrFilled++;
							}
						}
					}
				}
			}
		}
	}
	int AreDuplicates[50000];
	double **UniquePlanes;
	UniquePlanes = allocMatrix(50000,3);
	for (i=0;i<50000;i++) AreDuplicates[i] = 0;
	int nrPlanes=0;
	for (i=0;i<nrFilled-1;i++){
		if (AreDuplicates[i] == 1){
			continue;
		}
		for (j=i+1;j<nrFilled;j++){
			if (Families[i][0] == Families[j][0] && 
				Families[i][1] == Families[j][1] && 
				Families[i][2] == Families[j][2] &&
				AreDuplicates[j] == 0){
					AreDuplicates[j] = 1;
			}
		}
		UniquePlanes[nrPlanes][0] = (double)Families[i][0];
		UniquePlanes[nrPlanes][1] = (double)Families[i][1];
		UniquePlanes[nrPlanes][2] = (double)Families[i][2];
		nrPlanes++;
	}
	double **hkls;
	hkls = allocMatrix(nrPlanes,12);
	CorrectHKLsLatC(LatC,UniquePlanes,nrPlanes,hkls);
	SortFunc(nrPlanes,11,hkls,3,-1);
	double DsMin = wl/(2*sind((atand(MaxRingRad/Lsd))/2));
	for (i=0;i<nrPlanes;i++){
		if (hkls[i][3] < DsMin){
			nrPlanes = i;
			break;
		}
	}
	int RingNr = 1;
	double DsTemp = hkls[0][3];
	hkls[0][4] = 1;
	hkls[0][8] = asind(wl/(2*(hkls[0][3])));
	hkls[0][9] = hkls[0][8]*2;
	hkls[0][10] = Lsd*tand(hkls[0][9]);
	for (i=1;i<nrPlanes;i++){
		if (fabs(hkls[i][3] - DsTemp) < Epsilon){
			hkls[i][4] = RingNr;
		}else{
			DsTemp = hkls[i][3];
			RingNr++;
			hkls[i][4] = RingNr;
		}
		hkls[i][8] = asind(wl/(2*(hkls[i][3])));
		hkls[i][9] = hkls[i][8]*2;
		hkls[i][10] = Lsd*tand(hkls[i][9]);
	}
	char *fn = "hkls.csv";
	FILE *fp;
	fp = fopen(fn,"w");
	fprintf(fp,"h k l D-spacing RingNr\n");
	for (i=0;i<nrPlanes;i++){
		fprintf(fp,"%.0f %.0f %.0f %f %.0f %f %f %f %f %f %f\n",hkls[i][0],
			hkls[i][1],hkls[i][2],hkls[i][3],hkls[i][4],
			hkls[i][5],hkls[i][6],hkls[i][7],hkls[i][8],
			hkls[i][9],hkls[i][10]);
	}
}
Example #30
0
void ArmGLWidget::drawArm(ArmAstroAngles A)
{
    // Rover!
    glColor3f (.5, .5, .5);
    glTranslatef (-35, 5, 15);
    drawBox(45, 15, 45);
    glTranslatef (35, -5, -15);

    glColor3f (1, 1, 1);

    // Testing
    matrix m = MatrixTranslate(0, 0, 0);

    //m = MatrixRotateY(A.base.rotation) * m;
    m = MatrixTranslate (-ArmController::BASE_OFFSET, 0, 0) * m;

    m = MatrixRotateZ(A.base.shoulder) * m;
    m = MatrixTranslate(ArmController::SEG1_LEN, 0, 0) * m;

    //m = MatrixTranslate(0, 0, -OFFSET) * m;
    m = MatrixRotateZ(A.base.elbow - 180) * m;
    m = MatrixTranslate(40, 0, 0) * m;


    glPushMatrix();
        glMultMatrixf (*(m.array));
        drawBox(1, 1, 1);
    glPopMatrix();

    glColor3f (1, 0, 0);

    // Draw arm box
    drawBox(15, 5, 15);

    glRotatef(A.base.rotation, 0, 1, 0);
    glTranslatef(0, 3.5, 0);
    drawCylinderY(3, 2);
    glTranslatef(-ArmController::BASE_OFFSET, 2, 0);
    drawCylinderZ(2, 6);


    glColor3f (0, 1, 0);

    glRotatef (A.base.shoulder, 0, 0, 1);//g.RotateTransform(-A.thetaS, System..Drawing2D.MatrixOrder.Prepend);
    glTranslatef(ArmController::SEG1_LEN/2, 0, 0);
    drawCylinderX(2, ArmController::SEG1_LEN);
    glTranslatef(ArmController::SEG1_LEN/2, 0, -ArmController::OFFSET/2);
    drawCylinderZ(2, ArmController::OFFSET + 4);
    glTranslatef(0, 0, -ArmController::OFFSET/2);

    glColor3f (1, 1, 0);

    // Elbow to wrist elevation
    glRotatef (A.base.elbow - 180, 0, 0, 1);//g.RotateTransform(180 - A.thetaE, System.Drawing.Drawing2D.MatrixOrder.Prepend);
    float elbowToEnd = 20;
    glTranslatef (elbowToEnd/2, 0, 0);
    drawCylinderX(2, elbowToEnd);
    glTranslatef (elbowToEnd/2, 0, 0);
    drawCylinderZ(2, 4);


    //glColor3f (0, 0, 1);
    // Wirst elevation to wrist rotate
    //glRotatef(-A.wristElevation, 0, 0, 1);//g.RotateTransform(A.thetaW, System.Drawing.Drawing2D.MatrixOrder.Prepend);

    //glTranslatef(ArmController::END_EFFECTOR_MID/2, 0, 0);
    //drawCylinderX(2, ArmController::END_EFFECTOR_MID);
    //glTranslatef(ArmController::END_EFFECTOR_MID/2, 0, 0);
    //drawCylinderY(2, 4);

    glColor3f (1, 0, 1);

    float GRIPPER_ARM_LEN = 8;
    //float HALF = ArmController::END_EFFECTOR_END - GRIPPER_ARM_LEN; // Point of rotation servo
    //glRotatef(A.writsTip, 0, 1, 0);
    //glTranslatef(HALF/2, 0, 0);
    //drawCylinderX(2, HALF);
    //glTranslatef(HALF/2, 0, 0);

    //glColor3f (0, 1, 1);

    static float r = 0;
    r += 7;

    //glRotatef (A.wristRotation, 1, 0, 0);

    // CLAMPY CLAMPY!
    static float a = 0;
    a = sind(r) * 15;
    drawCylinderX(4, 1);
    glPushMatrix();
    glTranslatef(0, 0, -4);
    drawCylinderY(1, 2);
    glRotatef(a, 0, 1, 0);
    glTranslatef (GRIPPER_ARM_LEN/2, 0, 0);
    drawCylinderX(1, GRIPPER_ARM_LEN);
    glTranslatef (GRIPPER_ARM_LEN/2, 0, 0);
    glRotatef(-a - 90, 0, 1, 0);
    drawCylinderY(1, 2);
    glTranslatef(1, 0, 0);
    drawCylinderX(1, 2);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(0, 0, 4);
    drawCylinderY(1, 2);
    glRotatef(-a, 0, 1, 0);
    glTranslatef (GRIPPER_ARM_LEN/2, 0, 0);
    drawCylinderX(1, GRIPPER_ARM_LEN);
    glTranslatef (GRIPPER_ARM_LEN/2, 0, 0);
    glRotatef(a + 90, 0, 1, 0);
    drawCylinderY(1, 2);
    glTranslatef(1, 0, 0);
    drawCylinderX(1, 2);
    glPopMatrix();
}