Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Spherical Coordinates

JohnNichols
Valued Contributor III
6,719 Views

I was just looking at coding a transformation from XYZ to spherical.  I was looking at Wikipedia for the equations for more than 3 dimensions and the following note is on the site.  X3 has to be wrong?

Screenshot 2021-10-08 145652.jpg

0 Kudos
23 Replies
MWind2
New Contributor III
5,968 Views

n-sphere - Wikipedia

The last two n-1 and n equations are not consistent with x3. Why cos(phi3)?

0 Kudos
ClariceStarling
Valued Contributor II
5,963 Views

Where is Dr. Fortran and why is he not posting anything?

Hope he's on a nice vacation!

 

0 Kudos
JohnNichols
Valued Contributor III
5,903 Views

I think we have all noticed Dr Fortran's absence.   This is the problem with this world, people just disappear.  

In terms of the equations, yes they are wrong.  Interesting, I wonder who you tell? 

Anyway I am about to code them in Fortran, for all the libraries I would have thought by now I could find this transformation. 

JohnNichols
Valued Contributor III
5,891 Views

A few weeks ago we were discussing the ATAN2 function. There is a long talk on ATAN2 in wikipedia and it discusses the problems with using the function.  Quite interesting.  It is mentioned in the spherical coordinate transformation.  

 

0 Kudos
Steve_Lionel
Honored Contributor III
5,856 Views

@ClariceStarling wrote:

Where is Dr. Fortran and why is he not posting anything?

Hope he's on a nice vacation!

 


He was. But he has nothing to add here.

mecej4
Honored Contributor III
5,800 Views

MWind2 wrote: "The last two n-1 and n equations are not consistent with x3. Why cos(phi3)?"

I think that you missed the fact that there are n coordinates, of which one is a length (the radius), and the remaining n-1 coordinates are angles. The formulae for x_1 to x_(n-1) follow a regular pattern: x_i is equal to the product of r ,  (i-1) sines, and cos(phi_i).

This pattern does not apply to the last x, namely, x_n. The pattern would need  cos(phi_n), but we have only n-1 angles. What factor do we need to make the sum of the squares of all the x_i equal to the square of r? It is the sine of phi_(n-1). If you prefer, you may think of a fake angle, phi_n = π/2 - phi_(n-1).

[ COMPLAINT: The clumsy forum software available to us makes it a nuisance to type mathematical formulae and the results are ugly. No subscripts and superscripts, no Greek letters are available. And this in the year 2021, in a forum for a language for Formula Translation! ]

0 Kudos
Steve_Lionel
Honored Contributor III
5,746 Views

No Grεεκ letters? It's as easy as Π²!

mecej4
Honored Contributor III
5,744 Views

Thanks, but how? I know that it can be done using HTML codes;  how can that be done using the toolbar? Or do you create in some external software and copy/paste formulae here? Some web sites used to allow TeX for equations, but I have not used any recently.

0 Kudos
Steve_Lionel
Honored Contributor III
5,650 Views


@mecej4 wrote:

Thanks, but how? I know that it can be done using HTML codes;  how can that be done using the toolbar? Or do you create in some external software and copy/paste formulae here? Some web sites used to allow TeX for equations, but I have not used any recently.


I used Character Map in Windows, selected the characters I wanted and copy/paste. I am not sure if HTML would work - hmm, let's try...

πR², cake R round

Yes, it does work. Bit of a nuisance.

MWind2
New Contributor III
5,724 Views

I'm still trying understand how to use such for a dimension n. Would 

x1 = r*cos(phi1)                                   x1 calculation  imply minimum dimension is 2 if phi1!=0
x2 = r*sin(phi1)cos(phi2)                    x2 calculation  imply minimum dimension is 3 if phi2!=0
x3 = r*sin(phi1)*sin(phi2)*cos(phi3) x3 calculation imply minimum dimension is 4 if phi3!-0

For whatever n is substituted , the last expression in the series gives xn :

for n=3, x1 = r*cos(phi1), x2 = r*sin(phi1)cos(phi2), and x(n=3) = x(n=2)*sin(phi(n=3-1=2))?

