| # EdenMath
Includes: | <math.h>
## Introduction Math utilities. ##### Discussion EdenMath forms one part of the Eden library. ## Functions `EdenMathCalcDistanceToPlane` Caclulate signed distance from point to a plane. `EdenMathIdentityMatrix` Creates a 4x4 identity matrix. `EdenMathIdentityMatrix3by3` Creates a 3x3 identity matrix. `EdenMathIntersectionLinePlane` Calculate the point of intersection (if any) between a line and a plane. `EdenMathInvertMatrix` Compute inverse of 4x4 transformation matrix `EdenMathInvertMatrix3by3` Invert a 3x3 matrix A, placing result in Ainv. `EdenMathInvertMatrixd` Compute inverse of 4x4 transformation matrix `EdenMathMultMatrix` Multiplies 4x4 matrix B into 4x4 matrix A, placing result in C. `EdenMathMultMatrix3by3` Multiplies 3x3 matrix B into 3x3 matrix A, placing result in C. `EdenMathMultMatrixByVector` Multiples 4x4 matrix A into column vector p, placing result in q. `EdenMathMultMatrixByVectord` Multiples 4x4 matrix A into column vector p, placing result in q. `EdenMathMultMatrixd` Multiplies 4x4 matrix B into 4x4 matrix A, placing result in C. `EdenMathNormalise` Normalise a vector. `EdenMathNormalised` Normalise a vector. `EdenMathPointsToPlane` Calculate the general form of a plane, given three points lying on the plane. `EdenMathPointsToPlaneHessianNormal` Calculates the Hessian normal (unit normal vector) to a plane. `EdenMathRotateMatrix` Rotate a matrix about an arbitrary axis. `EdenMathRotatePointAboutAxis` Rotate a point about an arbitrary axis. `EdenMathRotatePointAboutAxisd` Rotate a point about an arbitrary axis. `EdenMathRotationMatrix` Creates a matrix which represents the general case of a rotation about an arbitrary axis. `EdenMathRotationMatrixFromTo` Creates a rotation matrix that rotates a vector called "from" into another vector called "to". `EdenMathTranslateMatrix` Translate a matrix by a vector. `EdenMathTranslationMatrix` Creates a matrix which represents translation by a vector. `frsqrt` Fast calculation of reciprocal square root. `frsqrt3` Fast calculation of three reciprocal square roots. `fsqrt` Fast calculation of square root. `fsqrt3` Fast calculation of three square roots. ### EdenMathCalcDistanceToPlane Caclulate signed distance from point to a plane.
    float EdenMathCalcDistanceToPlane(
        const float x0[3],
        const float abc[3],
        const float d);
##### Parameters `x0` Position of the point. `abc` The vector of values A, B, and C from the general definition of a plane Ax + By + Cz + D = 0 (see EdenMathPointsToPlane()). The value D from the general definition of a plane Ax + By + Cz + D = 0 (see EdenMathPointsToPlane()). ##### Return Value The 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. ##### Discussion See http://mathworld.wolfram.com/Point-PlaneDistance.html ### EdenMathIdentityMatrix Creates a 4x4 identity matrix.
    void EdenMathIdentityMatrix(
        float mtx16[16]);
##### Parameters `mtx16` A 4x4 matrix that will receive the output. ### EdenMathIdentityMatrix3by3 Creates a 3x3 identity matrix.
    void EdenMathIdentityMatrix3by3(
        float mtx9[9]);
##### Parameters `mtx9` A 3x3 matrix that will receive the output. ### EdenMathIntersectionLinePlane Calculate 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 `intersection` Pointer to an array of 3 floats which will be filled out with the coordinates of the point of intersection. `u_out` If non-null, the float pointed to will be filled out with the value 'u', representing the point of intersection, relative to the line segement between p1 and p2. I.e., when u is 0, the intersection is at p1, and when u is 1 the intersection is at p2. Values of u < 0 or > 1 indicate the intersection point is outside the line segment (but there IS still an intersection point). NULL may be passed if you are not interested in this value. `p1` A point lying on the line. `p2` Another point lying on the line. `abc` The vector of values A, B, and C from the general definition of a plane Ax + By + Cz + D = 0 (see EdenMathPointsToPlane()). The value D from the general definition of a plane Ax + By + Cz + D = 0 (see EdenMathPointsToPlane()). ##### Return Value FALSE if the normal to the plane is perpendicular to the line, or if a required value was not specified, TRUE otherwise. ##### Discussion See http://mathworld.wolfram.com/Plane.html ### EdenMathInvertMatrix Compute inverse of 4x4 transformation matrix
    EDEN_BOOL EdenMathInvertMatrix(
        float out[16],
        const float m[16]);
