How would I "rotate" x, y coordinate?

Ok so I have a position stored in a double x and y, and I want to rotate it by A.

   double x; // coordinates
   double y;
   double A; // The rotation I want to apply to x,y in radians

Here I have a visual representation of what I want to do:
2873029--210604--upload_2016-12-3_18-34-51.png

Btw I know I could rotate it if I used vector3 and quaternion, but I really need the precision of doubles

What you’re looking for is the RotateAround method. You may want to add some more logic, as this will rotate forever.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
    }
}
1 Like

I need to rotate doubles, not floats. Floats simply aren’t precise enough for what I need.

My math is quite rusty, but I think you can do something like this:

var cos = Math.Cos(angle);
var sin = Math.Sin(angle);
var rotatedX = x * cos - y * sin;
var rotatedY = x * sin + y * cos;

Note that you need to use System.Math.Cos, not UnityEngine.Mathf.Cos, since the former is using doubles and the latter is using floats. Also, mind the unit of angular measure, radian vs degree. Check the documentation.

Again, not sure if the math is right, but I think so and you’ll find out rather fast I’m sure.

Thanks!