示例#1
0
  /**
   * Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores
   * the results in the store var.
   */
  public static PVector sphericalToCartesianZ(PVector sphereCoords, PVector store) {
    store.z = sphereCoords.x * FastMath.sin(sphereCoords.z);
    float a = sphereCoords.x * FastMath.cos(sphereCoords.z);
    store.x = a * FastMath.cos(sphereCoords.y);
    store.y = a * FastMath.sin(sphereCoords.y);

    return store;
  }
示例#2
0
 /**
  * Converts a point from Cartesian coordinates (using positive Z as up) to Spherical and stores
  * the results in the store var. (Radius, Azimuth, Polar)
  */
 public static PVector cartesianZToSpherical(PVector cartCoords, PVector store) {
   if (cartCoords.x == 0) cartCoords.x = FastMath.FLT_EPSILON;
   store.x =
       FastMath.sqrt(
           (cartCoords.x * cartCoords.x)
               + (cartCoords.y * cartCoords.y)
               + (cartCoords.z * cartCoords.z));
   store.z = FastMath.atan(cartCoords.z / cartCoords.x);
   if (cartCoords.x < 0) store.z += FastMath.PI;
   store.y = FastMath.asin(cartCoords.y / store.x);
   return store;
 }