using UnityEngine;
public static class Converter
{
public static Vector3 CartesianToSpherical(Vector3 cartesianCoordinates)
{
float x = cartesianCoordinates.x;
float y = cartesianCoordinates.y;
float z = cartesianCoordinates.z;
float r = Mathf.Sqrt(x * x + y * y + z * z);
float theta = Mathf.Asin(y / r);
float phi = Mathf.Atan2(z, x);
return new Vector3(r, theta, phi < 0 ? Mathf.PI * 2 - Mathf.Abs(phi) : phi);
}
public static Vector3 SphericalToCartesian(Vector3 sphericalCoordinates)
{
float r = sphericalCoordinates.x;
float theta = sphericalCoordinates.y;
float phi = sphericalCoordinates.z;
float x = r * Mathf.Cos(theta) * Mathf.Cos(phi);
float z = r * Mathf.Cos(theta) * Mathf.Sin(phi);
float y = r * Mathf.Sin(theta);
return new Vector3(x, y, z);
}
}
if (Input.GetMouseButtonDown(0))
{
Ray ray = this.GetComponent<UnityEngine.Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit info;
Physics.Raycast(ray,out info);
var sc = Converter.CartesianToSpherical(info.point);
var cc = Converter.SphericalToCartesian(sc);
// Debug.Log("Декартовы координаты точки: " + info.point);
Debug.Log("Сферические координаты точки: " + sc.y * Mathf.Rad2Deg + " " + sc.z * Mathf.Rad2Deg);
// Debug.Log("Декартовы координаты точки: " + cc);
Instantiate(Point,cc,Quaternion.identity);
}
public static float degAsin(float z, float r)
{
float f = Mathf.Rad2Deg * Mathf.Asin(z, r);
return f;
}
public IActionResult Img(string name)
{
var image = System.IO.File.OpenRead(@"D:\SiteCore\SiteCore\Content\img\blend_s\"+ name);
return File(image, "image/jpeg");
}
template: "{controller}/{action}/{name?}");