Class Sphere

java.lang.Object
hoverball.math.Sphere

public final class Sphere
extends java.lang.Object
The class Sphere represents the surface of a three dimensional sphere.

A sphere is only defined by its radius. Unlike Matrix, Vector and Complex it is a rather stiff object. You cannot "calculate" a lot, but the class Sphere offers a small library of spherical operations that eases the handling of matrices, vectors and complex numbers.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    double per
    Sphere perimeter
    double rad
    Sphere radius
  • Constructor Summary

    Constructors 
    Constructor Description
    Sphere​(double r)
    Creates a sphere with the specified radius.
  • Method Summary

    Modifier and Type Method Description
    Matrix base​(Vector v)
    Creates an orthonormal basis from a given vector.
    Matrix base​(Vector v, double alpha)
    Creates an orthonormal basis from a given vector and a turn angle.
    double diff​(Vector a, Vector b)
    Returns the distance between two vectors on the sphere.
    boolean equals​(java.lang.Object S)
    Compares with a sphere
    static Vector euler​(Matrix M)
    Creates the Euler vector from a matrix.
    static Matrix euler​(Vector v)
    Creates the matrix from an Euler vector.
    int hashCode()
    Returns the hash code.
    java.lang.String toString()
    String representation.
    Vector warp​(Complex c)
    Transforms a plane position into a spherical position.
    Matrix warp​(Complex c, double alpha)
    Transforms a plane position into a spherical position.
    Vector warp​(Matrix M)
    Transforms a spherical position into a plane position.
    Complex warp​(Vector v)
    Transforms a spherical position into a plane position.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • rad

      public final double rad
      Sphere radius
    • per

      public final double per
      Sphere perimeter
  • Constructor Details

    • Sphere

      public Sphere​(double r)
      Creates a sphere with the specified radius.
      Parameters:
      r - Radius
  • Method Details

    • hashCode

      public int hashCode()
      Returns the hash code.
      Overrides:
      hashCode in class java.lang.Object
      Returns:
      the hash code
    • toString

      public java.lang.String toString()
      String representation.
      Overrides:
      toString in class java.lang.Object
      Returns:
      the string
    • equals

      public boolean equals​(java.lang.Object S)
      Compares with a sphere
      Overrides:
      equals in class java.lang.Object
      Parameters:
      S - sphere
      Returns:
      the equality
    • diff

      public final double diff​(Vector a, Vector b)
      Returns the distance between two vectors on the sphere.

      If R is the sphere radius, and if a, b != 0 are the two vectors, this function will compute:

      R * acos(< a, b > / |a||b|)

      Parameters:
      a - vector
      b - vector
      Returns:
      the distance
    • base

      public final Matrix base​(Vector v)
      Creates an orthonormal basis from a given vector.

      If v != 0 is the vector and (a,b,c) the orthonormal basis, there is:

      • c = v / |v|
      • b = z x c   [ z = (0,0,1) ]
      • a = b x c
      Parameters:
      v - vector
      Returns:
      the basis
    • base

      public final Matrix base​(Vector v, double alpha)
      Creates an orthonormal basis from a given vector and a turn angle.

      The orthonormal basis (a,b,c) is first generated from the vector, then turned by the turn angle around its c-axis.

      Parameters:
      v - vector
      alpha - angle
      Returns:
      the basis
    • warp

      public final Vector warp​(Complex c)
      Transforms a plane position into a spherical position.
      Parameters:
      c - complex number
      Returns:
      the spherical vector
    • warp

      public final Matrix warp​(Complex c, double alpha)
      Transforms a plane position into a spherical position.

      The plane visual angles are parametrized in a way that angles of value 0 point along the ray from the origin to the position.

      Parameters:
      c - complex number
      alpha - visual angle
      Returns:
      the spherical matrix
    • warp

      public final Complex warp​(Vector v)
      Transforms a spherical position into a plane position.
      Parameters:
      v - spherical vector
      Returns:
      the complex number
    • warp

      public final Vector warp​(Matrix M)
      Transforms a spherical position into a plane position.

      The plane visual angles are parametrized in a way that angles of value 0 point along the ray from the origin to the position.

      For practical reasons, the returned values position and visual angle are packed in a Vector object and should be decomposed at once by a programming code as follows:

      Vector v = Sphere.warp(M);         // "(c,a) = Sphere.warp(M);"
       
      Complex c = new Complex(cf.x,v.y);  // c = position
      double a = v.z;                    // a = visual angle
      
      Parameters:
      M - spherical matrix
      Returns:
      the complex number and the visual angle as Vector object
    • euler

      public static final Matrix euler​(Vector v)
      Creates the matrix from an Euler vector.
      Parameters:
      v - Euler vector
      Returns:
      the matrix
    • euler

      public static final Vector euler​(Matrix M)
      Creates the Euler vector from a matrix.
      Parameters:
      M - matrix
      Returns:
      the Euler vector