Working but nothing so far
This commit is contained in:
parent
6ed5b21890
commit
c0c129db88
5 changed files with 136 additions and 35 deletions
14
vec3.go
14
vec3.go
|
|
@ -92,8 +92,20 @@ func (v Vector3) Unpack() (float64, float64, float64) {
|
|||
return v.X, v.Y, v.Z
|
||||
}
|
||||
|
||||
// Others maths thingies
|
||||
// Return position, and units vectors of spherical into cartesian coords (r, theta, phi) units vecs
|
||||
func (v Vector3) SphericalToCartesian() (Vector3, Vector3, Vector3, Vector3) {
|
||||
p, theta, phi := v.Unpack()
|
||||
cos_theta, sin_theta := math.Cos(theta), math.Sin(theta)
|
||||
cos_phi, sin_phi := math.Cos(phi), math.Sin(phi)
|
||||
|
||||
cart_pos := Vector3{p * cos_theta * cos_phi, p * sin_theta * sin_phi, p * cos_theta}
|
||||
unit_vec_r := Vector3{sin_theta * cos_phi, sin_theta * cos_phi, cos_theta}
|
||||
unit_vec_theta := Vector3{cos_theta * cos_phi, cos_theta * sin_phi, -sin_theta}
|
||||
unit_vec_phi := Vector3{-sin_phi, cos_phi, 0}
|
||||
return cart_pos, unit_vec_r, unit_vec_theta, unit_vec_phi
|
||||
}
|
||||
|
||||
// Others maths thingies
|
||||
func Clamp(x float64, a float64, b float64) float64 {
|
||||
return min(max(x, a), b)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue