0

So im trying to get a point on a sphere via an angle.

double X = Math.Cos(pitch * (Math.PI / 180));
double Y = Math.Sin(pitch * (Math.PI / 180)) * Math.Sin(yaw * (Math.PI / 180));
double Z = Math.Sin(pitch * (Math.PI / 180)) * Math.Cos(yaw * (Math.PI / 180));

I've tried this, but the point it outputs seems to be clamped to the XZ axis, and increasing/decreasing the yaw doesn't do anything to the point it spits out.

I cant figure out whats wrong with this code? Could someone help me identify the problem?

1Blue
  • 1
  • Almost seems like more of a math problem than a programming problem. But make sure that you aren't performing floating point arithmetic on integers, e.g. use `180D` instead of just `180`. – John Wu Sep 19 '18 at 23:47
  • 1
    Your example code here in the question looks like a normal bog-standard polar-to-cartesian conversion. You say that _yaw_ doesn't seem to work. Have you checked in the debugger what the value of the _yaw_ variable is when these calculations are being executed? –  Sep 19 '18 at 23:50
  • @elgonzo The yaw seems to be normal once it goes into the expression, seems exactly what i set it. – 1Blue Sep 20 '18 at 01:35
  • @JohnWu I just didn't want people to get confused with the C# code. – 1Blue Sep 20 '18 at 01:36
  • check this one out https://stackoverflow.com/a/969880/361899 – aybe Sep 20 '18 at 03:38
  • hope `pitch = <-90,+90>` and `yaw = <0,360>` – Spektre Sep 20 '18 at 07:40

0 Answers0