当前位置: 首页>>代码示例>>Java>>正文


Java FastMath.PI属性代码示例

本文整理汇总了Java中org.apache.commons.math3.util.FastMath.PI属性的典型用法代码示例。如果您正苦于以下问题:Java FastMath.PI属性的具体用法?Java FastMath.PI怎么用?Java FastMath.PI使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.commons.math3.util.FastMath的用法示例。


在下文中一共展示了FastMath.PI属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setPreferredVelocities

private void setPreferredVelocities() {
    // Set the preferred velocity to be a vector of unit magnitude (speed)
    // in the direction of the goal.
    for (int agentNo = 0; agentNo < Simulator.instance.getNumAgents(); agentNo++) {
        Vector2D goalVector = goals.get(agentNo).subtract(Simulator.instance.getAgentPosition(agentNo));
        final double lengthSq = goalVector.getNormSq();

        if (lengthSq > 1.0) {
            goalVector = goalVector.scalarMultiply(1.0 / FastMath.sqrt(lengthSq));
        }

        Simulator.instance.setAgentPreferredVelocity(agentNo, goalVector);

        // Perturb a little to avoid deadlocks due to perfect symmetry.
        final double angle = random.nextDouble() * 2.0 * FastMath.PI;
        final double distance = random.nextDouble() * 0.0001;

        Simulator.instance.setAgentPreferredVelocity(agentNo, Simulator.instance.getAgentPreferredVelocity(agentNo).add(new Vector2D(FastMath.cos(angle), FastMath.sin(angle)).scalarMultiply(distance)));
    }
}
 
开发者ID:snape,项目名称:RVO2-Java,代码行数:20,代码来源:Blocks.java

示例2: setupScenario

private void setupScenario() {
    // Specify the global time step of the simulation.
    Simulator.instance.setTimeStep(0.25);

    // Specify the default parameters for agents that are subsequently
    // added.
    Simulator.instance.setAgentDefaults(15.0, 10, 10.0, 10.0, 1.5, 2.0, Vector2D.ZERO);

    // Add agents, specifying their start position, and store their goals on
    // the opposite side of the environment.
    final double angle = 0.008 * FastMath.PI;

    for (int i = 0; i < 250; i++) {
        Simulator.instance.addAgent(new Vector2D(FastMath.cos(i * angle), FastMath.sin(i * angle)).scalarMultiply(200.0));
        goals.add(Simulator.instance.getAgentPosition(i).negate());
    }
}
 
开发者ID:snape,项目名称:RVO2-Java,代码行数:17,代码来源:Circle.java

示例3: Arc

/** Simple constructor.
 * <p>
 * If either {@code lower} is equals to {@code upper} or
 * the interval exceeds \( 2 \pi \), the arc is considered
 * to be the full circle and its initial defining boundaries
 * will be forgotten. {@code lower} is not allowed to be
 * greater than {@code upper} (an exception is thrown in this case).
 * {@code lower} will be canonicalized between 0 and \( 2 \pi \), and
 * upper shifted accordingly, so the {@link #getInf()} and {@link #getSup()}
 * may not return the value used at instance construction.
 * </p>
 * @param lower lower angular bound of the arc
 * @param upper upper angular bound of the arc
 * @param tolerance tolerance below which angles are considered identical
 * @exception NumberIsTooLargeException if lower is greater than upper
 */
