/*
Orion's Standard Library
Orion Sky Lawlor, 11/3/1999
NAME:		vector3d.cpp

DESCRIPTION:	C++ 3-Dimentional vector library (no templates)

This file provides various utility routines for easily
manipulating 3-D vectors-- included are arithmetic,
dot/cross product, magnitude and normalization terms. 
Almost all routines are provided right in the header file (for inlining).

*/
#include "vector3d.h"
using namespace osl;

/****************** vector2d ****************/
//Polar coordinate constructor
vector3d::vector3d(const polar3d &p)
{
	x=p.r*cos(p.phi)*cos(p.theta);
	y=p.r*cos(p.phi)*sin(p.theta);
	z=p.r*sin(p.phi);
}

//Return the polar coordinates of this vector
polar3d::polar3d(const vector3d &v)
{
	theta=atan2(v.y,v.x);
	r=v.mag();
	phi=asin(v.z/r);
}


//Return the right-handed cross product of this vector and b
vector3d vector3d::cross(const vector3d &b) const
{
	return vector3d(y*b.z-z*b.y,z*b.x-x*b.z,x*b.y-y*b.x);
}

//Return the largest coordinate in this vector
real vector3d::max(void)
{
	real big=x;
	if (big<y) big=y;
	if (big<z) big=z;
	return big;
}

//Make each of this vector's coordinates at least as big
// as the given vector's coordinates.
void vector3d::enlarge(const vector3d &by)
{
	if (x<by.x) x=by.x;
	if (y<by.y) y=by.y;
	if (z<by.z) z=by.z;	
}

