reb
Class Mobius

Object
  extended by reb:Mobius

class 
Object:Mobius

Creates Mobius transformations in a matrix format.

T(z) = (az+b)/(cz+d)

T is a Mobius Transformation were z, a, b, c and d are complex numbers. T is typically represented in normalized matrix form:

T = | a b |
| c d |

T is normalized if the determinant of ad-bc = 1

A Mobius Transformation can be viewed as a composition of translation, scaling and inversion.

The Trace of T is TrT = a+ d


Ultra Fractal Source

Toggle UF Source Code Display

 class Mobius {
 ; Creates Mobius transformations in a matrix format. <br>
 ; <p>
 ; T(z) = (az+b)/(cz+d) <br>
 ; <p>
 ; T is a Mobius Transformation were z, a, b, c and d are complex
 ; numbers. T is typically represented in normalized matrix form:
 ; <p>
 ;       T =   | a  b |  <br>
 ;             | c  d |  <br>
 ; <p>
 ; T is normalized if the determinant of ad-bc = 1 <br>
 ; <p>
 ; A Mobius Transformation can be viewed as a composition of translation,
 ; scaling and inversion.
 ; <p>
 ; The Trace of T is TrT = a+ d
 
 public:
 
 ; Mobius constructor for T(a, b, c, d)
 ; @param a = a value
 ; @param b = b value
 ; @param c = c value
 ; @param d = d value
   func Mobius(complex a, complex b, complex c, complex d)
     m_a = a
     m_b = b
     m_c = c
     m_d = d
     m_TrT = m_a + m_d
   endfunc
 
 ; Circle to Mobius
   func CircToMob(Mobius T, Sphere s)
   ; Lines and Circles can be represented as Mobius Transforms. Lines and
   ; Circles are equivalent in Riemann space. For convenience circles are
   ; represented as sphere objects
      complex unit = 0
      complex im = (0,1)
      if s.frad <= 0
        ; matrix of line
        unit = cos(-#pi*s.frad) + flip(sin(-#pi*s.frad))
        m_a = im*unit
        m_b = im*(conj(unit)*s.fcen-unit*conj(s.fcen))
        m_c = 0
        m_d = im*conj(unit)
      else
        ; matrix of circle
        m_a = s.fcen/s.frad
        m_b = s.frad-|s.fcen|/s.frad
        m_c = 1/s.frad
        m_d = -conj(s.fcen)/s.frad
      endif
   endfunc
 
 ; Mobius to Circle
   func MobToCirc(int level, int rgen, Sphere s)
   ; A Mobius Transform can be represented as a Line or Circle. In
   ; Reimann space a line is a circle with a negative radius. The
   ; 'level' and 'rgen' arguments are for the Kleinian inversion algorithms
     float LINEFUZZ  = 1e-5
     if real(m_c) < LINEFUZZ && real(m_c) > - LINEFUZZ
       ; matrix to line
     s.frad = -atan2(m_a)/#pi-1.5
     s.fcen = -m_b*m_a/2
     else
       ; matrix to circle
       s.fcen = m_a/m_c
       s.frad = cabs(1/real(m_c))
     endif
     s.flevel = level
     s.fgen = rgen
   endfunc
 
 ; Normalize Mobius
   func Normalize(Mobius T)
     complex det = T.m_a*T.m_d-T.m_b*T.m_c
     det = 1/sqrt(det)
     T.m_a = m_a*det
     T.m_b = m_b*det
     T.m_c = m_c*det
     T.m_d = m_d*det
   endfunc
 
 ; Invert Mobius
   func Invert(Mobius T)
     complex det = m_a*m_d-m_b*m_c
     T.m_a = m_d
     T.m_b = -m_b
     T.m_c = -m_c
     T.m_d = m_a
     if real(det) <= 0
       T.m_a = -conj(T.m_a)
       T.m_b = -conj(T.m_b)
       T.m_c = -conj(T.m_c)
       T.m_d = -conj(T.m_d)
     endif
   endfunc
 
 ; Multiplication
   func Mult(Mobius T1, Mobius T2)
   ; T2 = T * T1 This does not commute.
   ;
     complex det = m_a*m_d-m_b*m_c
     if real(det) <= 0
       T2.m_a = m_a*conj(T1.m_a)+m_b*conj(T1.m_c)
       T2.m_b = m_a*conj(T1.m_b)+m_b*conj(T1.m_d)
       T2.m_c = m_c*conj(T1.m_a)+m_d*conj(T1.m_c)
       T2.m_d = m_c*conj(T1.m_b)+m_d*conj(T1.m_d)
     else
       T2.m_a = m_a*T1.m_a+m_b*T1.m_c
       T2.m_b = m_a*T1.m_b+m_b*T1.m_d
       T2.m_c = m_c*T1.m_a+m_d*T1.m_c
       T2.m_d = m_c*T1.m_b+m_d*T1.m_d
     endif
   endfunc
 
 ; Conjugate
   func MConj(Mobius T1,Mobius T2)
   ; T2 = T * T1 * inverse(T)
     Mobius igen = new Mobius(0,0,0,0)
     ; Inverse of T
     this.Invert(igen)
     Mobius prod1 = new Mobius(0,0,0,0)
     this.Mult(T1,prod1)
     prod1.Mult(igen,T2)
   endfunc
 
 ; Mobius Trace
   complex func Trace(Mobius T)
     return T.m_a + T.m_d
   endfunc
 
   complex m_a
   complex m_b
   complex m_c
   complex m_d
   complex m_TrT
 
 default:
   title = "Mobius Methods"
   int param v_mobius
     caption = "Version (Mobius Methods)"
     default = 101
     hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
     visible = @v_mobius < 101
   endparam
 }
 


Constructor Summary
Mobius()
           
Mobius(complex a, complex b, complex c, complex d)
          Mobius constructor for T(a, b, c, d)
 
Method Summary
 void CircToMob(Mobius T, Sphere s)
          Circle to Mobius
 void Invert(Mobius T)
          Invert Mobius
 void MConj(Mobius T1, Mobius T2)
          Conjugate
 void MobToCirc(int level, int rgen, Sphere s)
          Mobius to Circle
 void Mult(Mobius T1, Mobius T2)
          Multiplication
 void Normalize(Mobius T)
          Normalize Mobius
 complex Trace(Mobius T)
          Mobius Trace
 
Methods inherited from class Object
 

Constructor Detail

Mobius

public Mobius(complex a,
              complex b,
              complex c,
              complex d)
Mobius constructor for T(a, b, c, d)

Parameters:
a - = a value
b - = b value
c - = c value
d - = d value

Mobius

public Mobius()
Method Detail

CircToMob

public void CircToMob(Mobius T,
                      Sphere s)
Circle to Mobius


MobToCirc

public void MobToCirc(int level,
                      int rgen,
                      Sphere s)
Mobius to Circle


Normalize

public void Normalize(Mobius T)
Normalize Mobius


Invert

public void Invert(Mobius T)
Invert Mobius


Mult

public void Mult(Mobius T1,
                 Mobius T2)
Multiplication


MConj

public void MConj(Mobius T1,
                  Mobius T2)
Conjugate


Trace

public complex Trace(Mobius T)
Mobius Trace