behavior of sph2cart() doesn't match matlab (?)
Ben Abbott
bpabbott at mac.com
Fri Jan 16 10:09:01 CST 2009
On Friday, January 16, 2009, at 10:35AM, "michael tesch" <tesch1 at gmail.com> wrote:
>
>On Fri, Jan 16, 2009 at 6:35 AM, Ben Abbott <bpabbott at mac.com> wrote:
>>
>> On Jan 15, 2009, at 8:57 PM, michael tesch wrote:
>>
>>> GNU Octave, version 3.0.2, on macosx, from 'port'.
>>>
>>> I can't actually verify this on the matlab side, but I got code that
>>> was developed in matlab that did the following:
>>>
>>> for nsp=1:sz
>>> [TH,PHI]=cart2sph(xx,yy,zz);
>>> [X,Y,Z]=sph2cart(TH,PHI,A);
>>> spoke=[X ;Y ;Z];
>>> end
>>>
>>> Where xx,yy,zz,TH,PHI were all scalars, and A was a 1xN vector. The
>>> result was that spoke was a matrix of 3xN.
>>>
>>> the Octave implementation of sph2cart() dies with an error about
>>> mismatched dimensions of parameters.
>>
>>>
>>
>> I'm unable to reproduce any problem in the developers sources.
>>
>> Nothing depends upon "nsp", so why the loop?
>>
>> TH, PHI should each have same size as xx, yy, & zz. Are you sure A has the
>> same size?
>>
>> To make certain everything is sized/shaped correctly, try inserting the line
>> below after cart2sph
>>
>> whos xx yy zz TH PHI
>>
>> Ben
>>
>
>thanks for your answer.
>
>sorry, i should have removed the loop from the example snippet.
>the point is that the code works in matlab, but doesn't work in octave,
>because matlab's sph2cart() (apparently) accepts when TH and PHI
>are scalars and A is a vector, whereas octave's sph2cart() bombs out.
>
>xx,yy,zz,TH,PHI are all scalars. A is a vector (of points along a line)
>and spoke should be the cartesian coordinates of the points along that line.
>
>i have a workaround, but read that differences between octave and
>matlab were considered bugs.
>
>mt
>
Ok, I understand and have confirmed the problem. Also, Matlab's documentation confirms their behavior is intended.
CART2SPH Transform Cartesian to spherical coordinates.
[TH,PHI,R] = CART2SPH(X,Y,Z) transforms corresponding elements of
data stored in Cartesian coordinates X,Y,Z to spherical
coordinates (azimuth TH, elevation PHI, and radius R). The arrays
X,Y, and Z must be the same size (or any of them can be scalar).
TH and PHI are returned in radians.
TH is the counterclockwise angle in the xy plane measured from the
positive x axis. PHI is the elevation angle from the xy plane.
I don't have time to look at the details at the moment. There are related functions that will need to be modified as well. I'll try to get to this tonight or over the weekend.
Ben
More information about the Bug-octave
mailing list