Giter Club home page Giter Club logo

terathon-math-library's People

Contributors

ericlengyel avatar talanc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terathon-math-library's Issues

Terathon::Arctan() too imprecise

Hi,

We (Masterbrain Bytes/Cattle and Crops) have camera code that uses polar coordinates to handle input, and we also want the camera to move (and turn) with the vehicle the player is currently driving.
So we're using code like

float zrot = Arctan( vehicleTransform.m10, vehicleTransform.m00 );
azimuth += zrot;

This generally works, but we noticed that when just driving in a circle, at certain angles the camera stuttered.
When replacing Arctan() with atan2f() those problems went away.

This could've been it, but this issue somehow nerdsniped me so I started investigating and found out that Arctan(float x) has errors of up to 0.004459 (compared to atan(x) in double precision).

When looking up how a fast atan() can be implemented, I stumbled upon the idea of just doing a linear interpolation between values of a lookup table.
So I implemented it (with the existing lookup-table), just interpolating between table[i] and table[i+1], using b - i as the lerp factor, and to my big surprise this works really well - the maximal error seems to be below 0.000020, i.e. over 200 times lower.
In addition to that, it even seems to be about twice as fast, and it works with our camera code.

I tested this extensively both with values between +/- 10'000 (in steps of 0.00001) and values between +/- 1.5 (in steps of 0.00000001) and it indeed seems to work quite well.

Here's my test program (tested on both Linux and Windows), including both your and my Arctan(float) implementation: atantest-upd.cpp.txt (Github doesn't allow attaching .cpp files so I had to append .txt).
UPDATE: Replaced the file with an updated one with one more element in table; also added function with 130 element lookup table.
Feel free to use it (also in your commercial code).

Here's my test results from both Linux (on a AMD Ryzen 2700X) and Win10 (on an Intel Haswell i7-4771): atanresults.txt

Cheers,
Daniel

TSMath.h is missing

the TSMath.h header seems to be missing, it's being called from TSAlgebra.h , Thank you

wrong formula in doc for Vector2D Reject

I think the formula in the documentation is wrong.

It should not be (a - a.b)b, but rather a - (a.b)b

//# Returns (<b>a</b>&#x202F;&minus;&#x202F;<b>a</b>&#x202F;&sdot;&#x202F;<b>b</b>)<b>b</b>, which is the rejection of $a$ from $b$ under the assumption that the magnitude of $b$ is one.

The actual code seems fine, though:

return (a - b * Dot(a, b));

add topic tags

I suggest adding topics such as geometric-algebra, quaternion in the About section

Unit tests

Any plans on adding unit tests to the library? I think it could prevent issues like these:

#5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.