Get the vector with the highest down slope in the plan.
@param normal
@param epsilon
@return the steepest vector.
970931
public static Vector3D getSteepestVector(final Vector3D normal, final double epsilon) {
        if (Math.abs(normal.getX()) < epsilon && Math.abs(normal.getY()) < epsilon) {
            return new Vector3D(0, 0, 0);
        }
        Vector3D slope;
        if (Math.abs(normal.getX()) < epsilon) {
            slope = new Vector3D(0, 1, -normal.getY() / normal.getZ());
        } else if (Math.abs(normal.getY()) < epsilon) {
            slope = new Vector3D(1, 0, -normal.getX() / normal.getZ());
        } else {
            slope = new Vector3D(normal.getX() / normal.getY(), 1,
                    -1 / normal.getZ() * (normal.getX() * normal.getX() / normal.getY() + normal.getY()));
        }
        //We want the vector to be low-oriented.
        if (slope.getZ() > epsilon) {
            slope = new Vector3D(-slope.getX(), -slope.getY(), -slope.getZ());
        }
        //We normalize it
        return slope.normalize();
    }
405619
function( t ) {

		var delta = 0.0001;
		var t1 = t - delta;
		var t2 = t + delta;

		// Capping in case of danger

		if ( t1 < 0 ) t1 = 0;
		if ( t2 > 1 ) t2 = 1;

		var pt1 = this.getPoint( t1 );
		var pt2 = this.getPoint( t2 );

		var vec = pt2.clone().sub( pt1 );
		return vec.normalize();

	}
319116
public Plane fromPoints (IVector3 p1, IVector3 p2, IVector3 p3) {
        // compute the normal by taking the cross product of the two vectors formed
        p2.subtract(p1, _v1);
        p3.subtract(p1, _v2);
        _v1.cross(_v2, _normal).normalizeLocal();

        // use the first point to determine the constant
        constant = -_normal.dot(p1);
        return this;
    }
1272551
function inclination( vector ) {

		return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );

	}
1211435
protected DoubleMatrix2D getGradFi(DoubleMatrix1D X) {
		DoubleMatrix2D ret = F2.make(request.getFi().length, X.size());
		double[] x = X.toArray();
		for(int i=0; i<request.getFi().length; i++){
			ret.viewRow(i).assign(request.getFi()[i].gradient(x));
		}
		return ret;
	}
1008981
def normalLines(actor, ratio=1, c=(0.6, 0.6, 0.6), alpha=0.8):
    
    maskPts = vtk.vtkMaskPoints()
    maskPts.SetOnRatio(ratio)
    maskPts.RandomModeOff()
    actor = actor.computeNormals()
    src = actor.polydata()
    maskPts.SetInputData(src)
    arrow = vtk.vtkLineSource()
    arrow.SetPoint1(0, 0, 0)
    arrow.SetPoint2(0.75, 0, 0)
    glyph = vtk.vtkGlyph3D()
    glyph.SetSourceConnection(arrow.GetOutputPort())
    glyph.SetInputConnection(maskPts.GetOutputPort())
    glyph.SetVectorModeToUseNormal()
    b = src.GetBounds()
    sc = max([b[1] - b[0], b[3] - b[2], b[5] - b[4]]) / 20.0
    glyph.SetScaleFactor(sc)
    glyph.OrientOn()
    glyph.Update()
    glyphActor = Actor(glyph.GetOutput(), c=vc.getColor(c), alpha=alpha)
    glyphActor.mapper.SetScalarModeToUsePointFieldData()
    glyphActor.PickableOff()
    prop = vtk.vtkProperty()
    prop.DeepCopy(actor.GetProperty())
    glyphActor.SetProperty(prop)
    return glyphActor
459563
public ImageScale lookup( double sigma ) {
		ImageScale best = null;
		double bestValue = Double.MAX_VALUE;

		for (int i = 0; i < usedScales.size(); i++) {
			ImageScale image = usedScales.get(i);
			double difference = Math.abs(sigma-image.sigma);
			if( difference < bestValue ) {
				bestValue = difference;
				best = image;
			}
		}
		return best;
	}
