Computes the theta & phi angles of the vector.
@memberof Vec3#
@returns {object} ret
@returns {Number} ret.theta - angle from the xz plane
@returns {Number} ret.phi - angle from the y axis
39
function() {
        return {
            theta: Math.atan2(this.z, this.x),
            phi: Math.asin(this.y / this.length())
        };
    }
75128
function () {

		function isEarAt( vertex ) {

			var prevX = vertex.mprev.vFrom.x;
			var prevY = vertex.mprev.vFrom.y;

			var vertX = vertex.vFrom.x;
			var vertY = vertex.vFrom.y;

			var nextX = vertex.mnext.vFrom.x;
			var nextY = vertex.mnext.vFrom.y;

			var vnX = nextX - vertX,  vnY = nextY - vertY;
			var npX = prevX - nextX,  npY = prevY - nextY;
			var pvX = vertX - prevX,  pvY = vertY - prevY;

			// concave angle at vertex -> not an ear to cut off
			if ( PNLTRI.Math.EPSILON_P > ( ( pvX * vnY ) - ( vnX * pvY ) ) ) return false;

			// check whether any other point lieas within the triangle abc
			var vStop	= vertex.mprev.mprev;
			var vOther	= vertex.mnext;
			while ( vOther != vStop ) {
				vOther = vOther.mnext;
				var otherX = vOther.vFrom.x;
				var otherY = vOther.vFrom.y;

				var poX = otherX - prevX,  poY = otherY - prevY;
					// just in case there are several vertices with the same coordinate
					if ( ( poX === 0 ) && ( poY === 0 ) )		continue;	// vOther == vertex.mprev
				var voX = otherX - vertX,  voY = otherY - vertY;
					if ( ( voX === 0 ) && ( voY === 0 ) )		continue;	// vOther == vertex
				var noX = otherX - nextX,  noY = otherY - nextY;
					if ( ( noX === 0 ) && ( noY === 0 ) )		continue;	// vOther == vertex.mnext

				// if vOther is inside triangle abc -> not an ear to cut off
				if ( ( ( vnX * voY - vnY * voX ) >= PNLTRI.Math.EPSILON_N ) &&
					 ( ( pvX * poY - pvY * poX ) >= PNLTRI.Math.EPSILON_N ) &&
					 ( ( npX * noY - npY * noX ) >= PNLTRI.Math.EPSILON_N ) ) return false;
			}
			return true;

		}

		var myPolyData = this.polyData;
		var startSeg = myPolyData.getFirstSegment();

		// create a counter-clockwise ordered doubly linked list (monoChain links)

		var cursor = startSeg;
		if ( myPolyData.isClockWise( startSeg ) ) {
			do {	// reverses chain order
				cursor.mprev = cursor.snext;
				cursor.mnext = cursor.sprev;
				cursor = cursor.sprev;
			} while ( cursor != startSeg );
			myPolyData.set_PolyLeft_wrong(0);
		} else {
			do {
				cursor.mprev = cursor.sprev;
				cursor.mnext = cursor.snext;
				cursor = cursor.snext;
			} while ( cursor != startSeg );
		}

		//  remove all vertices except 2, creating 1 triangle every time

		var vertex = startSeg;
		var fullLoop = vertex;   // prevent infinite loop on "defective" polygons

		while ( vertex.mnext != vertex.mprev ) {
			if ( isEarAt( vertex ) ) {
				// found a triangle ear to cut off
				this.polyData.addTriangle( vertex.mprev.vFrom, vertex.vFrom, vertex.mnext.vFrom );
				// remove vertex from the remaining chain
				vertex.mprev.mnext = vertex.mnext;
				vertex.mnext.mprev = vertex.mprev;
				vertex = vertex.mnext;
				fullLoop = vertex;			// reset error detection
			} else {
				vertex = vertex.mnext;
				// loop?: probably non-simple polygon -> stop with error
				if ( vertex == fullLoop )	return false;
			}
		}

		return true;

	}
932534
def coords_to_vec(lon, lat):
    
    phi = np.radians(lon)
    theta = (np.pi / 2) - np.radians(lat)
    sin_t = np.sin(theta)
    cos_t = np.cos(theta)

    xVals = sin_t * np.cos(phi)
    yVals = sin_t * np.sin(phi)
    zVals = cos_t

    # Stack them into the output array
    out = np.vstack((xVals, yVals, zVals)).swapaxes(0, 1)
    return out
