/*
some vector functions for javascript selectable RASP maps.

Copyright (C) 2010 Thomas Pantzer

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 3 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, see http://www.gnu.org/licenses/.
*/


siteOptionErrorCheck();

function deg2rad(d)
{
	return (d*3.14159265358979323)/180.0;
}

var Ax = (m2x - m1x);
var Ay = (m2y - m1y);
var Bx = (m3x - m4x);
var By = (m3y - m4y);

if (debug) {
	alert("Ax:"+Ax+" Ay:"+Ay+" Bx:"+Bx+" By:"+By);
}

function Scalar2(x1,y1,x2,y2)
{
	return ((x1*x2)+(y1*y2));
}

function Scalar(x,y)
{
	return Scalar2(x,y, x,y);
}

function vLength(x,y)
{
	return Math.sqrt(Scalar(x,y));
}

var la = vLength(Ax,Ay);
var aNx = Ax/la;
var aNy = Ay/la;

var lb = vLength(Bx,By);
var bNx = Bx/lb;
var bNy = By/lb;

var Rx = (m1x-m4x) / (bNx - aNx);
var Ry = (m1y-m4y) / (bNy - aNy);

if (debug) {
//	alert("Rx:"+Rx+" Ry:"+Ry);
	alert("bNy:"+bNy+" aNy:"+aNy);
}


var lR = vLength(Rx,Ry);

function alpha(x1,y1, x2,y2)
{
 	return Math.acos( Scalar2(x1,y1, x2,y2) / vLength(x1,y1) / vLength(x2,y2) );
} 