If this is what is meant, then I would have to agree the expressions are correct. 

0 Kudos
mecej4
Honored Contributor III
5,689 Views

Let us fix n, the dimension of the space. Then, for i = 1 to (n-1), use the formula

 

     x_i = r . product[ sin (phi_j), j = 1, ..., (i-1)] . cos (phi_i)

 

This gives you x_1, x_2, ..., x_{n-1}. Note that each expression has only one cosine.

 

The last (i.e., n-th) equation has no cos(); thus, you have r times a product of all sines.

 

     x_n = r . product[ sin (phi_j), j = 1, ..., (n-1)] 

---------------

I do not understand what you mean by "minimum dimension". In your last equation, you wrote n=3 in one term and n = 2 in another. That is wrong.

0 Kudos
JohnNichols
Valued Contributor III
5,643 Views

@mecej4 ,

I do not disagree with your thoughts, they are perfectly clear. 

My fundamental concern is much deeper in Pure Math. 

The fundamental assumption of N dimensional space.   It is an artificial limit and makes the presentation -- bodgy. 

If we have N .. 1,2,3,4, then N can take any value up to natural infinity.   Therefore N + 1 must belong to this set.  So the fundamental assumption of N is one of engineering use and not Pure Math in this article.   If is intended as engineering make the presentation useful for the average user, show the solution for the 3D equations commonly used in engineering, if the presentation is pure math then deal with N+1. 

If N+1 exists then we can theoretically view N dimensional space in N+1 dimensional space by setting on the defining vector values to 0.   The natural number line exists, if  theta(1) to theta(infinity) are assumed zero. 

Hence theta(n+1) can be defined as zero, we can always do a linear transformation.  Cos(0) is 1, so the Nth equation in the set shown in Wikipedia emerges, it emerges because we made the assumption of N, which is a problem, as if N can take any value to infinity, then n+1 must exist.  

So if I say N = 3, then X3 does not take the value of the equation shown, it must take the last equation with the implicit assumption that  cos(theta3) = 1, from the artificial limit on N. 

Some poor high school student has now got to understand that X3 only exists as the third equation if N > 3, but if N is exactly 3, then equation 3 is exactly equal to the last equation as cos(theta3) is 1. 

I know what they are attempting to do, but personally I think you could develop a simpler algorithm - that showed the exact solutions without the bodginess of ignoring N+1.  (Clearly their equation X3 as shown immediately implies N+1, by induction )

Summary, X3 only exists as shown in N > 3.  If N = 3 than X3 is replaced with the last equation.  

Poor presentation for a high school student who may not pick up the nuance of the 4th dimension assumption and try and find theta3.

 

 

 

0 Kudos
MWind2
New Contributor III
5,625 Views

The series is a list of what the xN  calculation is, followed by the general case n-1 an n. I don't care about n= 36 if I want n=3.

The listed expansion for x3 contains phi3. I was trying to make sense of this without a decent drawing. I concluded, perhaps wrongly, that it could not refer to the angle phi(i) makes with the x(i) axis.

"We may define a coordinate system in an n-dimensional Euclidean space which is analogous to the spherical coordinate system defined for 3-dimensional Euclidean space, in which the coordinates consist of a radial coordinate r, and n − 1 angular coordinates φ1, φ2, ... φn−1, where the angles φ1, φ2, ... φn−2 range over [0,π] radians (or over [0,180] degrees) and φn−1 ranges over [0,2π) radians (or over [0,360) degrees). If xi are the Cartesian coordinates, then we may compute x1, ... xn from r, φ1, ... φn−1 with:[2]...

 

I conclude there should be no cos(phi3) in x3 of a 3-dimension, such must be the third coordinate of a four dimensional system. the x4 in such is all sin's of phi(i) i=1,2,3.

x1 = r*cos(phi1)                                   x1 calculation  imply minimum dimension is 2 if phi1!=0

if cos(phi1) =1 then x1 =r and dimension could be 1, and if not, not necessarily 2.

if cos(phi2)=1 then x2 =r*sin(phi2) and the dimension could be 2, not necessarily 3

I am in no way convinced I am "wrong"

 

 

 

