//https://blog.nobel-joergensen.com/2010/10/22/spherical-coordinates-in-unity/ public static void SphericalToCartesian(Spherical3 sphereCoords, out Vector3 outCart) { float a = sphereCoords.r * Mathf.Cos(sphereCoords.e); outCart.x = a * Mathf.Cos(sphereCoords.p); outCart.y = sphereCoords.r * Mathf.Sin(sphereCoords.e); outCart.z = a * Mathf.Sin(sphereCoords.p); }
public void StartRecord() { mytrail.Clear(); startPos = transform.position; startSph = new Spherical3(); SphereUtility.CartesianToSpherical(startPos - origin.transform.position, out startSph); mytrail.Push(startSph); StartCoroutine("Recording"); }
public static Spherical3 Rotate(Spherical3 inS, float deltaRad) { Spherical3 m = new Spherical3(); m.r = inS.r; m.p = inS.p + deltaRad; m.e = inS.e; return(m); }
public static Spherical3 Mirror(Spherical3 inS) { Spherical3 m = new Spherical3(); m.r = inS.r; m.p = -inS.p; m.e = inS.e; return(m); }
// Update is called once per frame void Update() { Spherical3 sc = new Spherical3(); Vector3 where = toTrack.transform.position - origin.transform.position; SphereUtility.CartesianToSpherical(where, out sc); // reflecting sc.p *= -1; Vector3 nwhere = new Vector3(); SphereUtility.SphericalToCartesian(sc, out nwhere); transform.position = startPos + nwhere; }
public static void CartesianToSpherical(Vector3 cartCoords, out Spherical3 sphereCoords) { if (cartCoords.x == 0) { cartCoords.x = Mathf.Epsilon; } sphereCoords.r = Mathf.Sqrt((cartCoords.x * cartCoords.x) + (cartCoords.y * cartCoords.y) + (cartCoords.z * cartCoords.z)); sphereCoords.p = Mathf.Atan(cartCoords.z / cartCoords.x); if (cartCoords.x < 0) { sphereCoords.p += Mathf.PI; } sphereCoords.e = Mathf.Asin(cartCoords.y / sphereCoords.r); }
// Use this for initialization void Start() { mytrail = new Stack <Spherical3>(); sc = new Spherical3(); }