/* 
 * Thomas Pantzer: t_vector.cc, v0.1b  8.6.99 16:49 
 * 
 * 
 * Copyright 1999 by Thomas Pantzer
 * 
 * Permission to use, copy, modify, and distribute this software for noncommercial 
 * use and without fee is hereby granted, provided that the above copyright notice 
 * appear in all copies and that both that copyright notice and this permission 
 * notice appear in supporting documentation, and that the name of the Author not be 
 * used in advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission. The Author makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is" 
 * without expressed or implied warranty. 
 * 
 * 
 * pantec@isys2.informatik.uni-leipzig.de   (Thomas Pantzer) 
 * 
 */

#include "copyright.h"


#include "t_vector.h"
#include <math.h>
#include <stdio.h>

void t_vector::Init(t_vector &d)
{
	x = d.x;
	y = d.y;
}
	

void t_vector::Init(double nx,double ny)
{
	x = nx;
	y = ny;
}

void t_vector::Normalize(void)
{
	double d = Length();

	x /= d;
	y /= d;
}

void t_vector::Add(t_vector *v)
{
	x += v->x;
	y += v->y;
}

void t_vector::Sub(t_vector *v)
{
	x -= v->x;
	y -= v->y;
}

double t_vector::Scalar(t_vector *v)
{
	return (x * v->x) + (y * v->y);
}

double t_vector::Distance(t_vector *v)
{
	return sqrt(SQR(x - v->x) + SQR(y - v->y));
}

double t_vector::CosPhi(t_vector *v)
{
	return Scalar(v) / (Length() * v->Length());
}

double t_vector::Length(void)
{
	double d = sqrt(SQR(x) + SQR(y));
	if (d <= 0.0)
	   fprintf(stderr,"vector length == %g\n",d);

	return d;	
}

void t_vector::Mult(double d)
{
	x *= d;
	y *= d;
}

void t_vector::Rotate(double rho)
{
	double X = (x*cos(-rho)) + (y*sin(-rho));
	double Y = (-x*sin(-rho)) + (y*cos(-rho));
	x = X;
	y = Y;
}







/**/
/**/
/**/
/**/
/**/
/**/
/**/
/**/
/*****  End Of File  ****************************/