281373
def rodrigues_axis_angle_rotate(x, vec, theta):
    
    x = np.array(x).T
    vec = np.array(vec).T
    theta = np.array(theta).T[...,None]

    out = np.cos(theta)*x + np.sin(theta)*np.cross(vec, x) + \
        (1 - np.cos(theta)) * (vec * x).sum(axis=-1)[...,None] * vec

    return out.T
1139026
function (v) {
            var _vz = v.z || 0;
            return this._set((this.x < v.x) ? this.x : v.x, (this.y < v.y) ? this.y : v.y, (this.z < _vz) ? this.z : _vz);
        }
912299
function(obj) {
                if (obj.normal || (obj.start && obj.end)) { return obj.isParallelTo(this); }
                var theta = this.direction.angleFrom(obj.direction);
                return (Math.abs(theta) <= sylvester.precision || Math.abs(theta - Math.PI) <= sylvester.precision);
              }
73572
public double getTheta() {
		double theta = StrictMath.toDegrees(StrictMath.atan2(y, x));
		if ((theta < -360) || (theta > 360)) {
			theta = theta % 360;
		}
		if (theta < 0) {
			theta = 360 + theta;
		}

		return theta;
	}
130223
function x(){function c(a,d){this.x=a||0;this.y=d||0}function B(a,d){this.pos=a||new c;this.r=d||0}function m(a,d){this.pos=a||new c;this.angle=0;this.offset=new c;this.u(d||[])}function p(a,d,b){this.pos=a||new c;this.w=d||0;this.h=b||0}function w(){this.b=this.a=null;this.overlapN=new c;this.overlapV=new c;this.clear()}function C(a,d,b){for(var g=Number.MAX_VALUE,c=-Number.MAX_VALUE,l=a.length,v=0;v<l;v++){var e=a[v].f(d);e<g&&(g=e);e>c&&(c=e)}b[0]=g;b[1]=c}function y(a,d,b,g,c,l){var k=q.pop(),
e=q.pop();a=h.pop().c(d).sub(a);d=a.f(c);C(b,c,k);C(g,c,e);e[0]+=d;e[1]+=d;if(k[0]>e[1]||e[0]>k[1])return h.push(a),q.push(k),q.push(e),!0;l&&(k[0]<e[0]?(l.aInB=!1,k[1]<e[1]?(b=k[1]-e[0],l.bInA=!1):(b=k[1]-e[0],g=e[1]-k[0],b=b<g?b:-g)):(l.bInA=!1,k[1]>e[1]?(b=k[0]-e[1],l.aInB=!1):(b=k[1]-e[0],g=e[1]-k[0],b=b<g?b:-g)),g=Math.abs(b),g<l.overlap&&(l.overlap=g,l.overlapN.c(c),0>b&&l.overlapN.reverse()));h.push(a);q.push(k);q.push(e);return!1}function z(a,d){var b=a.g(),g=d.f(a);return 0>g?-1:g>b?1:0}
function D(a,d,b){for(var g=h.pop().c(d.pos).sub(a.pos),c=d.r,l=c*c,v=a.calcPoints,e=v.length,t=h.pop(),f=h.pop(),m=0;m<e;m++){var u=m===e-1?0:m+1,q=0===m?e-1:m-1,p=0,r=null;t.c(a.edges[m]);f.c(g).sub(v[m]);b&&f.g()>l&&(b.aInB=!1);var n=z(t,f);if(-1===n){t.c(a.edges[q]);u=h.pop().c(g).sub(v[q]);n=z(t,u);if(1===n){n=f.j();if(n>c)return h.push(g),h.push(t),h.push(f),h.push(u),!1;b&&(b.bInA=!1,r=f.normalize(),p=c-n)}h.push(u)}else if(1===n){if(t.c(a.edges[u]),f.c(g).sub(v[u]),n=z(t,f),-1===n){n=f.j();
if(n>c)return h.push(g),h.push(t),h.push(f),!1;b&&(b.bInA=!1,r=f.normalize(),p=c-n)}}else{u=t.m().normalize();n=f.f(u);q=Math.abs(n);if(0<n&&q>c)return h.push(g),h.push(u),h.push(f),!1;b&&(r=u,p=c-n,0<=n||p<2*c)&&(b.bInA=!1)}r&&b&&Math.abs(p)<Math.abs(b.overlap)&&(b.overlap=p,b.overlapN.c(r))}b&&(b.a=a,b.b=d,b.overlapV.c(b.overlapN).scale(b.overlap));h.push(g);h.push(t);h.push(f);return!0}function E(a,d,b){for(var c=a.calcPoints,k=c.length,l=d.calcPoints,f=l.length,e=0;e<k;e++)if(y(a.pos,d.pos,c,
l,a.normals[e],b))return!1;for(e=0;e<f;e++)if(y(a.pos,d.pos,c,l,d.normals[e],b))return!1;b&&(b.a=a,b.b=d,b.overlapV.c(b.overlapN).scale(b.overlap));return!0}var f={};f.Vector=c;f.V=c;c.prototype.copy=c.prototype.c=function(a){this.x=a.x;this.y=a.y;return this};c.prototype.clone=c.prototype.clone=function(){return new c(this.x,this.y)};c.prototype.perp=c.prototype.m=function(){var a=this.x;this.x=this.y;this.y=-a;return this};c.prototype.rotate=c.prototype.rotate=function(a){var d=this.x,b=this.y;
this.x=d*Math.cos(a)-b*Math.sin(a);this.y=d*Math.sin(a)+b*Math.cos(a);return this};c.prototype.reverse=c.prototype.reverse=function(){this.x=-this.x;this.y=-this.y;return this};c.prototype.normalize=c.prototype.normalize=function(){var a=this.j();0<a&&(this.x/=a,this.y/=a);return this};c.prototype.add=c.prototype.add=function(a){this.x+=a.x;this.y+=a.y;return this};c.prototype.sub=c.prototype.sub=function(a){this.x-=a.x;this.y-=a.y;return this};c.prototype.scale=c.prototype.scale=function(a,d){this.x*=
a;this.y*="undefined"!=typeof d?d:a;return this};c.prototype.project=c.prototype.o=function(a){var d=this.f(a)/a.g();this.x=d*a.x;this.y=d*a.y;return this};c.prototype.projectN=c.prototype.s=function(a){var d=this.f(a);this.x=d*a.x;this.y=d*a.y;return this};c.prototype.reflect=function(a){var d=this.x,b=this.y;this.o(a).scale(2);this.x-=d;this.y-=b;return this};c.prototype.reflectN=function(a){var d=this.x,b=this.y;this.s(a).scale(2);this.x-=d;this.y-=b;return this};c.prototype.dot=c.prototype.f=
function(a){return this.x*a.x+this.y*a.y};c.prototype.len2=c.prototype.g=function(){return this.f(this)};c.prototype.len=c.prototype.j=function(){return Math.sqrt(this.g())};f.Circle=B;B.prototype.getAABB=function(){var a=this.r,d=this.pos.clone().sub(new c(a,a));return(new p(d,2*a,2*a)).l()};f.Polygon=m;m.prototype.setPoints=m.prototype.u=function(a){if(!this.points||this.points.length!==a.length){var d,b=this.calcPoints=[],g=this.edges=[],k=this.normals=[];for(d=0;d<a.length;d++)b.push(new c),g.push(new c),
k.push(new c)}this.points=a;this.i()};m.prototype.setAngle=function(a){this.angle=a;this.i();return this};m.prototype.setOffset=function(a){this.offset=a;this.i();return this};m.prototype.rotate=m.prototype.rotate=function(a){for(var d=this.points,b=d.length,c=0;c<b;c++)d[c].rotate(a);this.i();return this};m.prototype.translate=m.prototype.translate=function(a,d){for(var b=this.points,c=b.length,k=0;k<c;k++)b[k].x+=a,b[k].y+=d;this.i();return this};m.prototype.i=function(){var a=this.calcPoints,c=
this.edges,b=this.normals,g=this.points,k=this.offset,l=this.angle,f=g.length,e;for(e=0;e<f;e++){var h=a[e].c(g[e]);h.x+=k.x;h.y+=k.y;0!==l&&h.rotate(l)}for(e=0;e<f;e++)g=a[e],g=c[e].c(e<f-1?a[e+1]:a[0]).sub(g),b[e].c(g).m().normalize()};m.prototype.getAABB=function(){for(var a=this.calcPoints,d=a.length,b=a[0].x,g=a[0].y,k=a[0].x,l=a[0].y,f=1;f<d;f++){var e=a[f];e.x<b?b=e.x:e.x>k&&(k=e.x);e.y<g?g=e.y:e.y>l&&(l=e.y)}return(new p(this.pos.clone().add(new c(b,g)),k-b,l-g)).l()};m.prototype.getCentroid=
function(){for(var a=this.calcPoints,d=a.length,b=0,g=0,k=0,f=0;f<d;f++){var h=a[f],e=f===d-1?a[0]:a[f+1],m=h.x*e.y-e.x*h.y;b+=(h.x+e.x)*m;g+=(h.y+e.y)*m;k+=m}k*=3;return new c(b/k,g/k)};f.Box=p;p.prototype.toPolygon=p.prototype.l=function(){var a=this.pos,d=this.w,b=this.h;return new m(new c(a.x,a.y),[new c,new c(d,0),new c(d,b),new c(0,b)])};f.Response=w;w.prototype.clear=w.prototype.clear=function(){this.bInA=this.aInB=!0;this.overlap=Number.MAX_VALUE;return this};for(var h=[],r=0;10>r;r++)h.push(new c);
var q=[];for(r=0;5>r;r++)q.push([]);var A=new w,F=(new p(new c,1E-6,1E-6)).l();f.isSeparatingAxis=y;f.pointInCircle=function(a,c){var b=h.pop().c(a).sub(c.pos),d=c.r*c.r,f=b.g();h.push(b);return f<=d};f.pointInPolygon=function(a,c){F.pos.c(a);A.clear();var b=E(F,c,A);b&&(b=A.aInB);return b};f.testCircleCircle=function(a,c,b){var d=h.pop().c(c.pos).sub(a.pos),f=a.r+c.r,l=d.g();if(l>f*f)return h.push(d),!1;b&&(l=Math.sqrt(l),b.a=a,b.b=c,b.overlap=f-l,b.overlapN.c(d.normalize()),b.overlapV.c(d).scale(b.overlap),
b.aInB=a.r<=c.r&&l<=c.r-a.r,b.bInA=c.r<=a.r&&l<=a.r-c.r);h.push(d);return!0};f.testPolygonCircle=D;f.testCirclePolygon=function(a,c,b){if((a=D(c,a,b))&&b){c=b.a;var d=b.aInB;b.overlapN.reverse();b.overlapV.reverse();b.a=b.b;b.b=c;b.aInB=b.bInA;b.bInA=d}return a};f.testPolygonPolygon=E;return f}
328482
function() {
			// Get the x and y coordinates
			var xCoords = this.pluck('x');
			var yCoords = this.pluck('y');

			// Get the means for the x and y coordinates
			var meanX = xCoords.mean();
			var meanY = yCoords.mean();

			// Get the standard deviations for the x and y coordinates
			var stdDevX = xCoords.stdDev();
			var stdDevY = yCoords.stdDev();

			// Calculate the correlation coefficient
			var r = this.r();

			// Calculate the slope
			var slope = r * (stdDevY / stdDevX);

			// Calculate the y-intercept
			var yIntercept = meanY - slope * meanX;

			return {
				slope: slope,
				yIntercept: yIntercept,
				r: r
			};
		}
