本文整理汇总了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)));
}
}
示例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;
}
示例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();
}
示例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);
}
}