0 Kudos
JohnNichols
Valued Contributor III
5,684 Views

A 4D linear mapping will work on a 3D if we only map one of the 16 four dimension quadrants onto one the eight 3 dimensional quadrants, which implies I think , not being about to really visualize, it but it suggests some of the 4D values have to be perfectly zero.  

 

 

0 Kudos
andrew_4619
Honored Contributor III
5,864 Views

"In terms of the equations, yes they are wrong.  Interesting, I wonder who you tell? ",  John it is on wiki if you know the correction you just edit the page and quote any references used . If you are not confident edit the page and add a note that you believe it to be wrong and state a reason. In my experience Wiki pages can stay dormant for years but as soon as a change is made a whole host of people jump on the change and modify/correct/improve  it. I have been quite surprised at the level and quality of 'peer review' and 'moderation'  that goes on in the past.

0 Kudos
mecej4
Honored Contributor III
5,847 Views

JohnNichols said, "X3 has to be wrong?"

Looks fine to me. If you think it is wrong, give an authoritative reference or a well-reasoned argument. 

Note that there can be differences in the transformation formulae (cartesian to spherical) depending on how the angles are defined. In 3D-space, for example, one may use either the latitude or its complement, the co-latitude. In n-dimensional space, n-2 angles may be chosen to be between (-π/2, π/2) or (0, π), and the (n-1)th angle  may range over (0, 2π)) or (-π, π). These angles may be numbered from 1 to n-1, or n-1 down to 1, and they may be represented by different symbols. Since most people use only 2-D or 3-D space, there is almost no variation in the conventions there, but the same is not true in higher dimensional spaces.

The Wikipedia article that you quote and the following references agree, but they use different conventions for the angles: 

 

https://sites.math.washington.edu/~morrow/335_16/sphericalCoords.pdf 

 

Wolfram Mathworld 

0 Kudos
JohnNichols
Valued Contributor III
5,694 Views

My standard reference is Kaplan and Lewis "Calculus and Linear Algebra" 1971.  

Section 11-20 Spherical and Cylindrical Coordinates: page 865

Figure 11-37 Spherical coordinates.  page 866

Equation 11-202 - page 866.

X1 in Wikipedia is the standard Z in engineering and applied math.

The z = x1 = radius*cos(beta).   

X = X2 = radius *sin(beta)*cos(theta) 

Y = X3 = radius *sin(beta)*sin(theta) for 3 dimensions, which matches the pattern on the equation X(n), from equation 11-202

but equation 3 has 

Y = X3 = radius*sin(beta)*sin(theta)*sin(alpha).   This equation represents a 4 dimension linear mapping and we want 3 dimensions.  

Wikipedia 3D has three angles, the others are correct, but as most people looking at this would be high school students and maybe University students and that 3D is the most commonly needed translation as 2d is trivial , one would expect it to be correct. 

As my Pure Math Professor said, mark till it is incorrect and stop.  As I noted above, X3 has to be wrong, and unless Kaplan and Lewis is wrong and this is one of the standard textbooks from 1950's to the 1990's, I would be surprised if they are incorrect.  

The other equations are correct.  I did not say they were wrong.  I would say it is a typing error, easy to do when setting equations.  

 

0 Kudos
JohnNichols
Valued Contributor III
5,692 Views

I would guess, the original person who edited did up to X4, and then someone did a bad edit thinking we do not need more than 3 and in say Tex that is really easy to do. 

 

 

0 Kudos
JohnNichols
Valued Contributor III
5,690 Views

In n-dimensional space, n-2 angles may be chosen to be between (-π/2, π/2) or (0, π), and the (n-1)th angle  may range over (0, 2π)) or (-π, π).

 

X3 equation does not match your pattern it has N dimensional space and has N angles. 

0 Kudos
mecej4
Honored Contributor III
5,654 Views

Please read my responses to MWind2. 

The equations in the n-sphere article should not be used verbatim for spaces of dimension less than 4. There is one pattern for x_1, ..., x_(n-1): each contains exactly one cosine on the right hand side. The equation for x_n is different; it has no cosine. 

0 Kudos
Reply