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


Java Vector2D类代码示例

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


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

示例1: toDegrees

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
public static double toDegrees(Vector2D tempSum ) {

        double tempTangent = Math.abs(tempSum.getY().doubleValue()) / Math.abs(tempSum.getX().doubleValue());
        double tempDegrees = Math.toDegrees(Math.atan(tempTangent));

        if (tempSum.getX() >= 0 && tempSum.getY() >= 0) {
            tempDegrees += 0.0;
        } else if (tempSum.getX() <= 0 && tempSum.getY() >= 0) {
            tempDegrees += 90.0;
        } else if (tempSum.getX() <= 0 && tempSum.getY() <= 0) {
            tempDegrees += 180.0;
        } else if (tempSum.getX() >= 0 && tempSum.getY() <= 0) {
            tempDegrees += 270.0;
        }

        return tempDegrees;
    }
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:18,代码来源:MultiSteering.java

示例2: 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

示例3: setupScenario

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

示例4: addAgent

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
/**
 * Adds a new agent with default properties to the simulation.
 *
 * @param position The two-dimensional starting position of this agent.
 * @return The number of the agent, or -1 when the agent defaults have not
 * been set.
 */
public int addAgent(Vector2D position) {
    if (defaultAgent == null) {
        return -1;
    }

    final Agent agent = new Agent();
    agent.id = agents.size();
    agent.maxNeighbors = defaultAgent.maxNeighbors;
    agent.maxSpeed = defaultAgent.maxSpeed;
    agent.neighborDistance = defaultAgent.neighborDistance;
    agent.position = position;
    agent.radius = defaultAgent.radius;
    agent.timeHorizonAgents = defaultAgent.timeHorizonAgents;
    agent.timeHorizonObstacles = defaultAgent.timeHorizonObstacles;
    agent.velocity = defaultAgent.velocity;
    agents.add(agent);

    return agent.id;
}
 
开发者ID:snape,项目名称:RVO2-Java,代码行数:27,代码来源:Simulator.java

示例5: calculateDistance

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
public static double calculateDistance(double[] a, double[] b,
		double[] q) {
	final Vector2D ab = new Vector2D(b[0] - a[0], b[1] - a[1]);
	final Vector2D aq = new Vector2D(q[0] - a[0], q[1] - a[1]);
	final Vector2D bq = new Vector2D(q[0] - b[0], q[1] - b[1]);

	final double aqDotProduct = ab.dotProduct(aq);
	final double bqDotProduct = -ab.dotProduct(bq);
	
	if (aqDotProduct < 0)
	{
		return aq.getNorm();
	}
	else if (bqDotProduct < 0)
	{
		return bq.getNorm();
	}
	else
	{
		final Line line = new Line(new Vector2D(a), new Vector2D(b), 1.0e-10);
		return Math.abs(line.getOffset(new Vector2D(q)));
	}
}
 
开发者ID:highsource,项目名称:tenra,代码行数:24,代码来源:DistanceCalculator.java

示例6: boundaryFacet

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
/** Check if a point belongs to the boundary part of a node.
 * @param point point to check
 * @param node node containing the boundary facet to check
 * @return the boundary facet this points belongs to (or null if it
 * does not belong to any boundary facet)
 */