920389
public static int getMaxIndex(DoubleMatrix1D v){
	  	int maxIndex = -1;
	  	double maxValue = -Double.MAX_VALUE;
	  	for(int i=0; i<v.size(); i++){
	  		if(v.getQuick(i)>maxValue){
	  			maxIndex = i;
	  			maxValue = v.getQuick(i); 
	  		}
	  	}
	  	return maxIndex; 
	  }
325206
public double calculateDistance(S individual, double[] lambda,
                                  double[] z_, double[] nz_) {

    double scale;
    double distance;

    double[] vecInd = new double[problem.getNumberOfObjectives()];
    double[] vecProj = new double[problem.getNumberOfObjectives()];

    // normalize the weight vector (line segment)
    double nd = norm_vector(lambda);
    for (int i = 0; i < problem.getNumberOfObjectives(); i++) {
      lambda[i] = lambda[i] / nd;
    }

    // vecInd has been normalized to the range [0,1]
    for (int i = 0; i < problem.getNumberOfObjectives(); i++) {
      vecInd[i] = (individual.getObjective(i) - z_[i]) / (nz_[i] - z_[i]);
    }

    scale = innerproduct(vecInd, lambda);
    for (int i = 0; i < problem.getNumberOfObjectives(); i++) {
      vecProj[i] = vecInd[i] - scale * lambda[i];
    }

    distance = norm_vector(vecProj);

    return distance;
  }
443572
public static boolean epsilonEquals (IVector v1, IVector v2, float epsilon) {
        return Math.abs(v1.x() - v2.x()) <= epsilon && Math.abs(v1.y() - v2.y()) <= epsilon;
    }
1277565
public void findBestValEntropy(Node node, DoubleVector classCountL, DoubleVector classCountR,
			boolean status, double minEntropy, DoubleVector parentCCLeft ){
		if (this.root != null) {
			if (node != null) {
				int numClass=0;
				DoubleVector classCountLTemp = new DoubleVector(); 
				DoubleVector classCountRTemp = new DoubleVector(); 
				DoubleVector parentCCL = new DoubleVector();
				DoubleVector parentCCLParameter = new DoubleVector();
				for (int f = 0; f < node.classCountsLeft.numValues(); f++) {
					parentCCLParameter.setValue(f, node.classCountsLeft.getValue(f));
					}
				for (int p = 0; p < parentCCLeft.numValues(); p++) {
					parentCCL.addToValue(p, parentCCLeft.getValue(p));
					}
				if (classCountL.numValues() >= classCountR.numValues()) {
					numClass = classCountL.numValues();
				} else {
					numClass = classCountR.numValues();
				}
				// Counting the real class count left and the real class count right.
				if (node.cut_point != this.root.cut_point) {
					for (int i = 0; i < numClass; i++) {
						if (status == true) {		// Left node.
							double parentss = parentCCL.getValue(i) - (node.classCountsLeft.getValue(i) 
									+ node.classCountsRight.getValue(i));
						    double left = classCountL.getValue(i) 
						    		- node.classCountsRight.getValue(i) - parentss;
						    double right = classCountR.getValue(i) 
						    		+ node.classCountsRight.getValue(i) + parentss;
						    classCountLTemp.addToValue(i, left);
					        classCountRTemp.addToValue(i, right);
					        }
						if (status == false) {		// Right node.
							double left = classCountL.getValue(i)+ node.classCountsLeft.getValue(i);
							double right = classCountR.getValue(i)- node.classCountsLeft.getValue(i);
							classCountLTemp.addToValue(i, left);
							classCountRTemp.addToValue(i, right);
							}
						}
					} else {
						classCountLTemp = classCountL;
						classCountRTemp = classCountR;
						}
				double classCountLSum = classCountLTemp.sumOfValues();
				double classCountRSum = classCountRTemp.sumOfValues();
				double numInst = this.root.classCountsLeft.sumOfValues() + this.root.classCountsRight.sumOfValues();
				// The entropy value for all nodes except for the root.
				if ((classCountLSum > this.PminOption.getValue()*numInst) 
						&& (classCountRSum > this.PminOption.getValue() * numInst)) {
					double classCountLEntropy = entropy( classCountLTemp);   // Entropy of class count left.
					double classCountREntropy = entropy(classCountRTemp);    // Entropy of class count right
					if (((classCountLSum / numInst) * classCountLEntropy + (classCountRSum / numInst)* classCountREntropy) <= minEntropy) {
						this.minEntropyTemp = (classCountLSum / numInst) * classCountLEntropy 
								+ (classCountRSum / numInst) * classCountREntropy;
						this.cutPointTemp = node.cut_point;
						if (classCountLEntropy <= classCountREntropy) {
							this.symbol = -1.0;
							double value = 0.0;
							double index = 0.0;
							for (int h = 0; h < numClass; h++) {
								if (value <= classCountLTemp.getValue(h)) {
									value = classCountLTemp.getValue(h);
					    			index = (double)h;
					    			}
								}
							this.saveBestEntropy.setValue(0, this.cutPointTemp);
							this.saveBestEntropy.setValue(1, classCountLEntropy);
							this.saveBestEntropy.setValue(2, this.symbol);
							this.saveBestEntropy.setValue(4, index);
					    	} else {
					    		this.symbol = 1.0;
					    		double value = 0.0;
					    		double index = 0.0;
					    		for (int h = 0; h < numClass; h++) {
					    			if (value <= classCountRTemp.getValue(h)) {
					    				value = classCountRTemp.getValue(h);
					    				index = (double)h;
					    				}
					    			}
					    		this.saveBestEntropy.setValue(0, this.cutPointTemp);
					    		this.saveBestEntropy.setValue(1, classCountREntropy);
					    		this.saveBestEntropy.setValue(2, this.symbol);
					    		this.saveBestEntropy.setValue(4, index);
						    	}
						}
					}
				findBestValEntropy(node.left ,classCountLTemp , classCountRTemp,
						true, this.minEntropyTemp, parentCCLParameter);
				findBestValEntropy(node.right ,classCountLTemp , classCountRTemp,
						false, this.minEntropyTemp, parentCCLParameter);
				}
			}
		}
