--Vector3
function InitVector3(X, Y, Z)
return {x = X or 0,y = Y or 0, z = Z or 0}
end

--Dot Product, TESTED
function Dot(vector1, vector2)
      if type(vector1.x) ~= "number" then
        error("bad param: vector1.x")
      elseif type(vector1.y) ~= "number" then
        error("bad param: vector1.y")
      elseif type(vector1.z) ~= "number" then
        error("bad param: vector1.z")
	  end
	  
     if type(vector2.x) ~= "number" then
        error("bad param: vector2.x")
      elseif type(vector2.y) ~= "number" then
        error("bad param: vector2.y")
      elseif type(vector2.z) ~= "number" then
        error("bad param: vector2.z")
	  end
	   
	return vector1.x*vector2.x + vector1.y*vector2.y + vector1.z*vector2.z
end

--Magnitude, TESTED
	function Magnitude(vector1)
	return math.sqrt(Dot(vector1, vector1))
end

function Normalize(vector1)
	local mag = Magnitude(vector1)
	return {vector1.x/mag, vector1.y/mag, vector1.z/mag}
end

function DisplayVector(vector1)
	io.write(vector1.x, ' ', vector1.y, ' ', vector1.z)
end


--Matrix4
function MI(mat1)
	for i=1,4 do
	  mat1[i] = {}
	  for j=1,4 do
		if( i == j) then
			mat1[i][j] = 1
		else
			mat1[i][j] = 0
		end
	  end
	end
end

function MakeIdentity()
	local mat = {}
	for i=1,4 do
	  mat[i] = {}
	  for j=1,4 do
		if( i == j) then
			mat[i][j] = 1
		else
			mat[i][j] = 0
		end
	  end
	end
	return mat
end

--[[
function DisplayMatrix(mat1)
	io.write("Matrix:\n")
	for i=1,4 do
	  if(i ~= 1) then
	    io.write('\n')
	    end
	  for j=1,4 do
	  ret1, ret2 = math.modf(mat1[i][j])
		if(math.abs(ret2) > 0.5) then
			io.write(' ', math.ceil(mat1[i][j]))
		else
			io.write(' ', math.floor(mat1[i][j]))
		end
	  end
	end
end
]]--

function DisplayMatrix(mat1)
	io.write("Matrix:\n")
	for i=1,4 do
	  if(i ~= 1) then
	    io.write('\n')
	    end
	  for j=1,4 do
	  ret1, ret2 = math.modf(mat1[i][j])
			io.write(' ', (mat1[i][j]))
	  end
	end
end

