(35S) Spherical coordinates <-> rectangular - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (35S) Spherical coordinates <-> rectangular (/thread-8300.html) |
(35S) Spherical coordinates <-> rectangular - stephane - 05-05-2017 05:51 PM Find below two programs to convert from/to rectangular coordinates to/from spherical coordinates. The variables of the calculator are preserved. Only the stack is used. Two programs are provided: - rect2sph: XEQ S - sph2rect: XEQ R Cartesian coordinates are in the form (x, y, z) Spherical coordinates are in the form (r, theta, phi), where r is the radius/distance, theta is the azimuth, and phi is the elevation. Formula used are: x = r.cos(theta).cos(phi) y = r.sin(theta).cos(phi) z = r.sin(phi) r = sqrt(x²+y²+z²) theta = atan2(y, x) phi = atan2(z, sqrt(x²+y²)) Usage for rect2sph: Stack before: Z: x Y: y X: z Exec program: XEQ S Stack after: T: [x, y, z] Z: r Y: theta X: phi Usage for sph2rect: Stack before: Z: r Y: theta X: phi Exec program: XEQ R Stack after: T: [r, theta, phi] Z: x Y: y X: z Code for rect2sph: Code:
Code for sph2rect: Code:
RE: (35s) Spherical coordinates <-> rectangular - PedroLeiva - 05-05-2017 06:12 PM (05-05-2017 05:51 PM)stephane Wrote: Find below two programs to convert from/to rectangular coordinates to/from spherical coordinates.Well, finally something to try on my HP 35s. Could you put a numerical example, and perhaps a graphic illustration, to check that everything works well? Thank you in advance, Pedro RE: (35s) Spherical coordinates <-> rectangular - stephane - 05-05-2017 06:34 PM To check that everything works well: First, put your calculator in DEG mode, because the result depends on DEG or RAD. Example for rect2sph(10, 20, 30): Code:
should give the following values in the stack: T: [10,20,30] Z: 37.4166 (meters of distance) Y: 63.4349 (degrees of azimuth) X: 53.3008 (degrees of elevation) Example for sph2rect(5, 30°, 45°): Code:
should give the following values in the stack: T: [5,30,45] Z: 3.0619 (x value in meters) Y: 1.7678 (y value in meters) X: 3.5355 (z value in meters) Then, pressing XEQ S ENTER gives you again the initial spherical coordinates. RE: (35s) Spherical coordinates <-> rectangular - PedroLeiva - 05-05-2017 10:13 PM Thank you stepahne, Pedro |