Are you planning to upload your awesome spell or system to Hive? Please review the rules here.Dismiss Notice
Triumph has risen from these uncharted shores. The 34th Modeling Contest Results are out!Dismiss Notice
Awaken what lies in the heart of your swarm. The 17th Techtree Contest has arrived!Dismiss Notice
The Hive Workshop is launching its first HD modelling contest. How HD should it be?Dismiss Notice
Check out the Staff Job Openings thread.Dismiss Notice
Advanced Maths & Ingame Calculator
Submitted by looking_for_help
Advanced Mathematics & Ingame Calculator
vJass Version 184.108.40.206
This is a math library designed to provide advanced mathematic functions and functionalities that are not supported by the World Editor. Mathematics are important for various things like calculating a units armor, physic systems with kinematics or differential equations, movement, artificial intelligence, statistics for balancing and many more. Therefore it is quite annoying that the World Editor lacks of many important math functions. The aim of this system is to close this gap - The library provides extremly efficient functions to calculate logarithms, hyperbolic functions and their inverses as well as typecheck or rounding functions and many more. Not only "complicated" functions are provided but also very easy ones like the absolute value of a real number, to finally have a full and complete list of important functions which every Math library should provide.
Further the library is designed modular, so that further and more advanced extensions can be easily added or removed from the system core. As a first Extension, there is a MathParser library included to the system which provides a fully functional interpreter for mathematic expressions, making it possible to implement an ingame calculator to the game. Further Plug-Ins or Extensions will follow.
2. System Code
Enclosed is the systems code. The system uses Newton-Cotes formulars to compute logarithms, hyperbolic functions and their inverses at an extremly high precision with a minimal overhead. Only four divisions are used in the worst case to compute the natural logarithm of a number, apart from that only additions and multiplications are used, making these functions very efficient. Some functions of the library already exist in the standard editor, like the min/max functions or abs. These are included for better readability to not have to use BJs. For more details about the interpreter, see section 3.
System API and math function list
3. Implementation and Available Extensions
To implement this system, just copy and paste the Math and the IngameCalculator triggers to your map. The only requirement is vJass, then you can use it right away, same applies for the available Extensions.
This is one Extension to the Math library, a Math Parser library making it possible to dynamically evaluate mathematic expressions. This can be used to implement an ingame calculator to the game which makes ingame calculations very comfortable. This can be also useful for several things like: mathematic minigames or riddles, calculations during debugging or as a comfort function for maps that have a complex stat/skill system. Also maps with economy simulation parts could benefit from this. The math interpreter is based on standard Matlab conventions and supports the following symbols:
- Numbers with or without decimal point, e.g.: 3, 4.3, 55.2
- Arithmetic operators: +, -, *, /
- Power: ^
- Parenthesis: ( )
- Result memory (stores the last computed result): ans
- Clear screen: clc
The interpreter is designed to be very robust towards the different typing styles of mathematical expressions. So you can write for example 5*(1+2) or 5(1+2), the interpreter will automatically bring it into an understandable form. With the formatExpression method it is garantueed that the expression will also follow the standard conventions in terms of spacing and operator placement. Finally the interpreter is provided with various syntax and math error messages which will throw exceptions if the entered expression is invalid. These error messages can be optionally turned of in the system configuration. Enclosed is the Plug-In code:
This is another Extension to the basic Maths library which gives you the possiblity to perform Matrix operations in Warcraft 3. Matrices can basically be used like 2D-Arrays with this library. The library also provides advanced methods to initialize, reshape or to perform calculations with Matrices. Gaußian Eliminiation with pivotising is implemented as well as solving a System of Linear Equations (SLE), inverting or transposing a Matrix as well as calculating the norm, condition or trace.
This library will serve as a base for more advanced libraries in the future which allow curve fitting, trajectory interpolation and many more.
Example Solution of a System of Linear Equations
Enclosed are some screenshots of the testmap, showing some of the ingame calculations from the MathParser Extension.
5. Accuracy and Performance
The following tables show the accuracy of the natural logarithm function which is used to calculate al other logarithms as well as the hyperbolic functions and their inverses. Also performance for all math functions is displayed in an extra table. Finally the efficiency of the isPrime method is analysed and compared towards the standard brute force attempt.
Accuracy and Performance
Hope you enjoy it!
Advanced Mathematics, Math, Calculator, Ingame calculator, interpreter, logarithm, hyperbolic
Page 1 of 5
Page 1 of 5