R/cart2polar.R

# Coordenate Cartesian to Polar
cart2polar = function(x, y, rad = TRUE)
{
	toRad = pi/180
	
	x = x #* toRad
	y = y #* toRad
	
	r = sqrt(x^2 + y^2) #/ toRad
	
	if(rad)	theta = (atan2(y, x) + (2*pi)) %% (2*pi)
	else theta = (atan2(y, x) / toRad + 360) %% 360
	
	out = data.frame("rho" = r, "theta" = theta)
	
	return(out)
}#end cart2polar
salah31416/toolbox documentation built on June 3, 2019, 6:59 p.m.