fancytools.math package¶
Submodules¶
fancytools.math.MaskedMovingAverage module¶
-
class
fancytools.math.MaskedMovingAverage.MaskedMovingAverage(shape, calcVariance=False, dtype=<type 'numpy.float64'>)[source]¶ Bases:
objectCalculating the moving average and variance on (optional masked) ndArray allowing to update different areas every time
moving average and variance taken from http://stackoverflow.com/a/14638138 referring to http://www.johndcook.com/blog/standard_deviation/
fancytools.math.MovingAverage module¶
fancytools.math.Point3D module¶
Created on 21 Aug 2015
#taken from http://codentronix.com/2011/04/20/simulation-of-3d-point-rotation-with-python-and-pygame/
fancytools.math.angleDiff module¶
-
fancytools.math.angleDiff.angleDiff(angle1, angle2)[source]¶ smallest difference between 2 angles code from http://stackoverflow.com/questions/1878907/the-smallest-difference-between-2-angles
fancytools.math.blockshaped module¶
-
fancytools.math.blockshaped.blockshaped(arr, nrows, ncols)[source]¶ Return an new array of shape (n, nrows, ncols) where n * nrows * ncols = arr.size
If arr is a 2D array, the returned array looks like n subblocks with each subblock preserving the “physical” layout of arr.
-
fancytools.math.blockshaped.from2dBlocks(arr)[source]¶ input needs to be 4d array (2d array of 2d arrays)
fancytools.math.boundingBox module¶
-
fancytools.math.boundingBox.boundingBox(booleanArray)[source]¶ return indices of the smallest bounding box enclosing all non-zero values within an array
>>> a = np.array([ [0,0,0,0], ... [0,1,0,1], ... [0,0,1,0], ... [1,0,0,0], ... [0,0,0,0] ]) >>> print boundingBox(a) (slice(1, 3, None), slice(0, 3, None))
fancytools.math.execOnSubArrays module¶
-
fancytools.math.execOnSubArrays.execOnSubArrays(arrs, fn, splitX, splitY)[source]¶ execute a function(on or multiple arrays) only on sub sections works only on 2d arrays at the moment
>>> a1 = np.ones((1000,1000)) >>> a2 = np.ones((1000,1000)) >>> out = execOnSubArrays((a1,a2), lambda sa1,sa2: sa1+as2, splitX=10, splitY=10)
fancytools.math.findXAt module¶
fancytools.math.gridPointsFromEdges module¶
fancytools.math.linRegressUsingMasked2dArrays module¶
-
fancytools.math.linRegressUsingMasked2dArrays.linRegressUsingMasked2dArrays(xVals, arrays, badMask)[source]¶ if you have multiple 2d arrays each with position given by xVals[array-index] and you want to do a linear regression on all cells but you also might mask different areas in each 2darray
returns ascent, offset, RMS-error
fancytools.math.line module¶
Collection of line-based functions line given as:
x0,y0,x1,y1 = line
-
fancytools.math.line.distance(line, point)[source]¶ infinite line to point or line to line distance is point is given as line - use middle point of that liune
-
fancytools.math.line.intersection[source]¶ Return the coordinates of a point of intersection given two lines. Return None if the lines are parallel, but non-colli_near. Return an arbitrary point of intersection if the lines are colli_near.
Parameters: line1 and line2: lines given by 4 points (x0,y0,x1,y1).
-
fancytools.math.line.resize(line, factor)[source]¶ factor: relative length (1->no change, 2-> double, 0.5:half)
-
fancytools.math.line.split(line, lines)[source]¶ split <line> into multiple sublines using intersection with <lines>
fancytools.math.linspace2 module¶
fancytools.math.nearestPosition module¶
fancytools.math.nearestPosition2 module¶
-
class
fancytools.math.nearestPosition2.NearestPosition2(array, lastPos=0)[source]¶ Bases:
objectreturn the index of that value that is most similar in the array starting from the last known position, checking the right direction
- assumes that new values to sort are close the the old ones
- for this case and in case the array is sorted this approach is much faster than the normal nearestPosition
>>> import numpy >>> a = numpy.array([1,3,7,12,15,20,33]) >>> n = NearestPosition2(a) >>> n(5) 2 >>> n(22) 5 >>> n(24) 5
fancytools.math.pointInsidePolygon module¶
-
fancytools.math.pointInsidePolygon.pointInsidePolygon(x, y, poly)[source]¶ Determine if a point is inside a given polygon or not Polygon is a list of (x,y) pairs.
[code taken from: http://www.ariel.com.au/a/python-point-int-poly.html]
let’s make an easy square:
>>> poly = [ (0,0), (1,0), (1,1), (0,1) ] >>> pointInsidePolygon(0.5,0.5, poly) True >>> pointInsidePolygon(1.5,1.5, poly) False
fancytools.math.rotatePolygon module¶
-
fancytools.math.rotatePolygon.rotatePolygon(polygon, theta, origin=None)[source]¶ Rotates the given polygon around the origin or if not given it’s center of mass
polygon: np.array( (x1,y1), (...)) theta: rotation clockwise in RADIAN origin = [x,y] - if not given set to center of gravity
returns: None
fancytools.math.rotation module¶
-
fancytools.math.rotation.axisAndAngle2RotMatrix(axis, angle)[source]¶ http://stackoverflow.com/questions/6802577/python-rotation-of-3d-vector
Return the rotation matrix associated with counterclockwise rotation about the given axis by angle radians.
-
fancytools.math.rotation.rotMatrix2AxisAndAngle(R)[source]¶ -
R : 3x3 rotation matrix returns axis, angle
-
fancytools.math.rotation.rotVector2Matrix(vec)[source]¶ better use cv2.Rodrigues(rvec)[0] for that job...
the angle is given as the magnitude of the rot vector, see https://www.safaribooksonline.com/library/view/learning-opencv/9780596516130/ch11s05.html