792102
def inclination(vector)
      Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z))
    end
631561
function InfiniteCylinder3D( x , y , z , nx , ny , nz , r ) {
	this.axis = new BoundVector3D( x , y , z , nx , ny , nz ).normalizeCheck() ;
	this.r = + r ;
}
1233441
public double getMaxDist(VectorApproximation vec) {
    final int dim = lookup.length;
    double maxDist = 0;
    for(int d = 0; d < dim; d++) {
      final int vp = vec.getApproximation(d);
      maxDist += getPartialMaxDist(d, vp);
    }
    return FastMath.pow(maxDist, onebyp);
  }
190809
public static Vector getMaximum(Vector v1, Vector v2) {
        return new Vector(Math.max(v1.x, v2.x), Math.max(v1.y, v2.y), Math.max(v1.z, v2.z));
    }
684500
public static Vector3D getNormalVector(Triangle t) throws IllegalArgumentException {
        if(Double.isNaN(t.p0.z) || Double.isNaN(t.p1.z) ||  Double.isNaN(t.p2.z)) {
            throw new IllegalArgumentException("Z is required, cannot compute triangle normal of "+t);
        }
        double dx1 = t.p0.x - t.p1.x;
        double dy1 = t.p0.y - t.p1.y;
        double dz1 = t.p0.z - t.p1.z;
        double dx2 = t.p1.x - t.p2.x;
        double dy2 = t.p1.y - t.p2.y;
        double dz2 = t.p1.z - t.p2.z;
        return Vector3D.create(dy1*dz2 - dz1*dy2, dz1 * dx2 - dx1 * dz2, dx1 * dy2 - dy1 * dx2).normalize();
    }
670339
def nearly_eq(valA, valB, maxf=None, minf=None, epsilon=None):
    '''
    
    '''

    if valA == valB:
        return True

    if maxf is None:
        maxf = float_info.max

    if minf is None:
        minf = float_info.min

    if epsilon is None:
        epsilon = float_info.epsilon

    absA = abs(valA)
    absB = abs(valB)
    delta = abs(valA - valB)

    if (valA == 0) or (valB == 0) or (delta < minf):
        return delta < (epsilon * minf)

    return (delta / min(absA + absB, maxf)) < (epsilon * 2)