I am trying to understand the following code in this answeranswer regarding Möbius transformation:
(* Projection from the sphere to the plane *)
stereo = Compile[{{xyz, _Real, 1}, {XYZ, _Real, 1}}, Module[{
r = Sqrt[(xyz[[1]] - XYZ[[1]])^2 + (xyz[[2]] - XYZ[[2]])^2],
theta = ArcTan[(xyz[[1]] - XYZ[[1]]), (xyz[[2]] - XYZ[[2]])]},
{(r (1 + xyz[[3]]))/(1 - XYZ[[3]] + xyz[[3]]) Cos[theta + Pi] + xyz[[1]],
(r (1 + xyz[[3]]))/(1 - XYZ[[3]] + xyz[[3]]) Sin[theta + Pi] + xyz[[2]], 0}]];
I have read the documents for the functions Compile
and Module
, but still cannot figure out how the code works.
Could anyone elaborate the following?
What does
{xyz,_Real,1}
do and what doesxyz[[1]]
mean?[Added:] In the document for
Compile
, it is said thatCompile[{{x1,t1,n1},…},expr]
assumes thatxi
is a rankni
array of objects, each of a type that matchesti
.
But what is 1
in {xyz,_Real,1}
? If it means rank 1, then why later it is written that xyz[[1]]
, xyz[[2]]
, xyz[[3]]
, which suggests that xyz
is an array?
- How do
Compile
andModule
work together to give the definition of a function? - What is the formula for the function that this code is really defining? What is the input and what it is the output?