/*
 * Filename ........ vectors.c
 * Description ..... Some functions to calculate with vectors.
 * 
 * Student name .... Sander van Veen & Taddeus Kroes
 * Student email ... sandervv@gmail.com & taddeuskroes@hotmail.com
 * Collegekaart .... 6167969 & 6054129
 * Date ............ 09.10.2010
 */

#include "vectors.h"

point createPoint(GLdouble x, GLdouble y, GLdouble z)
{
	point p = {x, y, z};
	return p;
}

point normalizeVector(point p)
{
	return scalarMultiply(p, 1 / VECTOR_LENGTH(p));
}

point addVectors(point p1, point p2)
{
	return createPoint(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z);
}

point subtractVectors(point p1, point p2)
{
	return createPoint(p1.x - p2.x, p1.y - p2.y, p1.z - p2.z);
}

point scalarMultiply(point p, GLdouble scalar)
{
	return createPoint(p.x * scalar, p.y * scalar, p.z * scalar);
}

GLdouble dotProduct(point p1, point p2)
{
	return p1.x * p2.x + p1.y * p2.y + p1.z * p2.z;
}

point crossProduct(point p1, point p2)
{
	return createPoint( p1.y * p2.z - p1.z * p2.y,
	                    p1.z * p2.x - p1.x * p2.z,
	                    p1.x * p2.y - p1.y * p2.x );
}
