デカルト座標から角座標

  • 予定パッケージ名
    • SphereAndSimplex
  • 関数名
    • Cartesian2Angular
  • タイトル
Cartesian2Angular
  • 説明
デカルト座標を角座標に変換する
  • 使用例
Cartesian2Angular(c(0,1/sqrt(2),1/sqrt(2)))
  • ソース
	# xk=sin(vk)
	# xk-1=cos(vk)*sin(vk-1)
	# xk-2=cos(vk)*cos(vk-1)*sin(vk-2)
	# ...
	# x2=cos(vk)*cos(vk-1)*cos(vk-2)*...*sin(v1)
	# x1=cos(vk)*cos(vk-1)*cos(vk-2)*...*cos(v1)

# デカルト座標から角座標へ
Cartesian2Angular<-function(x){
	r<-sqrt(sum(x^2))
	xst<-x/r
	n<-length(xst)
	t<-rep(0,n-1)
	S<-C<-t
	S[n-1]<-xst[n]
	if(S[n-1]>1)S[n-1]<-1
	if(S[n-1]<(-1))S[n-1]<-(-1)
	t[n-1]<-asin(S[n-1])
	C[n-1]<-cos(t[n-1])
	cumC<-C[n-1]
	for(i in (n-2):1){
		if(cumC!=0){
			S[i]<-xst[i+1]/cumC
			if(S[i]>1)S[i]<-1
			if(S[i]<(-1))S[i]<-(-1)
			t[i]<-asin(S[i])
			C[i]<-cos(t[i])
			cumC<-cumC*C[i]
		}else{
			S[i]<-0
			t[i]<-asin(S[i])
			C[i]<-cos(t[i])
		}
		
	}
	list(r=r,t=t)
}
  • Rdファイル
\name{Cartesian2Angular}
\alias{Cartesian2Angular}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Cartesian2Angular
}
\description{
translate Cartesian coordinates to angular coordinate
デカルト座標から角座標へ
}
\usage{
Cartesian2Angular(c(1,2,3))
}
%- maybe also 'usage' for other objects documented here.
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
\item{r }{Norm of vector}
\item{t }{n-1 angles}
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
Angular2Cartesian
}
\examples{
x<-runif(4)
a<-Cartesian2Angular(x)
a$r
a$t
a[[1]]
a[[2]]
x2<-Angular2Cartesian(a$r,a$t)
x
a
x2
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line