##### Parameters `m` Input, 4x4 column-major matrix. `out` Output, 4x4 column-major matrix. ##### Return Value Return TRUE for success, FALSE for failure (singular matrix) ##### Discussion Code contributed by Jacques Leroy jle@star.be ### EdenMathInvertMatrix3by3 Invert a 3x3 matrix A, placing result in Ainv.
    EDEN_BOOL EdenMathInvertMatrix3by3(
        float A[9],
        float Ainv[9]);
##### Discussion A and Ainv are in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) ### EdenMathInvertMatrixd Compute inverse of 4x4 transformation matrix
    EDEN_BOOL EdenMathInvertMatrixd(
        double out[16],
        const double m[16]);
##### Parameters `m` Input, 4x4 column-major matrix. `out` Output, 4x4 column-major matrix. ##### Return Value Return TRUE for success, FALSE for failure (singular matrix) ##### Discussion Code contributed by Jacques Leroy jle@star.be ### EdenMathMultMatrix Multiplies 4x4 matrix B into 4x4 matrix A, placing result in C.
    void EdenMathMultMatrix(
        float C[16],
        const float B[16],
        const float A[16]);
##### Discussion A, B and C are in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) ### EdenMathMultMatrix3by3 Multiplies 3x3 matrix B into 3x3 matrix A, placing result in C.
    void EdenMathMultMatrix3by3(
        float C[9],
        const float B[9],
        const float A[9]);
##### Discussion A, B and C are in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) ### EdenMathMultMatrixByVector Multiples 4x4 matrix A into column vector p, placing result in q.
    void EdenMathMultMatrixByVector(
        float q[4],
        const float A[16],
        const float p[4]);
##### Discussion A is in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) ### EdenMathMultMatrixByVectord Multiples 4x4 matrix A into column vector p, placing result in q.
    void EdenMathMultMatrixByVectord(
        double q[4],
        const double A[16],
        const double p[4]);
##### Discussion A is in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) ### EdenMathMultMatrixd Multiplies 4x4 matrix B into 4x4 matrix A, placing result in C.
    void EdenMathMultMatrixd(
        double C[16],
        const double B[16],
        const double A[16]);
##### Discussion A, B and C are in column-major form, which is standard for OpenGL (wheras the usual mathematical matrix notation is row-major.) ### EdenMathNormalise Normalise a vector.
    float EdenMathNormalise(
        float v[3]);
##### Parameters `v` Vector to normalise. ### EdenMathNormalised Normalise a vector.
    double EdenMathNormalised(
        double v[3]);
##### Parameters `v` Vector to normalise. ### EdenMathPointsToPlane Calculate 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]);
##### Parameters `abc` Vector describing the plane. `d` Value describing the plane. `p1` Vector describing point on the plane. `p2` Vector describing point on the plane. `p3` Vector describing point on the plane. ##### Discussion The 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 ### EdenMathPointsToPlaneHessianNormal Calculates 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 `n` Vector representing Hessian normal (unit normal vector) to plane. `p` Value of distance of plane from origin. The sign of *p determines the side of the plane on which the origin is located. If > 0, it is in the half-space determined by the direction of n, and if < 0, it is in the other half-space. `p1` Vector describing point on the plane. `p2` Vector describing point on the plane. `p3` Vector describing point on the plane. ##### Discussion The 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 ### EdenMathRotateMatrix Rotate 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 `B` A 4x4 matrix that will receive the output in column major form. `A` A 4x4 matrix that will supply the input in column major form. `q` The angle of rotation measured in a right-hand sense, in radians. `x` X component of the normalised non-zero vector representing the axis of rotation. `y` Y component of the normalised non-zero vector representing the axis of rotation. `z` Z component of the normalised non-zero vector representing the axis of rotation. ##### Discussion (description) ### EdenMathRotatePointAboutAxis Rotate a point about an arbitrary axis.
    void EdenMathRotatePointAboutAxis(
        float p2[3],
        const float p1[3],
        const float q,
        const float a[3]);
##### Parameters `p2` Rotated point. `p1` Point to rotate. `q` The angle of rotation measured in a right-hand sense, in radians. `a` Normalised non-zero vector representing the axis of rotation. ### EdenMathRotatePointAboutAxisd Rotate a point about an arbitrary axis.
    void EdenMathRotatePointAboutAxisd(
        double p2[3],
        const double p1[3],
        const double q,
        const double a[3]);
