EdenMath
IntroductionMath utilities. DiscussionEdenMath forms one part of the Eden library. Functions
EdenMathCalcDistanceToPlaneCaclulate signed distance from point to a plane. float EdenMathCalcDistanceToPlane( const float x0[3], const float abc[3], const float d); ParametersReturn ValueThe distance from the point to the plane, which is positive if the point lies on the same side of the plane as the normal to the plane, or negative if it lies on the opposite side, or 0 if the parameters are invalid. DiscussionSee http://mathworld.wolfram.com/Point-PlaneDistance.html EdenMathIdentityMatrixCreates a 4x4 identity matrix. void EdenMathIdentityMatrix( float mtx16[16]); ParametersEdenMathIdentityMatrix3by3Creates a 3x3 identity matrix. void EdenMathIdentityMatrix3by3( float mtx9[9]); ParametersEdenMathIntersectionLinePlaneCalculate the point of intersection (if any) between a line and a plane. EDEN_BOOL EdenMathIntersectionLinePlane( float intersection[3], float *u_out, const float p1[3], const float p2[3], const float abc[3], const float d); Parameters
Return ValueFALSE if the normal to the plane is perpendicular to the line, or if a required value was not specified, TRUE otherwise. DiscussionSee http://mathworld.wolfram.com/Plane.html EdenMathInvertMatrixCompute inverse of 4x4 transformation matrix EDEN_BOOL EdenMathInvertMatrix( float out[16], const float m[16]); ParametersReturn ValueReturn TRUE for success, FALSE for failure (singular matrix) DiscussionCode contributed by Jacques Leroy jle@star.be EdenMathInvertMatrix3by3Invert a 3x3 matrix A, placing result in Ainv. EDEN_BOOL EdenMathInvertMatrix3by3( float A[9], float Ainv[9]); DiscussionA and Ainv are in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) EdenMathInvertMatrixdCompute inverse of 4x4 transformation matrix EDEN_BOOL EdenMathInvertMatrixd( double out[16], const double m[16]); ParametersReturn ValueReturn TRUE for success, FALSE for failure (singular matrix) DiscussionCode contributed by Jacques Leroy jle@star.be EdenMathMultMatrixMultiplies 4x4 matrix B into 4x4 matrix A, placing result in C. void EdenMathMultMatrix( float C[16], const float B[16], const float A[16]); DiscussionA, B and C are in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) EdenMathMultMatrix3by3Multiplies 3x3 matrix B into 3x3 matrix A, placing result in C. void EdenMathMultMatrix3by3( float C[9], const float B[9], const float A[9]); DiscussionA, B and C are in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) EdenMathMultMatrixByVectorMultiples 4x4 matrix A into column vector p, placing result in q. void EdenMathMultMatrixByVector( float q[4], const float A[16], const float p[4]); DiscussionA is in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) EdenMathMultMatrixByVectordMultiples 4x4 matrix A into column vector p, placing result in q. void EdenMathMultMatrixByVectord( double q[4], const double A[16], const double p[4]); DiscussionA is in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) EdenMathMultMatrixdMultiplies 4x4 matrix B into 4x4 matrix A, placing result in C. void EdenMathMultMatrixd( double C[16], const double B[16], const double A[16]); DiscussionA, B and C are in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) EdenMathNormaliseNormalise a vector. float EdenMathNormalise( float v[3]); ParametersEdenMathNormalisedNormalise a vector. double EdenMathNormalised( double v[3]); ParametersEdenMathPointsToPlaneCalculate the general form of a plane, given three points lying on the plane. void EdenMathPointsToPlane( float abc[3], float *d, const float p1[3], const float p2[3], const float p3[3]); ParametersDiscussionThe general form of a plane is the equation Ax + By + Cz + D = 0. The plane is specified by three vectors which are points on the plane. The vector ABC is normal to the plane (not unit normal though). See http://mathworld.wolfram.com/Plane.html EdenMathPointsToPlaneHessianNormalCalculates the Hessian normal (unit normal vector) to a plane. void EdenMathPointsToPlaneHessianNormal( float n[3], float *p, const float p1[3], const float p2[3], const float p3[3]); Parameters
DiscussionThe plane is specified by three vectors which are points on the plane. The normal calculated is of unit length (i.e. it is the Hessian normal). See http://mathworld.wolfram.com/HessianNormalForm.html EdenMathRotateMatrixRotate a matrix about an arbitrary axis. void EdenMathRotateMatrix( float B[16], const float A[16], const float q, const float x, const float y, const float z); Parameters
Discussion(description) EdenMathRotatePointAboutAxisRotate a point about an arbitrary axis. void EdenMathRotatePointAboutAxis( float p2[3], const float p1[3], const float q, const float a[3]); ParametersEdenMathRotatePointAboutAxisdRotate a point about an arbitrary axis. void EdenMathRotatePointAboutAxisd( double p2[3], const double p1[3], const double q, const double a[3]); ParametersEdenMathRotationMatrixCreates a matrix which represents the general case of a rotation about an arbitrary axis. void EdenMathRotationMatrix( float mtx16[16], const float q, const float x, const float y, const float z); Parameters
EdenMathRotationMatrixFromToCreates a rotation matrix that rotates a vector called "from" into another vector called "to". void EdenMathRotationMatrixFromTo( const float from[3], const float to[3], float mtx9[9]); ParametersDiscussionAuthor: Tomas Moller, 1999 EdenMathTranslateMatrixTranslate a matrix by a vector. void EdenMathTranslateMatrix( float B[16], const float A[16], const float x, const float y, const float z); ParametersEdenMathTranslationMatrixCreates a matrix which represents translation by a vector. void EdenMathTranslationMatrix( float mtx16[16], const float x, const float y, const float z); ParametersfrsqrtFast calculation of reciprocal square root. void frsqrt( double *arg); ParametersDiscussionUses a ppc-only instruction to get an estimate of the reciprocal square root, then performs 4 iterations of Newton-Rhapson refinement to give better precision. Note: these functions are not IEEE-754 compliant and do not calculate the last bit correctly. For correct accuary, refer to libm on MacOS X. Written by A. Sazegari, started on February 2002. Copyright 2002 Apple Computer, Inc. All rights reserved.
frsqrt3Fast calculation of three reciprocal square roots. void frsqrt3( double *arg1, double *arg2, double *arg3); Parameters
DiscussionUses a ppc-only instruction to get an estimate of the reciprocal square root, then performs 4 iterations of Newton-Rhapson refinement to give better precision. Note: these functions are not IEEE-754 compliant and do not calculate the last bit correctly. For correct accuary, refer to libm on MacOS X. Written by A. Sazegari, started on February 2002. Copyright 2002 Apple Computer, Inc. All rights reserved.
fsqrtFast calculation of square root. void fsqrt( double *arg); ParametersDiscussionUses a ppc-only instruction to get an estimate of the square root, then performs 4 iterations of Newton-Rhapson refinement to give better precision. Note: these functions are not IEEE-754 compliant and do not calculate the last bit correctly. For correct accuary, refer to libm on MacOS X. Written by A. Sazegari, started on February 2002. Copyright 2002 Apple Computer, Inc. All rights reserved.
fsqrt3Fast calculation of three square roots. void fsqrt3( double *arg1, double *arg2, double *arg3); Parameters
DiscussionUses a ppc-only instruction to get an estimate of the square root, then performs 4 iterations of Newton-Rhapson refinement to give better precision. Note: these functions are not IEEE-754 compliant and do not calculate the last bit correctly. For correct accuary, refer to libm on MacOS X. Written by A. Sazegari, started on February 2002. Copyright 2002 Apple Computer, Inc. All rights reserved.
Macro Definitions
ADD(description) #define ADD(dest,v1,v2) Discussion(description) AVERAGE(description) #define AVERAGE(dest,v1,v2) Discussion(description) COPY(description) Discussion(description) CROSSVector cross-product in R3. #define CROSS(dest,v1,v2) Discussion6 multiplies + 3 subtracts. Vector cross product calculates a vector with direction orthogonal to plane formed by the other two vectors, and length equal to the area of the parallelogram formed by the other two vectors. Right hand rule for vector cross products: Point thumb of right hand in direction of v1, fingers together in direction of v2, then palm faces in the direction of dest. DOTVector dot-product in R3. #define DOT(v1,v2) Discussion3 multiplies + 2 adds. DTORConvert degrees to radians. #define DTOR 0.0174532925 DiscussionMultiply an angle in degrees by this constant to get the value of the angle in radians. HALFPI(description) #define HALFPI Discussion(description) LENGTH(description) Discussion(description) M_PIValue of PI. #define M_PI 3.141592653589793238462643 DiscussionDefined only if not already defined in math.h. MAXDetermine maximum of two values. MINDetermine minimum of two values. PIValue of PI. RTODConvert radians to degrees. #define RTOD 57.2957795 DiscussionMultiply an angle in radians by this constant to get the value of the angle in degrees. SUB(description) #define SUB(dest,v1,v2) Discussion(description) TWOPI(description) #define TWOPI Discussion(description) |