private SubHyperplane<Euclidean3D> boundaryFacet(final Vector3D point,
                                                 final BSPTree<Euclidean3D> node) {
    final Vector2D point2D = ((Plane) node.getCut().getHyperplane()).toSubSpace((Point<Euclidean3D>) point);
    @SuppressWarnings("unchecked")
    final BoundaryAttribute<Euclidean3D> attribute =
        (BoundaryAttribute<Euclidean3D>) node.getAttribute();
    if ((attribute.getPlusOutside() != null) &&
        (((SubPlane) attribute.getPlusOutside()).getRemainingRegion().checkPoint(point2D) == Location.INSIDE)) {
        return attribute.getPlusOutside();
    }
    if ((attribute.getPlusInside() != null) &&
        (((SubPlane) attribute.getPlusInside()).getRemainingRegion().checkPoint(point2D) == Location.INSIDE)) {
        return attribute.getPlusInside();
    }
    return null;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:23,代码来源:PolyhedronsSet.java

示例7: apply

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
/** {@inheritDoc} */
public SubHyperplane<Euclidean2D> apply(final SubHyperplane<Euclidean2D> sub,
                                        final Hyperplane<Euclidean3D> original,
                                        final Hyperplane<Euclidean3D> transformed) {
    if (original != cachedOriginal) {
        // we have changed hyperplane, reset the in-hyperplane transform

        final Plane   oPlane = (Plane) original;
        final Plane   tPlane = (Plane) transformed;
        final Vector2D shift  = tPlane.toSubSpace((Point<Euclidean3D>) apply(oPlane.getOrigin()));

        cachedOriginal  = (Plane) original;
        cachedTransform =
                org.apache.commons.math3.geometry.euclidean.twod.Line.getTransform(1, 0, 0, 1,
                                                                                   shift.getX(),
                                                                                   shift.getY());

    }

    return ((SubLine) sub).applyTransform(cachedTransform);

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

示例8: generate

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
/** {@inheritDoc} */
public ConvexHull2D generate(final Collection<Vector2D> points)
        throws NullArgumentException, ConvergenceException {
    // check for null points
    MathUtils.checkNotNull(points);

    Collection<Vector2D> hullVertices = null;
    if (points.size() < 2) {
        hullVertices = points;
    } else {
        hullVertices = findHullVertices(points);
    }

    try {
        return new ConvexHull2D(hullVertices.toArray(new Vector2D[hullVertices.size()]),
                                tolerance);
    } catch (MathIllegalArgumentException e) {
        // the hull vertices may not form a convex hull if the tolerance value is to large
        throw new ConvergenceException();
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:22,代码来源:AbstractConvexHullGenerator2D.java

示例9: parseTextureCoordinate

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
private Vector2D parseTextureCoordinate(String line, int lineNumber) {
	if (isValid(line, textureCoordinatePattern)) {
		line = line.substring(line.indexOf(' ') + 1);
		String[] tokens = line.split(" ");
		try {
			if (tokens.length >= 2) {
				return new Vector2D(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1]));
			}
		} catch (NumberFormatException e) {
			throw new RenderException(String.format("Number formatting error at line %d", lineNumber), e);
		}
	} else {
		throw new RenderException("Error parsing entry ('" + line + "'" + ", line " + lineNumber + ") in model '" + this.name + "' - Incorrect format");
	}
	return null;
}
 
开发者ID:NOVA-Team,项目名称:NOVA-Core,代码行数:17,代码来源:WavefrontObjectModelProvider.java

示例10: apply

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
/** {@inheritDoc} */
public SubHyperplane<Euclidean2D> apply(final SubHyperplane<Euclidean2D> sub,
                                        final Hyperplane<Euclidean3D> original,
                                        final Hyperplane<Euclidean3D> transformed) {
    if (original != cachedOriginal) {
        // we have changed hyperplane, reset the in-hyperplane transform

        final Plane   oPlane = (Plane) original;
        final Plane   tPlane = (Plane) transformed;
        final Vector2D shift  = tPlane.toSubSpace((Point<Euclidean3D>) apply(oPlane.getOrigin()));
        final AffineTransform at =
            AffineTransform.getTranslateInstance(shift.getX(), shift.getY());

        cachedOriginal  = (Plane) original;
        cachedTransform =
                org.apache.commons.math3.geometry.euclidean.twod.Line.getTransform(at);

    }

    return ((SubLine) sub).applyTransform(cachedTransform);

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:PolyhedronsSet.java

示例11: makeCircle

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
public static List<Vector2D> makeCircle(int samples, final RandomVectorGenerator generator) {
    List<Vector2D> points = new ArrayList<Vector2D>();
    for (double i = 0; i < samples; i++) {
        double[] vector = generator.nextVector();
        Vector2D point = new Vector2D(vector);
        points.add(point);
    }

    // normalize points first
    points = normalize(points);
    
    // now test if the sample is within the unit circle
    List<Vector2D> circlePoints = new ArrayList<Vector2D>();
    for (Vector2D p : points) {
        double criteria = FastMath.pow(p.getX(), 2) + FastMath.pow(p.getY(), 2);
        if (criteria < 1.0) {
            circlePoints.add(p);
        }
    }

    return circlePoints;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:LowDiscrepancyGeneratorComparison.java

示例12: centroid

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
public default Vector2D centroid() {
	Vertex2D[] vertices = vertices();
	int n = size();

	double cx = 0, cy = 0;
	int i, j;

	double f = 0;
	for (i = 0; i < n; i++) {
		j = (i + 1) % n;
		f = (vertices[i].getX() * vertices[j].getY() - vertices[j].getX() * vertices[i].getY());
		cx += (vertices[i].getX() + vertices[j].getX()) * f;
		cy += (vertices[i].getY() + vertices[j].getY()) * f;
	}
	f = 1.0 / (6.0 * area());
	cx *= f;
	cy *= f;

	return new Vector2D(cx, cy);
}
 
开发者ID:NOVA-Team,项目名称:NOVA-GUI,代码行数:21,代码来源:Shape2D.java

示例13: paintComponent

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);

    int w = getWidth();
    int h = getHeight();

    g2.clearRect(0, 0, w, h);
    
    g2.setPaint(Color.black);
    g2.drawRect(0, 0, w - 1, h - 1);
    
    for (Vector2D point : points) {
        Vector2D p = transform(point, w, h);
        double[] arr = p.toArray();
        g2.draw(new Rectangle2D.Double(arr[0] - 1, arr[1] - 1, 2, 2));
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:LowDiscrepancyGeneratorComparison.java

示例14: draw

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
@Override
public void draw(int mouseX, int mouseY, float partial, Graphics graphics) {

	Canvas canvas = graphics.getCanvas();

	Optional<Vector2D> preferredSize = getComponent().getPreferredSize();
	if (preferredSize.isPresent()) {
		// We have a preferred size so we can draw our fancy gray
		// background.

		Vector2D size = getOutline().getDimension();
		Vector2D position = getOutline().getPosition();
		GuiUtils.drawGUIWindow((int) position.getX() - 4, (int) position.getY() - 4, (int) size.getX() + 8, (int) size.getY() + 8);
	}

	Outline guiOutline = getOutline();
	canvas.translate(guiOutline.minXi(), guiOutline.minYi());
	super.draw(mouseX - guiOutline.minXi(), mouseY - guiOutline.minYi(), partial, graphics);
	canvas.translate(-guiOutline.minXi(), -guiOutline.minYi());
}
 
开发者ID:NOVA-Team,项目名称:NOVA-GUI,代码行数:21,代码来源:MCGui.java

示例15: testCircleFitting

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
@Test
public void testCircleFitting() {
    CircleScalar problem = new CircleScalar();
    problem.addPoint( 30.0,  68.0);
    problem.addPoint( 50.0,  -6.0);
    problem.addPoint(110.0, -20.0);
    problem.addPoint( 35.0,  15.0);
    problem.addPoint( 45.0,  97.0);
    NonLinearConjugateGradientOptimizer optimizer
       = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE,
                                                 new SimpleValueChecker(1e-30, 1e-30),
                                                 1e-15, 1e-13, 1);
    PointValuePair optimum
        = optimizer.optimize(new MaxEval(100),
                             problem.getObjectiveFunction(),
                             problem.getObjectiveFunctionGradient(),
                             GoalType.MINIMIZE,
                             new InitialGuess(new double[] { 98.680, 47.345 }));
    Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]);
    Assert.assertEquals(69.960161753, problem.getRadius(center), 1.0e-8);
    Assert.assertEquals(96.075902096, center.getX(), 1.0e-7);
    Assert.assertEquals(48.135167894, center.getY(), 1.0e-6);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:NonLinearConjugateGradientOptimizerTest.java


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