0

There's already a question and it has an answer here, however it doesn't work the way I expect it.

# Assume my radius is 1 for simplicity

x = cos(s) * sin(t)
y = sin(s) * sin(t)
z = cos(t)

When t=0, regardless of my s,

(x,y,z)=(0,0,1)  

# Since sin 0 = 0 on x 
# and y and z is independent of s

So here's how my world is

enter image description here

But actually when s increases, the point on the sphere varies, doesn't remain at (0,0,1). For eg. if my s=(-45)deg and t=0, point on sphere should be (0,0.707,0.707) right?

UPDATE: Here's what I need:

(s,t)   |  (x,y,z)
---------------
(0,0)   |  (0,0,1)
(45,0)  |  (.707,0,0.707)
(90,0)  |  (1,0,0)
(180,0) |  (0,0,-1)
(270,0) |  (-1,0,0)
(0,-45) | (0,0.707,0.707)
(0,45)  | (0,-0.707,0.707)

But I don't get those results from the above equations...! What do I do?

Community
  • 1
  • 1
Saravanabalagi Ramachandran
  • 8,551
  • 11
  • 53
  • 102

1 Answers1

3

with your formula t=0 means that you are at pole so the radius is zero. No matter what s is the output should be always (x,y,z)=(0,0,1). If you need the standard spherical coordinates instead use this:

x = cos(s) * cos(t)
y = sin(s) * cos(t)
z =          sin(t)

s = <0,360> [deg]
t = <-90,+90> [deg]

for (s=45deg,t=0deg) it should return (x,y,z)=(0.707,0.707,0.000)

PS. I am not sure why you have mixed coordinates y,z instead of x,y in OP.

[Edit1]

To match your image reference frame try to use these:

x = sin(s) * cos(t)
y =        - sin(t)
z = cos(s) * cos(t)

s = <0,360> [deg]
t = <-90,+90> [deg]
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • the equations I wrote on the question are directly from this [answer](http://stackoverflow.com/a/969880/3125070) and they didn't work for me, hence this question. So is that answer flawed? – Saravanabalagi Ramachandran May 03 '17 at 07:16
  • @ZekeDran no they just use different reference frame for `t` the angle starts at poles not at equator ... so there `t=<0,180> [deg]` ... – Spektre May 03 '17 at 07:18
  • ah, I get that now, thanks for the explanation... When looking from front (Front View), my x-axis runs to my right horizontally, y-axis runs vertically, and z-axis measures the depth. That way, when I have angles (0,0), the point on sphere in my line of sight will be (x,y,z) = (0,0,1), and so when I look 45 deg above, angles are (45,0) and the point on sphere should be (0,0.707,0.707) – Saravanabalagi Ramachandran May 03 '17 at 07:21
  • It's pretty much like the browser screen is mapped to x,y axes as usual, while the 3rd dimension is z-axis marking the depth or elevation of each element on the screen. Its `z-index` in css. – Saravanabalagi Ramachandran May 03 '17 at 07:24
  • I updated my question so its much clearer :) and here's a [fiddle](https://dotnetfiddle.net/YAL6AL) I get two 1s for (s,t)=(0,0) – Saravanabalagi Ramachandran May 03 '17 at 08:08
  • @ZekeDran I converted the equation to your image reference frame see edit1 and let me know if it is what you need... – Spektre May 03 '17 at 08:53
  • Flawless...! I wish to know how this is done, I can just work the trigonometry out for 2D, and this involves multiplication of sines and cosines and i get lost imagining that. If its not short, would be glad if you add a link that would point me in the right direction :) – Saravanabalagi Ramachandran May 03 '17 at 09:11
  • 1
    @ZekeDran I just substitute axises of my reference frame with yours `my(x,y,z)=your(z,x,-y)` ... `x` axis is where booth angles are zero ... and `z` axis is polar singularity where `t=+/-90` and `y` is rotated `x` by `90deg` in `s` direction – Spektre May 03 '17 at 09:35