Jump to content

[TOOLKIT] Math Formula Rendering


The_GTA

Recommended Posts

Dear MTA community,

this resource renders mathematical formulas in scientific notation. It does solely contain internal Lua functions that should be used inside this resource. You are allowed to take the code from this resource into your own project without restrictions (if you do I would greatly appreciate a post in this thread with a link to the project you used my code in, maybe for further support).

GitHub: quiret/lua_math_formulas: Math formulation renderer for MTA San Andreas written in Lua (github.com)

spacer.png

Example commands:

  • dt disfract
  • dt fraction
  • dt sqroot
  • dt realdf
  • dt realfract
  • dt realexp
  • dt realexpfract
  • dt realrootfract
  • dt realadd
  • dt realaddcomplex
  • dt realaddcomplex2
  • dt realaddcomplex3
  • dt realaddcomplex4
  • dt realdiv
  • dt realdivcomplex
  • dt realdivcomplex2
  • dt realdivcomplex3
  • dt realdivcomplex4
  • dt realdivcomplex5
  • dt off

Public API:

fraction createFraction( df counter, df divisor )
real createRealNumber( realvalue value )

number math_add( number a, number, b )
number math_sub( number a, number b )
number math_mul( number a, number b )
number math_div( number a, number b )
number math_pow( number a, number b )
number math_neg( number a )
number math_inv( number a )
number math_simple( number a )

bool math_eq( number a, number b )
bool math_lt( number a, number b )
bool math_le( number a, number b )
	
  • number is a regular Lua numeric value (1, 2, 3, 4, math.pi, math.exp(1), etc)
  • any approximated value is not calculated-on in the math engine, you should stick to fractions which require natural numbers, zero or negative natural numbers (df type)
  • objects returned by the math_ family of functions as well as createFraction or createRealNumber have the Lua operators +, -, /, *, ^, ==, <, <= overloaded to simplify usage
  • real numbers such as math.pi or math.exp(1) are generarilly not specially implemented beyond visual representation; to simplify the implementation of real number comparison I have resorted to calculating the machine approximation and comparing based on that; improvement would require proven real number representation comparisons and their implementations; feel free to contribute any add-ons to the code in this topic which I might merge
drawobj createDrawingFormula( number formula )

void drawobj.draw( float xoff, float yoff, float scale )
float(x), float(y) drawobj.getSize()

Motivation:

This resource should be used to get a mathematical result that is scientifically correct and is not based on a machine-accelerated approximated calculation. I created this code as part of a mathematical project I am working on that I will disclose at a later date.

Noteworthy technology:

A custom UI layout engine is being used to draw the formulas. Dependency graph logic is being used to perform node-based computation, reusing many results with efficiency in mind.

Have fun!

Edited by The_GTA
  • Like 3
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...