1011245
function angle(v) {
         return Math.acos(me.Math.clamp(this.dotProduct(v) / (this.length() * v.length()), -1, 1));
       }
405621
function getDirectionAngle(start, end, numDirections, grid, opt) {

        var quadrant = 360 / numDirections;
        var angleTheta = start.theta(fixAngleEnd(start, end, grid, opt));
        var normalizedAngle = g.normalizeAngle(angleTheta + (quadrant / 2));
        return quadrant * Math.floor(normalizedAngle / quadrant);
    }
1295840
function(v) {

      // [0, v'] = Q * [0, v] * Q'

      // Q
      var w1 = this['w'];
      var x1 = this['x'];
      var y1 = this['y'];
      var z1 = this['z'];

      // [0, v]
      var w2 = 0;
      var x2 = v[0];
      var y2 = v[1];
      var z2 = v[2];

      // Q * [0, v]
      var w3 = /*w1 * w2*/ -x1 * x2 - y1 * y2 - z1 * z2;
      var x3 = w1 * x2 + /*x1 * w2 +*/ y1 * z2 - z1 * y2;
      var y3 = w1 * y2 + /*y1 * w2 +*/ z1 * x2 - x1 * z2;
      var z3 = w1 * z2 + /*z1 * w2 +*/ x1 * y2 - y1 * x2;

      var w4 = w3 * w1 + x3 * x1 + y3 * y1 + z3 * z1;
      var x4 = x3 * w1 - w3 * x1 - y3 * z1 + z3 * y1;
      var y4 = y3 * w1 - w3 * y1 - z3 * x1 + x3 * z1;
      var z4 = z3 * w1 - w3 * z1 - x3 * y1 + y3 * x1;

      return [x4, y4, z4];
    }
