• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Vector2D类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testAbscissa

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2), 1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:17,代码来源:LineTest.java


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


示例18: testCircleFittingBadInit

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
@Test
public void testCircleFittingBadInit() {
    CircleVectorial circle = new CircleVectorial();
    double[][] points = circlePoints;
    double[] weights = new double[points.length];
    final double[] start = {-12, -12};
    Arrays.fill(weights, 2);
    for (int i = 0; i < points.length; ++i) {
        circle.addPoint(points[i][0], points[i][1]);
    }

    Optimum optimum = optimizer.optimize(builder(circle).weight(new DiagonalMatrix(weights)).start(start).build());

    Vector2D center = new Vector2D(optimum.getPoint().getEntry(0), optimum.getPoint().getEntry(1));
    Assert.assertTrue(optimum.getEvaluations() < 25);
    Assert.assertEquals(0.043, optimum.getRMS(), 1e-3);
    Assert.assertEquals(0.292235, circle.getRadius(center), 1e-6);
    Assert.assertEquals(-0.151738, center.getX(), 1e-6);
    Assert.assertEquals(0.2075001, center.getY(), 1e-6);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例19: testCircleFitting

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


示例20: Vector2D

import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; //导入依赖的package包/类
public Vector2D(List<Double> mult, List<Vector2D> vect) {
    this.x = new Double(0);
    this.y = new Double(0);

    for (int i = 0; i < mult.size(); i++) {
        this.x += mult.get(i) * vect.get(i).x;
        this.y += mult.get(i) * vect.get(i).y;
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:10,代码来源:MultiSteering.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HorizontalAlignment类代码示例发布时间:2022-05-21
下一篇:
Java IRecordProcessorFactory类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap