51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public struct Double3 {
|
|
public double X;
|
|
public double Y;
|
|
public double Z;
|
|
|
|
public static Double3 operator *(Double3 v, double r) {
|
|
return new Double3 { X = v.X * r, Y = v.Y * r, Z = v.Z * r };
|
|
}
|
|
|
|
public Vector3 ToVector3() {
|
|
return new Vector3((float)X, (float)Y, (float)Z);
|
|
}
|
|
|
|
public double Length() {
|
|
return Math.Sqrt(X * X + Y * Y + Z * Z);
|
|
}
|
|
public void Normalize() {
|
|
var len = Length();
|
|
X /= len;
|
|
Y /= len;
|
|
Z /= len;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public struct SphericalDir {
|
|
public double Theta;
|
|
public double Phi;
|
|
|
|
public Double3 ToCartesian() {
|
|
return new Double3 { X = Math.Sin(Theta) * Math.Cos(Phi), Y = Math.Sin(Theta) * Math.Sin(Phi), Z = Math.Cos(Theta) };
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public struct SphericalCoord {
|
|
public double R;
|
|
public SphericalDir Dir;
|
|
|
|
public Double3 ToCartesian() {
|
|
return Dir.ToCartesian() * R;
|
|
}
|
|
}
|
|
|