278718
function() {
        var ox = this._origin.x + this._x,
            oy = this._origin.y + this._y,
            rad = -this._rotation * DEG_TO_RAD;
        // axis-aligned (unrotated) coordinates, relative to the origin point
        var dx1 = this._x - this._bx1 - ox,
            dx2 = this._x + this._w + this._bx2 - ox,
            dy1 = this._y - this._by1 - oy,
            dy2 = this._y + this._h + this._by2 - oy;

        var ct = rounded_cos(rad),
            st = rounded_sin(rad);

        // Calculate the new points relative to the origin, then find the new (absolute) bounding coordinates!
        var x0 = dx1 * ct + dy1 * st,
            y0 = -dx1 * st + dy1 * ct,
            x1 = dx2 * ct + dy1 * st,
            y1 = -dx2 * st + dy1 * ct,
            x2 = dx2 * ct + dy2 * st,
            y2 = -dx2 * st + dy2 * ct,
            x3 = dx1 * ct + dy2 * st,
            y3 = -dx1 * st + dy2 * ct,
            minx = Math.floor(Math.min(x0, x1, x2, x3) + ox),
            miny = Math.floor(Math.min(y0, y1, y2, y3) + oy),
            maxx = Math.ceil(Math.max(x0, x1, x2, x3) + ox),
            maxy = Math.ceil(Math.max(y0, y1, y2, y3) + oy);
        if (!this._mbr) {
            this._mbr = {
                _x: minx,
                _y: miny,
                _w: maxx - minx,
                _h: maxy - miny
            };
        } else {
            this._mbr._x = minx;
            this._mbr._y = miny;
            this._mbr._w = maxx - minx;
            this._mbr._h = maxy - miny;
        }

        // If a collision hitbox exists AND sits outside the entity, find a bounding box for both.
        // `_cbr` contains information about a bounding circle of the hitbox.
        // The bounds of `_cbr` will be the union of the `_mbr` and the bounding box of that circle.
        // This will not be a minimal region, but since it's only used for the broad phase pass it's good enough.
        //
        // cbr is calculated by the `_checkBounds` method of the "Collision" component
        if (this._cbr) {
            var cbr = this._cbr;
            var cx = cbr.cx,
                cy = cbr.cy,
                r = cbr.r;
            var cx2 = ox + (cx + this._x - ox) * ct + (cy + this._y - oy) * st;
            var cy2 = oy - (cx + this._x - ox) * st + (cy + this._y - oy) * ct;
            cbr._x = Math.min(cx2 - r, minx);
            cbr._y = Math.min(cy2 - r, miny);
            cbr._w = Math.max(cx2 + r, maxx) - cbr._x;
            cbr._h = Math.max(cy2 + r, maxy) - cbr._y;
        }
    }
