TkMath is a plugin library for the Tks Script Engine
As not every Application needs a sophisticated math library loaded, it was decided to divide the provided methods from the Core. This Documentation will provide you with a detailed description of how to install and use this library.
The TkMath Plugin provides with several kinds of Tools. First and foremost it expands the Core with scalar trigonometric and hyperbolic functions as well as the usual exp, log, pow etc methods found in common math libraries.
As an extension it also provides Classes for easy usage of Vector and Complex Number Mathematics.
It provides Vector2f, Vector3f and Vector4f for single precision Vector Mathematics
It provides Complexf for single precision complex calculation.
It provides Matrix2f, Matrix3f and Matrix4f for single precision advanced Vector Mathematics.
To compile and use TkMath you need first of all the TKS SDK, please see the following paragraph on how to install it.
First you need a supported C++ Compiler like GCC, VisualC or the Intel C Compiler. Additional libraries needed are:
as core requirements
Additional plugins (not required for tkmath) need the following
TkMath itself has no further requirements than the standard math library.
Download the library from http://tkscript.de/files/tkmath.zip or get the development version from http://tkscript.de/files/current/tkmath.zip
If you have the TKS SDK already installed, you can omit the next steps, change to your TKS SDK directory , and go on unzipping tkmath.zip.
Make sure that you also have the latest tkscript installed, download the Linux Installation Shell file and run
sh install_linux.sh compile
and after that
sudo sh install_linux.sh install
if you don't want or can't install it as root user, make sure that you have LD_LIBRARY_PATH set to the library directory and the have the Path to the binary include in your PATH environment variable.
Now unzip tkmath.zip into your TKS Development Direcotry you just prepared
unzip <PATH_TO_ARCHIVE>/tkmath.zip
Now you can enter the directoy and compile tkmath:
cd tkmath; make -f makefile.linux clean shared
If all went fine, it will look like this:
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c
commonmath.cpp -o commonmath.o -I../yac
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c vector2f.cpp
-o vector2f.o -I../yac
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c matrix2f.cpp
-o matrix2f.o -I../yac
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c complexf.cpp
-o complexf.o -I../yac
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c vector3f.cpp
-o vector3f.o -I../yac
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c matrix3f.cpp
-o matrix3f.o -I../yac
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c vector4f.cpp
-o vector4f.o -I../yac
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c matrix4f.cpp
-o matrix4f.o -I../yac
c++ -O3 -Wall -fPIC -g -DDX_USE_C99_COMPLEX -c tkmath.cpp -o
tkmath.o -I../yac
c++ -shared -o tkmath.so commonmath.o vector2f.o matrix2f.o
complexf.o vector3f.o matrix3f.o vector4f.o matrix4f.o tkmath.o
-Wl,-soname,tkmath.so -lm
Build finished at 16:17.
When no error appeared, you can go on and install the library to your TKS Installation:
sudo make -f makefile.linux install
That's it! You are done now and can go on using TkMath.
If not, please contact us.
Hier darfst du tippern :P
If you encounter problems with compilation, you may check here if your problem is known and solved.
Please make sure that your parent directoy structure is the one from your TKS SDK, as it looks for the YAC interface in ../yac
Your system c++ library has bad/no support for the complex datatype template. You can use the alternative implementation in TkMath through editing the appropriate makefile/projectfile and make sure that -DDX_USE_C99_COMPLEX is changed to -UDX_USE_C99_COMPLEX
If you want to check if TkMath is working correctly, download first the TkUnit plugin, unzip to your TKS SDK directory and install it. After you are ready, change into the tkmath/math-unittests directory and run
tks math-unittests
If all is fine with your installation, the last line should print out a big "OK" on your console. After running this, you will also have an updated math_unittests_results.html, which will inform you about what was tested with what kind of result.
Usage of TkMath especially and TkScript as a whole is really intuitive and easy. Just look at the following example: of hello_complex.tks:
use tkmath;
module Main;
Complex2f a=[1.0,0]; //we dont want a zero
element,
a
s we want to chang
e polar
coordinates on a circle
a.r=5; //we want a radius of 5
a.a=M_PI; // we want an angle of PI
print "Hello Complex Value, your content is "+a;
After saving this into hello_complex.tks, you can easily execute it now with
tks hello_complex.tks
and you will get
user@host:~/tks/tkmath/doc-examples$ tks
hello_complex.tks
Hello Complex Value, your content is
(-5+i*-4.37114e-07)
Now you have run your first TKS Script using a TkMath Class, Conagrats!
This is a list of categories of methods and function which are supplied by TkMath. All Classes share the ability of memory pooling and also support serialisation through the YAC Interface.
The following semantics will be used through the API description:
The method is to be used with instantiated values only.
Example:
Complex:mulConj(Complexf) returns float
Complexf a=[1,2],b=[3.4];
trace "a*b_conjugated="+a.mulConj(b); //result is
11
These are static methods available directly from the class itself.
Example:
Complex.New(float, float) returns Complexf
Complexf a<=Complexf.New(1,2);
These functions are globally available.
Example:
sinf(float) returns float
trace "sin(0.5*pi)="+sinf(0.5*M_PI);
These are accessible elements of type <type>. They can be either Read/Write, Read Only or Write Only!
Examples;
float Complexf:x
float Complexf:y
String Complexf:string
Complexf a=[1,2];
a.x=a.x+a.y; //Read/Write
trace "a="+a.string; //this is a readonly
property!
The API supports the generic RVAL/RARG/RSELF mechanism from tkscript where appropriated. So you can choose to work on the instance itself, copy to another value or use another instance as return object.
Example:
Vector2f v<=vector2f(3,4);
RSELF:
v.unit(); //saves the normalised value in v
RVAL:
Vector2f r=v.unit(); //copies the normalised value in r, v
unchanged
The target class of r can be different to v.
RARG:
Vector2f r;
v.unit() => r; //directly writes the normalised value into r,
v unchanged
The target class type of r must be the same of the return value (in this example Vector2f).
Methods with an RSELF implementation return the same class type of the instance called (see *:unit() as example), while methods without an RSELF implementation usually return a different class type (see Matrix*:mulv() as example).
Please click on the links to find out more about the choosen category!
This documentation and the plugin was written by