public Arc(final double lower, final double upper, final double tolerance)
    throws NumberIsTooLargeException {
    this.tolerance = tolerance;
    if (Precision.equals(lower, upper, 0) || (upper - lower) >= MathUtils.TWO_PI) {
        // the arc must cover the whole circle
        this.lower  = 0;
        this.upper  = MathUtils.TWO_PI;
        this.middle = FastMath.PI;
    } else  if (lower <= upper) {
        this.lower  = MathUtils.normalizeAngle(lower, FastMath.PI);
        this.upper  = this.lower + (upper - lower);
        this.middle = 0.5 * (this.lower + this.upper);
    } else {
        throw new NumberIsTooLargeException(LocalizedFormats.ENDPOINTS_NOT_AN_INTERVAL,
                                            lower, upper, true);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:Arc.java

示例4: angle

/** Compute the angular separation between two vectors.
 * <p>This method computes the angular separation between two
 * vectors using the dot product for well separated vectors and the
 * cross product for almost aligned vectors. This allows to have a
 * good accuracy in all cases, even for vectors very close to each
 * other.</p>
 * @param v1 first vector
 * @param v2 second vector
 * @return angular separation between v1 and v2
 * @exception MathArithmeticException if either vector has a null norm
 */
public static double angle(Vector2D v1, Vector2D v2) throws MathArithmeticException {

    double normProduct = v1.getNorm() * v2.getNorm();
    if (normProduct == 0) {
        throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
    }

    double dot = v1.dotProduct(v2);
    double threshold = normProduct * 0.9999;
    if ((dot < -threshold) || (dot > threshold)) {
        // the vectors are almost aligned, compute using the sine
        final double n = FastMath.abs(MathArrays.linearCombination(v1.x, v2.y, -v1.y, v2.x));
        if (dot >= 0) {
            return FastMath.asin(n / normProduct);
        }
        return FastMath.PI - FastMath.asin(n / normProduct);
    }

    // the vectors are sufficiently separated to use the cosine
    return FastMath.acos(dot / normProduct);

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:Vector2D.java

示例5: vector

/** Build the normalized vector corresponding to spherical coordinates.
 * @param theta azimuthal angle \( \theta \) in the x-y plane
 * @param phi polar angle \( \varphi \)
 * @return normalized vector
 * @exception OutOfRangeException if \( \varphi \) is not in the [\( 0; \pi \)] range
 */
private static Vector3D vector(final double theta, final double phi)
   throws OutOfRangeException {

    if (phi < 0 || phi > FastMath.PI) {
        throw new OutOfRangeException(phi, 0, FastMath.PI);
    }

    final double cosTheta = FastMath.cos(theta);
    final double sinTheta = FastMath.sin(theta);
    final double cosPhi   = FastMath.cos(phi);
    final double sinPhi   = FastMath.sin(phi);

    return new Vector3D(cosTheta * sinPhi, sinTheta * sinPhi, cosPhi);

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:21,代码来源:S2Point.java

示例6: angle

/** Compute the angular separation between two vectors.
 * <p>This method computes the angular separation between two
 * vectors using the dot product for well separated vectors and the
 * cross product for almost aligned vectors. This allows to have a
 * good accuracy in all cases, even for vectors very close to each
 * other.</p>
 * @param v1 first vector
 * @param v2 second vector
 * @return angular separation between v1 and v2
 * @exception MathArithmeticException if either vector has a null norm
 */
public static double angle(Vector3D v1, Vector3D v2) throws MathArithmeticException {

    double normProduct = v1.getNorm() * v2.getNorm();
    if (normProduct == 0) {
        throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
    }

    double dot = v1.dotProduct(v2);
    double threshold = normProduct * 0.9999;
    if ((dot < -threshold) || (dot > threshold)) {
        // the vectors are almost aligned, compute using the sine
        Vector3D v3 = crossProduct(v1, v2);
        if (dot >= 0) {
            return FastMath.asin(v3.getNorm() / normProduct);
        }
        return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct);
    }

    // the vectors are sufficiently separated to use the cosine
    return FastMath.acos(dot / normProduct);

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:Vector3D.java

示例7: reset

/** Reset the instance as if built from two points.
 * <p>The line is oriented from p1 to p2</p>
 * @param p1 first point
 * @param p2 second point
 */
public void reset(final Vector2D p1, final Vector2D p2) {
    unlinkReverse();
    final double dx = p2.getX() - p1.getX();
    final double dy = p2.getY() - p1.getY();
    final double d = FastMath.hypot(dx, dy);
    if (d == 0.0) {
        angle        = 0.0;
        cos          = 1.0;
        sin          = 0.0;
        originOffset = p1.getY();
    } else {
        angle        = FastMath.PI + FastMath.atan2(-dy, -dx);
        cos          = dx / d;
        sin          = dy / d;
        originOffset = MathArrays.linearCombination(p2.getX(), p1.getY(), -p1.getX(), p2.getY()) / d;
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:22,代码来源:Line.java

示例8: Geoid

public Geoid(double lat,double lon,double h){
	this.lat=lat;
	this.lon=lon;
	this.latRad=lat*FastMath.PI/180;
	this.lonRad=lon*FastMath.PI/180;
	this.h=h;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:7,代码来源:GeoUtils.java

示例9: distance

/**
 * 
 * @param lon1
 * @param lat1
 * @param lon2
 * @param lat2 
 * @return calculate the distance between 2 points
 */
public static double distance(double lon1, double lat1, double lon2, double lat2){
	lon1=(lon1*FastMath.PI)/180;
	lat1=(lat1*FastMath.PI)/180;
	
	lon2=(lon2*FastMath.PI)/180;
	lat2=(lat2*FastMath.PI)/180;
    
	return distanceRad(lon1,lat1,lon2,lat2);
	
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:18,代码来源:GeoUtils.java

示例10: GammaDistribution

/**
 * Creates a Gamma distribution.
 *
 * @param rng Random number generator.
 * @param shape the shape parameter
 * @param scale the scale parameter
 * @param inverseCumAccuracy the maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 * @since 3.1
 */
public GammaDistribution(RandomGenerator rng,
                         double shape,
                         double scale,
                         double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (shape <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
    }
    if (scale <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
    }

    this.shape = shape;
    this.scale = scale;
    this.solverAbsoluteAccuracy = inverseCumAccuracy;
    this.shiftedShape = shape + Gamma.LANCZOS_G + 0.5;
    final double aux = FastMath.E / (2.0 * FastMath.PI * shiftedShape);
    this.densityPrefactor2 = shape * FastMath.sqrt(aux) / Gamma.lanczos(shape);
    this.logDensityPrefactor2 = FastMath.log(shape) + 0.5 * FastMath.log(aux) -
                                FastMath.log(Gamma.lanczos(shape));
    this.densityPrefactor1 = this.densityPrefactor2 / scale *
            FastMath.pow(shiftedShape, -shape) *
            FastMath.exp(shape + Gamma.LANCZOS_G);
    this.logDensityPrefactor1 = this.logDensityPrefactor2 - FastMath.log(scale) -
            FastMath.log(shiftedShape) * shape +
            shape + Gamma.LANCZOS_G;
    this.minY = shape + Gamma.LANCZOS_G - FastMath.log(Double.MAX_VALUE);
    this.maxLogY = FastMath.log(Double.MAX_VALUE) / (shape - 1.0);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:44,代码来源:GammaDistribution.java

示例11: value

/** {@inheritDoc} */
public double value(final double x) {
    final double scaledX = normalized ? FastMath.PI * x : x;
    if (FastMath.abs(scaledX) <= SHORTCUT) {
        // use Taylor series
        final double scaledX2 = scaledX * scaledX;
        return ((scaledX2 - 20) * scaledX2 + 120) / 120;
    } else {
        // use definition expression
        return FastMath.sin(scaledX) / scaledX;
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:12,代码来源:Sinc.java

示例12: convexCellArea

/** Compute convex cell area.
 * @param start start vertex of the convex cell boundary
 * @return area
 */
private double convexCellArea(final Vertex start) {

    int n = 0;
    double sum = 0;

    // loop around the cell
    for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) {

        // find path interior angle at vertex
        final Vector3D previousPole = e.getCircle().getPole();
        final Vector3D nextPole     = e.getEnd().getOutgoing().getCircle().getPole();
        final Vector3D point        = e.getEnd().getLocation().getVector();
        double alpha = FastMath.atan2(Vector3D.dotProduct(nextPole, Vector3D.crossProduct(point, previousPole)),
                                      -Vector3D.dotProduct(nextPole, previousPole));
        if (alpha < 0) {
            alpha += MathUtils.TWO_PI;
        }
        sum += alpha;
        n++;
    }

    // compute area using extended Girard theorem
    // see Spherical Trigonometry: For the Use of Colleges and Schools by I. Todhunter
    // article 99 in chapter VIII Area Of a Spherical Triangle. Spherical Excess.
    // book available from project Gutenberg at http://www.gutenberg.org/ebooks/19770
    return sum - (n - 2) * FastMath.PI;

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:PropertiesComputer.java

示例13: nthRoot

/**
 * Computes the n-th roots of this complex number.
 * The nth roots are defined by the formula:
 * <pre>
 *  <code>
 *   z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2&pi;k/n) + i (sin(phi + 2&pi;k/n))
 *  </code>
 * </pre>
 * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi}
 * are respectively the {@link #abs() modulus} and
 * {@link #getArgument() argument} of this complex number.
 * <p>
 * If one or both parts of this complex number is NaN, a list with just
 * one element, {@link #NaN} is returned.
 * if neither part is NaN, but at least one part is infinite, the result
 * is a one-element list containing {@link #INF}.
 *
 * @param n Degree of root.
 * @return a List of all {@code n}-th roots of {@code this}.
 * @throws NotPositiveException if {@code n <= 0}.
 * @since 2.0
 */
public List<Complex> nthRoot(int n) throws NotPositiveException {

    if (n <= 0) {
        throw new NotPositiveException(LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N,
                                       n);
    }

    final List<Complex> result = new ArrayList<Complex>();

    if (isNaN) {
        result.add(NaN);
        return result;
    }
    if (isInfinite()) {
        result.add(INF);
        return result;
    }

    // nth root of abs -- faster / more accurate to use a solver here?
    final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n);

    // Compute nth roots of complex number with k = 0, 1, ... n-1
    final double nthPhi = getArgument() / n;
    final double slice = 2 * FastMath.PI / n;
    double innerPart = nthPhi;
    for (int k = 0; k < n ; k++) {
        // inner part
        final double realPart = nthRootOfAbs *  FastMath.cos(innerPart);
        final double imaginaryPart = nthRootOfAbs *  FastMath.sin(innerPart);
        result.add(createComplex(realPart, imaginaryPart));
        innerPart += slice;
    }

    return result;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:57,代码来源:Complex.java

示例14: revertSelf

/** Revert the instance.
 */
public void revertSelf() {
    unlinkReverse();
    if (angle < FastMath.PI) {
        angle += FastMath.PI;
    } else {
        angle -= FastMath.PI;
    }
    cos          = -cos;
    sin          = -sin;
    originOffset = -originOffset;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:13,代码来源:Line.java

示例15: getGeoidHOptimized

/**
 * search a point with distance<50 from the (lon,lat) parameter and return the geoid height  
 * 
 * @param lon
 * @param lat
 * @return the geoid Height for a point (lon,lat)
 */
public static double  getGeoidHOptimized(Geoid[][] gpoints,final double lon,final double lat){
	double h=0;
	
	double lonRad=lon*FastMath.PI/180;
	double latRad=lat*FastMath.PI/180;
	
	boolean finded=false;
	
	for(int row=0;row<geoidPoints.length&&!finded;row++){
		int middle=geoidPoints[0].length/2;
		Geoid geoRow[]=geoidPoints[row];
		//first value
		Geoid g=geoRow[middle];
		double middleDist = distanceRad(lonRad,latRad,g.lonRad,g.latRad);
		double oldDist =middleDist; 
	    if(middleDist<75){
	    	h= g.h;
	    }else{
	    	int left=0;
			int right=geoidPoints[0].length;
			
			for(;right-left>1;){
				int middleLeft=(left+middle)/2;
				int middleRight=middle+(right-middle)/2;
				
				double middleDistL = distanceRad(lonRad,latRad,geoRow[middleLeft].lonRad,geoRow[middleLeft].latRad);
				double middleDistR = distanceRad(lonRad,latRad,geoRow[middleRight].lonRad,geoRow[middleRight].latRad);
				if(middleDistL<middleDistR){
					right=middle;
					middle=left+(right-left)/2;
					middleDist=middleDistL;
				}else{
					left=middle;
					middle=left+(right-left)/2;
					middleDist=middleDistR;
				}
				if(middleDist<75&&oldDist>middleDist){
				//if(oldDist>middleDist){
					//finded=true;
					oldDist=middleDist;
			    	h=geoRow[middle].h;
			    	//System.out.println("D:"+middleDist+" - H:"+h+" - lon,lat:"+geoRow[middle].lonRad+","+geoRow[middle].lonRad);
			    	break;
			    }
			}
	    }
	}    
 //   System.out.println("H:"+h);
	return h;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:57,代码来源:GeoUtils.java


注:本文中的org.apache.commons.math3.util.FastMath.PI属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。