##### Parameters `p2` Rotated point. `p1` Point to rotate. `q` The angle of rotation measured in a right-hand sense, in radians. `a` Normalised non-zero vector representing the axis of rotation. ### EdenMathRotationMatrix Creates 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 `mtx16` A 4x4 matrix that will receive the output in column major form. `q` The angle of rotation measured in a right-hand sense, in radians. `x` X component of the normalised non-zero vector representing the axis of rotation. `y` Y component of the normalised non-zero vector representing the axis of rotation. `z` Z component of the normalised non-zero vector representing the axis of rotation. ### EdenMathRotationMatrixFromTo Creates 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]);
##### Parameters `from` Normalised non-zero vector. `to` Normalised non-zero vector. `mtx9` A 3x3 matrix in column-major form which receives the result. ##### Discussion Author: Tomas Moller, 1999 ### EdenMathTranslateMatrix Translate a matrix by a vector.
    void EdenMathTranslateMatrix(
        float B[16],
        const float A[16],
        const float x,
        const float y,
        const float z);
##### Parameters `B` A 4x4 matrix that will receive the output in column major form. `A` A 4x4 matrix that will supply the input in column major form. `x` X component of the translation vector. `y` Y component of the translation vector. `z` Z component of the translation vector. ### EdenMathTranslationMatrix Creates a matrix which represents translation by a vector.
    void EdenMathTranslationMatrix(
        float mtx16[16],
        const float x,
        const float y,
        const float z);
##### Parameters `mtx16` A 4x4 matrix that will receive the output in column major form. `x` X component of the translation vector. `y` Y component of the translation vector. `z` Z component of the translation vector. ### frsqrt Fast calculation of reciprocal square root.
    void frsqrt(
        double *arg);
##### Parameters `arg` Pointer to double-precision floating point number. Will be replaced with the reciprocal of the root of the number. (*arg = (*arg)^-0.5). ##### Discussion Uses 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. Availability Available on PowerPC CPUs only. ### frsqrt3 Fast calculation of three reciprocal square roots.
    void frsqrt3(
        double *arg1,
        double *arg2,
        double *arg3);
##### Parameters `arg1` Pointer to double-precision floating point number. Will be replaced with the reciprocal of the root of the number. `arg2` Pointer to double-precision floating point number. Will be replaced with the reciprocal of the root of the number. `arg3` Pointer to double-precision floating point number. Will be replaced with the reciprocal of the root of the number. ##### Discussion Uses 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. Availability Available on PowerPC CPUs only. ### fsqrt Fast calculation of square root.
    void fsqrt(
        double *arg);
##### Parameters `arg` Pointer to double-precision floating point number. Will be replaced with the root of the number. (*arg = (*arg)^0.5). ##### Discussion Uses 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. Availability Available on PowerPC CPUs only. ### fsqrt3 Fast calculation of three square roots.
    void fsqrt3(
        double *arg1,
        double *arg2,
        double *arg3);
##### Parameters `arg1` Pointer to double-precision floating point number. Will be replaced with the root of the number. `arg2` Pointer to double-precision floating point number. Will be replaced with the root of the number. `arg3` Pointer to double-precision floating point number. Will be replaced with the root of the number. ##### Discussion Uses 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. Availability Available on PowerPC CPUs only. ## Macro Definitions `ADD` (description) `AVERAGE` (description) `COPY` (description) `CROSS` Vector cross-product in R3. `DOT` Vector dot-product in R3. `DTOR` Convert degrees to radians. `HALFPI` (description) `LENGTH` (description) `M_PI` Value of PI. `MAX` Determine maximum of two values. `MIN` Determine minimum of two values. `PI` Value of PI. `RTOD` Convert radians to degrees. `SUB` (description) `TWOPI` (description) ### ADD (description)
    #define ADD(dest,v1,v2)
##### Discussion (description) ### AVERAGE (description)
    #define AVERAGE(dest,v1,v2)
##### Discussion (description) ### COPY (description)
    #define COPY(dest, v)
##### Discussion (description) ### CROSS Vector cross-product in R3.
    #define CROSS(dest,v1,v2)
##### Discussion 6 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. ### DOT Vector dot-product in R3.
    #define DOT(v1,v2)
##### Discussion 3 multiplies + 2 adds. ### DTOR Convert degrees to radians.
    #define DTOR 0.0174532925
##### Discussion Multiply an angle in degrees by this constant to get the value of the angle in radians. ### HALFPI (description)
    #define HALFPI
##### Discussion (description) ### LENGTH (description)
    #define LENGTH(v)
##### Discussion (description) ### M_PI Value of PI.
    #define M_PI 3.141592653589793238462643
##### Discussion Defined only if not already defined in math.h. ### MAX Determine maximum of two values.
    #ifndef MAX
    #define MAX(x,y)
    #endif
### MIN Determine minimum of two values.
    #ifndef MIN
    #define MIN(x,y)
    #endif
### PI Value of PI.
    #define PI M_PI
### RTOD Convert radians to degrees.
    #define RTOD 57.2957795
##### Discussion Multiply 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) © 2001-2013 Philip Lamb Last Updated: Monday, October 05, 2015