src/util/WWMath.js
function (line, equatorialRadius, polarRadius, result) {
                if (!line) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath",
                        "computeEllipsoidalGlobeIntersection", "missingLine"));
                }

                if (!result) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath",
                        "computeEllipsoidalGlobeIntersection", "missingResult"));
                }

                // Taken from "Mathematics for 3D Game Programming and Computer Graphics, Second Edition", Section 5.2.3.
                //
                // Note that the parameter n from in equations 5.70 and 5.71 is omitted here. For an ellipsoidal globe this
                // parameter is always 1, so its square and its product with any other value simplifies to the identity.

                var vx = line.direction[0],
                    vy = line.direction[1],
                    vz = line.direction[2],
                    sx = line.origin[0],
                    sy = line.origin[1],
                    sz = line.origin[2],
                    m = equatorialRadius / polarRadius, // ratio of the x semi-axis length to the y semi-axis length
                    m2 = m * m,
                    r2 = equatorialRadius * equatorialRadius, // nominal radius squared
                    a = vx * vx + m2 * vy * vy + vz * vz,
                    b = 2 * (sx * vx + m2 * sy * vy + sz * vz),
                    c = sx * sx + m2 * sy * sy + sz * sz - r2,
                    d = b * b - 4 * a * c, // discriminant
                    t;

                if (d < 0) {
                    return false;
                }
                else {
                    t = (-b - Math.sqrt(d)) / (2 * a);
                    result[0] = sx + vx * t;
                    result[1] = sy + vy * t;
                    result[2] = sz + vz * t;
                    return true;
                }
            }
function (line, equatorialRadius, polarRadius, result) {
                if (!line) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath",
                        "computeEllipsoidalGlobeIntersection", "missingLine"));
                }

                if (!result) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath",
                        "computeEllipsoidalGlobeIntersection", "missingResult"));
                }

                // Taken from "Mathematics for 3D Game Programming and Computer Graphics, Second Edition", Section 5.2.3.
                //
                // Note that the parameter n from in equations 5.70 and 5.71 is omitted here. For an ellipsoidal globe this
                // parameter is always 1, so its square and its product with any other value simplifies to the identity.

                var vx = line.direction[0],
                    vy = line.direction[1],
                    vz = line.direction[2],
                    sx = line.origin[0],
                    sy = line.origin[1],
                    sz = line.origin[2],
                    m = equatorialRadius / polarRadius, // ratio of the x semi-axis length to the y semi-axis length
                    m2 = m * m,
                    r2 = equatorialRadius * equatorialRadius, // nominal radius squared
                    a = vx * vx + m2 * vy * vy + vz * vz,
                    b = 2 * (sx * vx + m2 * sy * vy + sz * vz),
                    c = sx * sx + m2 * sy * sy + sz * sz - r2,
                    d = b * b - 4 * a * c, // discriminant
                    t;

                if (d < 0) {
                    return false;
                }
                else {
                    t = (-b - Math.sqrt(d)) / (2 * a);
                    result[0] = sx + vx * t;
                    result[1] = sy + vy * t;
                    result[2] = sz + vz * t;
                    return true;
                }
            }
function ( line , equatorialRadius , polarRadius , result ) { if ( ! line ) { throw new ArgumentError ( Logger . logMessage ( Logger . LEVEL_SEVERE , "WWMath" , "computeEllipsoidalGlobeIntersection" , "missingLine" ) ) ; } if ( ! result ) { throw new ArgumentError ( Logger . logMessage ( Logger . LEVEL_SEVERE , "WWMath" , "computeEllipsoidalGlobeIntersection" , "missingResult" ) ) ; } // Taken from "Mathematics for 3D Game Programming and Computer Graphics, Second Edition", Section 5.2.3. // // Note that the parameter n from in equations 5.70 and 5.71 is omitted here. For an ellipsoidal globe this // parameter is always 1, so its square and its product with any other value simplifies to the identity. var vx = line . direction [ 0 ] , vy = line . direction [ 1 ] , vz = line . direction [ 2 ] , sx = line . origin [ 0 ] , sy = line . origin [ 1 ] , sz = line . origin [ 2 ] , m = equatorialRadius / polarRadius , // ratio of the x semi-axis length to the y semi-axis length m2 = m * m , r2 = equatorialRadius * equatorialRadius , // nominal radius squared a = vx * vx + m2 * vy * vy + vz * vz , b = 2 * ( sx * vx + m2 * sy * vy + sz * vz ) , c = sx * sx + m2 * sy * sy + sz * sz - r2 , d = b * b - 4 * a * c , // discriminant t ; if ( d < 0 ) { return false ; } else { t = ( - b - Math . sqrt ( d ) ) / ( 2 * a ) ; result [ 0 ] = sx + vx * t ; result [ 1 ] = sy + vy * t ; result [ 2 ] = sz + vz * t ; return true ; } }
Computes the Cartesian intersection point of a specified line with an ellipsoid.
@param {Line} line The line for which to compute the intersection.
@param {Number} equatorialRadius The ellipsoid's major radius.
@param {Number} polarRadius The ellipsoid's minor radius.
@param {Vec3} result A pre-allocated Vec3 instance in which to return the computed point.
@returns {boolean} true if the line intersects the ellipsoid, otherwise false
@throws {ArgumentError} If the specified line or result is null or undefined.
@deprecated utilize the Globe.intersectsLine method attached implementation
Computes the Cartesian intersection point of a specified line with an ellipsoid .