WhiteBoxMath.py 966 B

1234567891011121314151617181920212223242526272829303132
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. # setup path
  7. import azlmbr.object
  8. import azlmbr.math as math
  9. # returns a Vector3 of cartesian coordinates from spherical coordinates
  10. # phi and theta are in degrees
  11. def spherical_to_cartesian(phi, theta, dist=1.0):
  12. phi = math.Math_DegToRad(phi)
  13. theta = math.Math_DegToRad(theta)
  14. x = float(dist) * float(math.Math_Sin(phi)) * float(math.Math_Cos(theta))
  15. y = float(dist) * float(math.Math_Sin(phi)) * float(math.Math_Sin(theta))
  16. z = float(dist) * float(math.Math_Cos(phi))
  17. return math.Vector3(x, y, z)
  18. # converts two Cartesian points into their midpoint, normalized into a vector of size r
  19. def normalize_midpoint(pos1, pos2, r=1.0):
  20. pos = pos1.Add(pos2).MultiplyFloat(0.5)
  21. pos.Normalize()
  22. return pos.MultiplyFloat(r)