/*
 *  COLA -- a satellite close-approach finder
 *  Copyright (C) 1996 Matthew Francey
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Functions yrot and zrot were added by Tom Rothamel to support
 *  Satellite Tracking Suite. (Those two functions are based on
 *  the functions of the same names in seesat5.)
 */
#include <math.h>
#include "vector.h"

double	*
cross(double *x, double *y)
{
static	double	r[3];
	double	x0 = x[0], x1 = x[1], x2 = x[2];
	double	y0 = y[0], y1 = y[1], y2 = y[2];

	r[0] = x1*y2 - x2*y1;
	r[1] = x2*y0 - x0*y2;
	r[2] = x0*y1 - x1*y0;
	return &r[0];
}

double
dot(double *x, double *y)
{
	return x[0]*y[0] + x[1]*y[1] + x[2]*y[2];
}

double
len(double *x)
{
 	return sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
}

double	*
norm(double *x)
{
	double	l;

	if((l = len(x)) > 0.0) {
		l     = 1.0/l;
		x[0] *= l;
		x[1] *= l;
		x[2] *= l;
	}
	return x;
}

double *
copy(double *d, double *s)
{
	*d++ = *s++;
	*d++ = *s++;
	*d++ = *s++;
	return d - 3;
}


void yrot(double *x, double sint, double cost) {
        double tempz;

        tempz = x[0] * sint + x[2] * cost;
        x[0] = x[0] * cost - x[2] * sint;
        x[2] = tempz;
}

void zrot(double *x, double sint, double cost) {
        double tempx;

        tempx = x[0] * sint + x[1] * cost;
        x[0] = x[0] * cost - x[1] * sint;
        x[1] = tempx;
}
