CiftiLib
A C++ library for CIFTI-2 and CIFTI-1 files
|
#include <MathFunctions.h>
Static Public Member Functions | |
static int64_t | combinations (const int64_t n, const int64_t k) |
static int64_t | permutations (const int64_t n, const int64_t k) |
static int64_t | factorial (const int64_t n) |
static bool | normalVector (const float v1[3], const float v2[3], const float v3[3], float normalVectorOut[3]) |
static bool | normalVector (const double v1[3], const double v2[3], const double v3[3], double normalVectorOut[3]) |
static void | normalVectorDirection (const float v1[3], const float v2[3], const float v3[3], float directionOut[3]) |
static void | crossProduct (const float v1[], const float v2[], float resultOut[]) |
static void | crossProduct (const double v1[], const double v2[], double resultOut[]) |
static void | normalizedCrossProduct (const float x1[], const float x2[], float resultOut[]) |
static float | normalizeVector (float vectorsAll[], const int32_t offset) |
static float | normalizeVector (float vectorInOut[3]) |
static double | normalizeVector (double vectorInOut[3]) |
static float | vectorLength (const float vector[3]) |
static float | vectorLength (const float vectorsAll[], const int32_t offset) |
static double | vectorLength (const double vector[3]) |
static float | distanceSquared3D (const float p1[3], const float p2[3]) |
static float | distanceSquared3D (const float xyzAll[], const int32_t offsetCoord1, const int32_t offsetCoord2) |
static float | distance3D (const float p1[3], const float p2[3]) |
static double | distanceSquared3D (const double p1[3], const double p2[3]) |
static double | distance3D (const double p1[3], const double p2[3]) |
static double | distanceSquared2D (const double x1, const double y1, const double x2, const double y2) |
static void | subtractVectors (const float v1[3], const float v2[3], float resultOut[3]) |
static void | addVectors (const float v1[3], const float v2[3], float resultOut[3]) |
static void | createUnitVector (const float startXYZ[3], const float endXYZ[3], float unitVectorOut[3]) |
static void | createUnitVector (const double startXYZ[3], const double endXYZ[3], double unitVectorOut[3]) |
static float | dotProduct (const float p1[3], const float p2[3]) |
static double | dotProduct (const double p1[3], const double p2[3]) |
static float | triangleArea (const float v1[3], const float v2[3], const float v3[3]) |
static float | triangleArea (const double v1[3], const double v2[3], const double v3[3]) |
static float | triangleArea (const float xyzAll[], const int32_t offsetCoord1, const int32_t offsetCoord2, const int32_t offsetCoord3) |
static float | triangleAreaSigned2D (const float p1[3], const float p2[3], const float p3[3]) |
static float | triangleAreaSigned3D (const float referenceNormal[3], const float p1[3], const float p2[3], const float p3[3]) |
static bool | lineIntersection2D (const float p1[3], const float p2[3], const float q1[3], const float q2[3], const float tolerance, float intersectionOut[3]) |
static bool | rayIntersectPlane (const float p1[3], const float p2[3], const float p3[3], const float rayOrigin[3], const float rayVector[3], float intersectionXYZandDistance[3]) |
static void | projectPoint (const float pt[3], const float origin[3], const float normal[3], float projectedPointOut[3]) |
static float | signedDistanceFromPlane (const float planeNormal[3], const float pointInPlane[3], const float queryPoint[3]) |
static int32_t | limitRange (const int32_t value, const int32_t minimumValue, const int32_t maximumValue) |
static float | limitRange (const float value, const float minimumValue, const float maximumValue) |
static double | limitRange (const double value, const double minimumValue, const double maximumValue) |
static float | distanceToLine3D (const float p1[3], const float p2[3], const float point[3]) |
static bool | arraysEqual (const float a[], const float b[], const int32_t numElements) |
static void | averageOfThreeCoordinates (const float c1[3], const float c2[3], const float c3[3], float outputAverage[3]) |
static void | averageOfThreeCoordinates (const float xyzAll[], const int32_t offsetCoord1, const int32_t offsetCoord2, const int32_t offsetCoord3, float outputAverage[], const int32_t outputOffset) |
static float | angle (const float p1[3], const float p2[3], const float p3[3]) |
static float | signedAngle (const float pi[3], const float pj[3], const float pk[3], const float n[3]) |
static bool | isOddNumber (const int32_t number) |
static bool | isEvenNumber (const int32_t number) |
static bool | isNaN (const float number) |
static bool | isPosInf (const float number) |
static bool | isNegInf (const float number) |
static bool | isInf (const float number) |
true if either inf or -inf | |
static bool | isNumeric (const float number) |
true only if not NaN, inf, or -inf | |
static bool | compareArrays (const float a1[], const float a2[], const int32_t numElements, const float tolerance) |
static int32_t | clamp (const int32_t value, const int32_t minimum, const int32_t maximum) |
static float | clamp (const float value, const float minimum, const float maximum) |
static uint32_t | gcd (uint32_t num1, uint32_t num2) |
greatest common divisor | |
static void | quaternToMatrix (const float cijk[4], float matrix[3][3]) |
convert quaternion to rotation matrix | |
static void | quaternToMatrix (const double cijk[4], double matrix[3][3]) |
convert quaternion to rotation matrix | |
static bool | matrixToQuatern (const float matrix[3][3], float cijk[4]) |
try to convert 3x3 matrix to quaternion (return false if not a rotation matrix) | |
static bool | matrixToQuatern (const double matrix[3][3], double cijk[4]) |
try to convert 3x3 matrix to quaternion (return false if not a rotation matrix) | |
static double | remainder (const double numerator, const double denominator) |
static double | round (const double value) |
Various mathematical functions.
|
static |
Angle formed by p1, p2, p3 (angle at p2). Returned angle is in radians. This method uses Java Math.acos() and produces highly accurate results.
p1 | - point. |
p2 | - point. |
p3 | - point. |
|
static |
Determine if two arrays are equal, same number of elements and corresponding elements equal.
a | - first array. |
b | - second array. |
|
static |
Get the average of three coordinates.
c1 | - coordinate 1 |
c2 | - coordinate 2 |
c3 | - coordinate 3 |
outputAverage | A three-dimensional array into which the average of the three coordinates is placed. |
|
static |
Calculate the average of 3 coordinates.
xyzAll | One-dimensional array containing the XYZ coordinates. |
offsetCoord1 | Offset of node 1's X-coordinate which is followed by the Y- and Z-coordinates. |
offsetCoord2 | Offset of node 2's X-coordinate which is followed by the Y- and Z-coordinates. |
offsetCoord3 | Offset of node 3's X-coordinate which is followed by the Y- and Z-coordinates. |
outputAverage | 3 dimensional array passed in, into which the average is placed. |
outputOffset | Offset of average into outputAverage array. |
|
static |
Clamp a value to the range minimum to maximum.
value | Value for clamping. |
minimum | Minimum allowed value. |
maximum | Maximum allowed value. |
|
static |
Clamp a value to the range minimum to maximum.
value | Value for clamping. |
minimum | Minimum allowed value. |
maximum | Maximum allowed value. |
|
static |
Calulate the number of combinations for choosing "k" elements from a total of "n" elements.
Formula: [n!/(k!*(n-k!)) If k > (n-k): [n(n-1)(n-2)...(k+1)] / (n-k)! If k < (n-k): [n(n-1)(n-2)...(n-k+1)] / k!
n | - total number of elements. |
k | - number of elements to choose. |
|
static |
Determine if two arrays are equal.
a1 | First array. |
a2 | Second array. |
tolerance | Allowable difference in elements at same index. |
|
static |
Create the unit vector for a vector that starts at startXYZ and ends at endXYZ.
startXYZ | - Starting position of vector. |
endXYZ | - Ending position of vector. |
unitVectorOut | - output, vector starting at startXYZ and pointing to endXYZ. |
|
static |
Create the unit vector for a vector that starts at startXYZ and ends at endXYZ.
startXYZ | - Starting position of vector. |
endXYZ | - Ending position of vector. |
unitVectorOut | - output, vector starting at startXYZ and pointing to endXYZ. |
|
static |
Cross product of two 3D vectors.
v1 | The first vector, an array of three floats. |
v2 | The first vector, an array of three floats. |
resultOut | Output containing the cross product. |
|
static |
Cross product of two 3D vectors.
v1 | The first vector, an array of three floats. |
v2 | The first vector, an array of three floats. |
resultOut | Output containing the cross product. |
|
static |
Get the distance between two 3D points.
p1 | Point 1 (3 element array) |
p2 | Point 2 (3 element array) |
|
static |
Get the distance between two 3D points.
p1 | Point 1 (3 element array) |
p2 | Point 2 (3 element array) |
|
static |
Distance SQUARED from (x1, y1) to (x2, y2)
X-coordinate | of first point. |
Y-coordinate | of first point. |
X-coordinate | of second point. |
Y-coordinate | of second point. |
|
static |
Get the squared distance between two 3D points.
p1 | Point 1 (3 element array) |
p2 | Point 2 (3 element array) |
|
static |
Get the squared distance between two 3D points.
p1 | Point 1 (3 element array) |
p2 | Point 2 (3 element array) |
|
static |
Get the squared distance between two 3D coordinates.
xyzAll | Array containing all of the XYZ coordinates. |
offsetCoord1 | Offset of the first coordinates X-coordinate. |
offsetCoord2 | Offset of the second coordinates X-coordinate. |
|
static |
Find the distance from the point to the line defined by p1 and p2. Formula is from "http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html".
p1 | - First coordinate in line. |
p2 | - Second coordinate in line. |
point | - coordinate for which distance to line is sought. |
|
static |
Dot produce of three dimensional vectors.
p1 | vector 1 |
p2 | vector 2 |
|
static |
Dot produce of three dimensional vectors.
p1 | vector 1 |
p2 | vector 2 |
|
static |
Calculate the factorial for a number.
n | - the number. |
|
static |
Determine if an integer is an odd number.
number | Integer to test. |
|
static |
Determine if an integer is an odd number.
number | Integer to test. |
|
static |
Limit the "value" to be inclusively between the minimum and maximum.
value | - Value for testing. |
minimumValue | - Minimum inclusive value. |
maximumValue | - Maximum inclusive value. |
|
static |
Limit the "value" to be inclusively between the minimum and maximum.
value | - Value for testing. |
minimumValue | - Minimum inclusive value. |
maximumValue | - Maximum inclusive value. |
|
static |
Limit the "value" to be inclusively between the minimum and maximum.
value | - Value for testing. |
minimumValue | - Minimum inclusive value. |
maximumValue | - Maximum inclusive value. |
|
static |
Determine if 2D line segments intersect. Algorithm from http://mathworld.wolfram.com/Line-LineIntersection.html
p1 | Line 1 end point 1. |
p2 | Line 1 end point 2. |
q1 | Line 2 end point 1. |
q2 | Line 2 end point 2. |
tolerance | Tolerance around the vertices (essentially lengthens lines by this quantity). Caret5 set this parameter to 0.01. |
intersectionOut | Location of intersection. |
|
static |
Cross product of two 3D vectors with normalizing both the input and output vectors.
x1 | The first vector, an array of three floats. |
x2 | The first vector, an array of three floats. |
|
static |
Normalize a 3D vector (make its length 1.0).
vectorInOut | vector that is normalized. |
|
static |
Normalize a 3D vector (make its length 1.0).
vectorInOut | vector that is normalized. |
|
static |
Normalize a 3D vector (make its length 1.0).
vectorsAll | Array containing the XYZ components of the vectors. |
offset | Offset of the vector's X-component in the vectorsAll array. |
|
static |
Compute a normal vector from three vertices and make it a unit vector.
v1 | the first vertex, an array of three floats. |
v2 | the first vertex, an array of three floats. |
v3 | the first vertex, an array of three floats. |
normalVectorOut | A three-dimensional array passed into which the normal vector is loaded. |
|
static |
Compute a normal vector from three vertices and make it a unit vector.
v1 | the first vertex, an array of three floats. |
v2 | the first vertex, an array of three floats. |
v3 | the first vertex, an array of three floats. |
normalVectorOut | A three-dimensional array passed into which the normal vector is loaded. |
|
static |
Compute a normal vector from three vertices and but the returned vector IS NOT a unit vector.
v1 | the first vertex, an array of three floats. |
v2 | the first vertex, an array of three floats. |
v3 | the first vertex, an array of three floats. |
|
static |
Calulate the number of permuations for choosing "k" elements from a total of "n" elements.
Formula: [n!/(n-m)!] = n(n-1)(n-2)...(n-m+1).
n | - total number of elements. |
k | - number of elements to choose. |
|
static |
Project a point to a plane.
pt | - the point to project. |
origin | - point in the plane. |
normal | - normal vector of plane. |
projectedPointOut | - output, the projected position of "pt" on the plane. |
|
static |
Determine if a ray intersects a plane.
p1 | - 1st point defining the plane |
p2 | - 2nd point defining the plane |
p3 | - 3rd point defining the plane |
rayOrigin | - origin of the ray |
rayVector | - vector defining the ray |
intersectionXYZandDistance | - An array of four that will contain the XYZ or the intersection point and the distance from the plane. |
|
static |
Return the remainder from the resulting division using the given values.
This method is written to match the result produced by the remainder() function that is part of C99 but not supported on all platforms.
Code may appear verbose but it avoid functions calls to fabs(), ceil(), and floor().
Note: X is the numerator. Y is the denominator. The remainder() functions compute the value r such that r = x - n*y, where n is the integer nearest the exact value of x/y. If there are two integers closest to x/y, n shall be the even one.
numerator | The numerator. |
denominator | The denominator. |
|
static |
Return the value rounded to the nearest integral (integer) value.
value | Value that is rounded. |
|
static |
Signed angle for "jik".
pi | - point. |
pj | - point. |
pk | - point. |
n | - normal |
|
static |
Get the signed distance from the plane to the "queryPoint".
A positive distance indicates "queryPoint" is above the plane and a negative distance indicates "queryPoint" is below the plane.
planeNormal | - plane's normal vector. |
pointInPlane | - point on the plane. |
queryPoint | - the query point for which distance to plane is sought. |
|
static |
subtract vectors (3d) result = v1 - v2.
v1 | 1st vector input |
v2 | 2nd vector input |
resultOut | output, 3D vector containing result of subtraction. |
|
static |
Calculate the area for a triangle (with doubles)
v1 | - XYZ coordinates for vertex 1 |
v2 | - XYZ coordinates for vertex 2 |
v3 | - XYZ coordinates for vertex 3 |
|
static |
Calculate the area for a triangle.
v1 | - XYZ coordinates for vertex 1 |
v2 | - XYZ coordinates for vertex 2 |
v3 | - XYZ coordinates for vertex 3 |
|
static |
Calculate the area of a triangle formed by 3 coordinates.
xyzAll | One-dimensional array containing the XYZ coordinates. |
offsetCoord1 | Offset of node 1's X-coordinate which is followed by the Y- and Z-coordinates. |
offsetCoord2 | Offset of node 2's X-coordinate which is followed by the Y- and Z-coordinates. |
offsetCoord3 | Offset of node 3's X-coordinate which is followed by the Y- and Z-coordinates. |
|
static |
Compute the signed area of a triangle in 2D.
p1 | - 1st coordinate of triangle |
p2 | - 2nd coordinate of triangle |
p3 | - 3rd coordinate of triangle |
|
static |
Compute the signed area of a triangle in 3D.
referenceNormal | - Normal vector. |
p1 | - 1st coordinate of triangle |
p2 | - 2nd coordinate of triangle |
p3 | - 3rd coordinate of triangle |
|
static |
Get length of vector.
vector | Vector whose length is computed. |
|
static |
Get length of vector.
vector | Vector whose length is computed. |
|
static |
Get length of vector.
vectorsAll | Array containing three-dimensional vectors. |
offset | Offset of vector's X-component in vectorsAll array. |