Complexf Class

This class provides you with an interface for easy handling of the complex number space with single precision float data type. If you like to get some more background around complex numbers and the corresponding functions, please read the Wikipedia Article http://en.wikipedia.org/wiki/Complex_number.

As with all Classes in TkMath, Complexf fully supports the serialisation interface.

  1. Initialisation of values

    1. Complexf:init(float a, float b)

      Initialises the x component with a and the y component with b.

    2. Complexf:initPolar(float r, float a)

      Similar to Complexf:init, only that it initialises the polar coordinates.

    3. Complexf.New(float a, float b) returns Complexf

      Creates a new Complexf instance and initialises its x and y values with x=a and y=b.

      Returns the newly created instance

    4. Complexf.NewPolar(float r, float a) returns Complexf

      Similar to Complexf:New, only that it initialises the polar coordinates.

    5. complexf(float a, float b) returns Complexf

      same as Complex.New

    6. complexfPolar(float r, float a) returns Complexf

      same as Complex.NewPolar

    7. Direct access to elements

      The Complexf class represents complex numbers which can be either interpreted as (x+iy) or as (r·eia)

      These elements can be accessed individually:

      • float Complexf:x

        Read/Write the x component of (x+iy).

      • float Complexf:y

        Read/Write the y component of (x+iy).

      • float Complexf:r

        Read/Write the r component of (r·eia).

        Only works on non-zero complex numbers, exception is thrown if a zero Complexf value occurs.

      • float Complexf:a

        Read/Write the a component of (r·eia).

        Only works on non-zero complex numbers, exception is thrown if a zero Complexf value occurs.

      • String Complexf:string

        Read out the string representation (x+iy) of a complex number. This property is Read-Only!

      • String Complexf:polarString

        Read out the string representation (r·eia) of a complex number. This property is Read-Only!

      • float Complexf:abs

        Returns the length of the complex number. Same as element r. This property is Read-Only!

      • float Complexf:absSquare

        Returns the squared length of the complex number. Same as r2. This property is Read-Only!

      Keep in mind when using the polar representation, that internally Complexf saves in (x+iy) format and thus some translation overhead as well as inaccuracies are occuring

    8. Importing values from other classes

      As Complexf uses the Array Interface to collect its values from other classes, such as FloatArray, Lists or even Vector2f.

      Simply use the assign operator:

      Complexf val;

      val=[1,2];

  2. Operator support

    The following operators are supported by the Complexf class to allow intuitive handling of complex numbers:

    Operator Type of second Value Action Returns
    <this>=<other> Complexf

    Generic Array Object

    copy contents from other to this

    copy contents from other to this

    this
    <this>==<other> Complexf comparison if equal bool
    <this>!=<other> Complexf comparison if not equal bool
    <this>+<other> Complexf complex addition this
    <this>-<other> Complexf complex substraction this
    <this>*<other> Complexf complex multiplication this
    <this>/<other> Complexf complex division this
    -<this> none negate components this

    The reference to <this> does mean, that for example

    Complexf x,y;

    x=y*(x+y);

    gives correct results, as a new temporary copy is created and used automatically by the TKS core.

  3. Array support

    Complexf uses the default TKS YAC Array interface, and thus you are capable of accessing its elements in a manner similar to common arrays.

    This is currently only supported for the euclidean representation (x+iy), so that

    Complexf[0]=Complexf.x

    Complexf[1]=Complexf.y

  4. Supplemental methods

    1. Complexf:add(Complexf a)

      implements RSELF, RVAL, RARG

      Add another complex number to this.

    2. Complexf:sub(Complexf a)

      implements RSELF, RVAL, RARG

      Subtract another complex number of this.

    3. Complexf:mulf(float a)

      implements RSELF, RVAL, RARG

      Multiplicate a scalar value with this.

    4. Complexf:mul(Complexf a)

      implements RSELF, RVAL, RARG

      Multiplicate another complex number with this

    5. Complexf:mulConj(Complexf a) returns float

      Multiplicate another complex conjugated number with this and return the resulting scalar.

    6. Complexf:div(Complexf a)

      implements RSELF, RVAL, RARG

      Divide this by a.

    7. Complexf:invert()

      implements RSELF, RVAL, RARG

      Invert this this=(1/this)

    8. Complexf:unit()

      implements RSELF, RVAL, RARG

      Set length of this to 1.

    9. Complexf:unitScale(float s)

      implements RSELF, RVAL, RARG

      Set length of this to s.

  5. Complexf functions

    1. Complexf logarithms and exponential functions

      1. sqrtcf(Complexf z) returns Complexf

        implements RVAL, RARG

        Returns complex √z

      2. powcf(Complexf a, Complexf b) returns Complexf

        implements RVAL, RARG

        Returns complex ab

      3. expcf(Complexf z) returns Complexf

        implements RVAL, RARG

        Returns complex ez

      4. logcf(Complexf z) returns Complexf

        implements RVAL, RARG

        Returns complex log z

    2. Complexf trigonometric functions

      1. sincf(Complexf a) returns Complexf

        implements RVAL, RARG

        Returns complex sine of a

      2. coscf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex cosine of a

      3. tancf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex tangent of a

      4. asincf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex inverted sine of a

      5. acoscf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex inverted cosine of a

      6. atancf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex inverted tangent of a

    3. Complexf hyperbolic functions

      1. sinhcf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex hyperbolic sine

      2. coshcf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex hyperbolic cosine

      3. tanhcf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex hyperbolic tangent

      4. asinhcf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex inverted hyperbolic sine

      5. acoshcf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex inverted hyperbolic cosine

      6. atanhcf(Complexf) returns Complexf

        implements RVAL, RARG

        Returns complex inverted hyperbolic tangent