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


Java Vector2D.scalarMultiply方法代码示例

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


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

示例1: setPreferredVelocities

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入方法依赖的package包/类
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,代码行数:21,代码来源:Blocks.java

示例2: makeCircles

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入方法依赖的package包/类
public static List<Vector2D> makeCircles(int samples, boolean shuffle, double noise, double factor, final RandomGenerator random) {
    if (factor < 0 || factor > 1) {
        throw new IllegalArgumentException();
    }
    
    NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9);

    List<Vector2D> points = new ArrayList<Vector2D>();
    double range = 2.0 * FastMath.PI;
    double step = range / (samples / 2.0 + 1);
    for (double angle = 0; angle < range; angle += step) {
        Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle));
        Vector2D innerCircle = outerCircle.scalarMultiply(factor);
        
        points.add(outerCircle.add(generateNoiseVector(dist)));
        points.add(innerCircle.add(generateNoiseVector(dist)));
    }
    
    if (shuffle) {
        Collections.shuffle(points, new RandomAdaptor(random));
    }

    return points;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:ClusterAlgorithmComparison.java

示例3: linearProgram2

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入方法依赖的package包/类
/**
 * Solves a two-dimensional linear program subject to linear constraints
 * defined by lines and a circular constraint.
 *
 * @param lines                Lines defining the linear constraints.
 * @param optimizationVelocity The optimization velocity.
 * @param optimizeDirection    True if the direction should be optimized.
 * @return The number of the line on which it fails, or the number of lines
 * if successful.
 */
private int linearProgram2(List<Line> lines, Vector2D optimizationVelocity, boolean optimizeDirection) {
    if (optimizeDirection) {
        // Optimize direction. Note that the optimization velocity is of unit length in this case.
        newVelocity = optimizationVelocity.scalarMultiply(maxSpeed);
    } else if (optimizationVelocity.getNormSq() > maxSpeed * maxSpeed) {
        // Optimize closest point and outside circle.
        newVelocity = optimizationVelocity.normalize().scalarMultiply(maxSpeed);
    } else {
        // Optimize closest point and inside circle.
        newVelocity = optimizationVelocity;
    }

    for (int lineNo = 0; lineNo < lines.size(); lineNo++) {
        if (RVOMath.det(lines.get(lineNo).direction, lines.get(lineNo).point.subtract(newVelocity)) > 0.0) {
            // Result does not satisfy constraint i. Compute new optimal
            // result.
            final Vector2D tempResult = newVelocity;
            if (!linearProgram1(lines, lineNo, optimizationVelocity, optimizeDirection)) {
                newVelocity = tempResult;

                return lineNo;
            }
        }
    }

    return lines.size();
}
 
开发者ID:snape,项目名称:RVO2-Java,代码行数:38,代码来源:Agent.java

示例4: setPreferredVelocities

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:snape,项目名称:RVO2-Java,代码行数:15,代码来源:Circle.java


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