A collection of C++ classes and functions to compute common mathematical operations and transformations that interoperate with common creative-coding libraries.
takram::math::Random
takram::math::Vec2
takram::math::Vec3
takram::math::Vec4
takram::math::Size2
takram::math::Size3
takram::math::Line2
takram::math::Line3
takram::math::Triangle2
takram::math::Triangle3
takram::math::Rect2
Random is a wrapper of STL’s random number library designed for providing a simpler interface.
#include <limits>
#include "takram/math/random.h"
takram::Random<> random;
// Uniform distribution ranges from 0 to the max int
random.uniform<int>(std::numeric_limits<int>::max());
// Gaussian (normal) distribution of mean 0 and standard deviation 1
random.gaussian<double>();
All types in this module promote the return type of arithmetic operators in the same way built-in arithmetic types do. Some member functions like magnitude()
also promote the return type. The magnitude of a vector of integral type is promoted to double, but that of float remains float.
#include "takram/math/vector.h"
takram::Vec2i veci;
takram::Vec2d vecd;
takram::Vec2f vecf;
veci + veci; // Vec2<double>
veci + vecf; // Vec2<double>
veci + vecd; // Vec2<double>
vecf + vecf; // Vec2<float>
vecf + vecd; // Vec2<double>
Vec, Size and Rect are implicitly convertible to/from corresponding types of OpenCV, openFrameworks and Cinder.
OpenCV | openFrameworks | Cinder | |
---|---|---|---|
Vec2 | cv::Point | ofVec2f | ci::Vec2 |
Vec3 | cv::Point3 | ofVec3f | ci::Vec3 |
Vec4 | ofVec4f | ci::Vec4 | |
Size2 | cv::Size | ||
Size3 | |||
Rect2 | cv::Rect | ofRectangle | ci::Rect |
Run "setup.sh" inside "script" directory to initialize submodules and build dependant libraries.
The MIT License
Copyright (C) 2015-2016 Shota Matsuda
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.