Code Monkey home page Code Monkey logo

math's Introduction

math

This is a collection of mathematical classes useful in my robotics projects. It contains 3D transforms, rotations, vectors, and some miscellaneous math methods.

Matrix and Vector Usage Patterns

There are API patterns to the matrix and vector classes in library: results pre-allocation and method chaining.

Pre-allocation of Results

Pre-allocate results, and use the result as the object of the method call. The pre-allocation allows the caller to completely control object allocation and thus reuse objects. This can (usually) avoid excessive allocation and garbage collection as a result of mathematical routines. Also by having the result object be the base of the call, it follows mathematical conventions of writing "x = a * b", for example:

Vec3d x = new Vec3d(); // preallocate result
x.cross(a, b); // compute cross product of a and b and store result in x

Method Chaining

Where possible, methods return this. This allows for method chaining, where the result from the first operation is used immediately as an operator in the second. For example:

Vec3d v = new Vec3d();
v.sub(a,b).mul(0.5).add(c); // compute v = (a-b) * 0.5 + c

Double / Float Versions

This code is primarily written in double precision math. The make-float-versions.sh script converts the double versions to float version. This is a very simple sed-script based conversion which relies upon a few rules:

  • For all floating-point values, use a decimal, e.g., instead of "0", use "0.0". The script will append "f" to make them "0.0f".
  • Follow the existing classes for computing hash codes based upon doubles, in particular, make sure to accumulate a long, and then return the XOR'd value in the same form.

License

BSD 2-Clause License

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.