1003681
def v_theta(self):
        
        # compute theta
        norm = np.sqrt(np.sum(self.wxyz**2))
        theta = 2 * np.arccos(self.wxyz[0] / norm)

        # compute the unit vector
        v = np.array(self.wxyz[1:])
        v = v / np.sqrt(np.sum(v**2))

        return v, theta
488489
@Pure
	public final double getAngle() {
		double mag = this.x*this.x + this.y*this.y + this.z*this.z;  

		if ( mag > EPS ) {
			mag = Math.sqrt(mag);
			return (2.f*Math.atan2(mag, this.w)); 
		}
		return 0f;
	}
532024
function(angles) {
      var s = this['SCALE'];
      
      // Basically treat each angle as a vector, add all the vecotrs up,
      // and return the angle of the resultant vector.

      var y = angles.map(a => Math.sin(a * TAU / s)).reduce((a, b) => a + b);
      var x = angles.map(a => Math.cos(a * TAU / s)).reduce((a, b) => a + b);
      
      // If the resultant vector is very short, this means the average angle is likely wrong or ambiguous.
      // For instance, what if a users asks for the average of the angles [0, PI]?
      
      // TODO: Warn user (or return undefined / null / NaN) when using opposite angles
      // Could be as simple as:
      //if (x * x + y * y < EPS * EPS) return NaN;

      return Math.atan2(y, x) * s / TAU;
    }
700356
function spherical2Cartesian(phi, theta) {
  const nPhi = parseFloat(phi);
  const nTheta = parseFloat(theta);
  const phiRad = (180.0 - nPhi) * (Math.PI / 180.0);
  const thetaRad = (180.0 - nTheta) * (Math.PI / 180.0);
  return [
    Math.sin(thetaRad) * Math.cos(phiRad),
    Math.sin(thetaRad) * Math.sin(phiRad),
    Math.cos(thetaRad),
  ];
}