# Coordenates Convert
coord_convert = function(..., to = c("radian", "decimal", "dms", "polar", "cartesian"),
rad = FALSE, num = TRUE)
{
if(...length() == 0) return(NULL)
switch(match.arg(to),
##---------------------------------------------------------
## RADIANOS - RAD .:. RADIAN - RAD
##---------------------------------------------------------
radian = {
coord = ..1
out = radian(coord, num = num, rad = rad)
}, #end radian
##---------------------------------------------------------
## GRAUS DECIMAIS - GD .:. DECIMAL DEGREE - DD
##---------------------------------------------------------
decimal = {
coord = ..1
out = decimal(coord, num = num, rad = rad)
}, #end decimal
##---------------------------------------------------------------
## GRAUS MINUTOS SEGUNDOS - GMS .:. DEGREE MINUTES SECONDS - DMS
##---------------------------------------------------------------
dms = {
coord = ..1
out = toDMS(coord, num = num, rad= rad)
}, #end dms
##---------------------------------------------------------------
## POLAR to CARTESIAN
##---------------------------------------------------------------
cartesian = {
if(...length() < 2) erro("e1")
rho = ..1
theta = ..2
if(...length() == 3) center = ..3 else center = c(0, 0)
out = toCART(rho, theta, center = center, rad = rad)
}, #end cartesian
##---------------------------------------------------------------
## CARTESIAN to POLAR
##---------------------------------------------------------------
polar = {
if(...length() < 2)
stop("A entrada deve conter 2 argumentos:\n x e y", call. = FALSE)
x = ..1
y = ..2
out = cart2polar(x, y, rad = rad)
} #end polar
)#end switch
return(out)
}#end coord_convert
toDMS = function(coord, rad = FALSE, num = TRUE)
{
if(rad) out = dec2dms(coord * (180/pi), num = num)
else out = dec2dms(coord, num = num)
return(out)
}#end toDMS
toCART = function(rho, theta, center = c(0,0), rad = TRUE)
{
theta = decimal(coord = theta, rad = rad)
## convert to cartesian coordinates
out = polar2cart(rho, theta, center, rad = FALSE)
return(out)
}
erro = function(err)
{
switch(err,
e1 = {
message("\n arg1 = distancia\n arg2 = angulo\n", appendLF = T)
stop("A entrada deve conter pelo menos 2 argumentos\n", call. = FALSE)
},#end e1
)#end switch
}#end erro
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.