0

I have this formula to rotate around a sphere

double naX = o.Node.Angle.X;
double naY = o.Node.Angle.Y;

double x = o.DrawingPosition.X - 4.0 * Math.Cos(naX) * Math.Sin(naY);
double y = o.DrawingPosition.Y - 4.0 * Math.Sin(naX) * Math.Sin(naY);
double z = o.DrawingPosition.Z - 4.0 * Math.Cos(naY);

Where 4.0 is the radius to follow and o.DrawingPosition is the center

I want it to rotate along the transform x axis (I have a quaternion and a unit vector normalized for calculated for the Z -1 normal) but if I add offsets the angles won't match

naX += _rotationTicks;
naY += _rotationTicks;

For example, it will follow a infinite shaped trajectory, how can I calculate the correct rotation so it behaves like a perfect circle?

Edit: I found this answer on Rotating body from spherical coordinates

But the main core difference is that both the XY rotation angles and the origins are arbitrary values, there is a forward vector calculated with a quaternion to determine facing like this:

var quat = System.Numerics.Quaternion.CreateFromYawPitchRoll((float)o.Node.Angle.X, (float)o.Node.Angle.Y, 0);


var dirVec = new Vector3(0, -1, 0).ToNumerics();

var downwards = quat.Multiply(dirVec); // it can be backwards, left, right, etc, changing the unit vector from dirVec

Thanks in advance.

Victor Lopez
  • 110
  • 1
  • 9
  • A position on a circle is sqrt(x^2 + y^2 + z^2). So if you want to rotate around x axis make x = zero. – jdweng Oct 03 '20 at 01:42
  • what's your email? I wanna message you about this... https://stackoverflow.com/questions/41961339/click-a-button-programmatically-c-sharp – YellowBlueBuzz Oct 03 '20 at 02:38
  • I know that we can use newX = oldX + r * Math.Cos(theta) * speed; newY = oldY + r * Math.Sin(theta) * speed; For any give circle and rotate around the origin, but I'm not sure what could be both values of theta in x and theta in y since this is a sphere – Victor Lopez Oct 03 '20 at 02:48

0 Answers0