function ret = cosp2(r)
	% for polar coordinate sys
	%	r(1) = Rsin(theta)cos(phi)
	%	r(2) = Rsin(theta)sin(phi)
	%  r(3) = Rcos(theta)
	%
	% calculate cos(phi/2) from cartesian coordinate vector r
	%
	
	Rsint		= sqrt(r(1)^2 + r(2)^2);
	cosp		= r(1) / Rsint;
	sgn_sinp = sign(r(2));
	ret		= sgn_sinp * sqrt((1+cosp)/2);
end