List of usage examples for org.apache.commons.math3.geometry.euclidean.twod Vector2D add
public Vector2D add(Vector<Euclidean2D> v)
From source file:io.lonelyrobot.empires.fw.game.traits.Movable.java
public static void move(BaseObject object, Vector2D offset) { /** Check if not called with invalid payload */ if (!(object instanceof Movable)) return;/*w ww .jav a 2s .c o m*/ /** Position is actually held on BaseObject */ Vector2D pos = object.getSolPos(); object.setSolPos(pos.add(offset)); }
From source file:io.lonelyrobot.empires.fw.game.obj.BaseObject.java
/** * This function is called recursively from the {@link Star}, updating it's children * with an offset of {0, 0}. These children then move themselves according to the * position of their parent and then pass this offset to their children. These children * move themselves by the offset and then calculate their additional offset. * /*from w ww .j av a 2 s .c o m*/ * @param parentOffset */ public void updateOrbits(Vector2D parentOffset) { Vector2D offset = new Vector2D(0, 0); if (orbit != null && orbit.getParent() != null) { Vector2D p = orbit.getParent().getSolPos(); /** Calculate own offset */ double x = p.getX() + orbit.getRadius() * Math.cos(orbit.getStep()); double y = p.getY() + orbit.getRadius() * Math.sin(orbit.getStep()); orbit.setStep(orbit.getStep() + orbit.getStepSpeed()); Vector2D newPos = new Vector2D(x, y); newPos.add(parentOffset); // offset.add(new Vector2D(x, y)); /** Add the parent offset on top */ // offset.add(parentOffset); offset.add(newPos); /** Apply position to self */ this.setSolPos(newPos); } /** Only propagate orbital offsets if self is Orbitable */ if (!(this instanceof Orbitable)) return; /** Call function for all children with the new (accumilated) offset */ Tools.safe(orbit.getChildren()).forEach((i) -> i.updateOrbits(offset)); }
From source file:io.lonelyrobot.empires.fw.game.map.SolarSystem.java
/** * Moves a unit inside the solar system and updates all references accordingly to avoid * future collision errors.// w w w . j a v a 2 s. c o m * * @param bo * Object to be moved * @param offset * Positional offset to be applied to the object */ public void moveUnit(BaseObject bo, Vector2D offset) { if (!(bo instanceof Movable)) { Logger.error("Failed to move unmovable object!"); return; } /** Update position reference in 2D search tree */ Vector2D curr = playerTree.get(bo); playerTree.move(bo, curr.add(offset)); /** Then update the object-own position reference */ Logger.debug("[" + bo.getName() + "] Moving object by " + offset); ((Movable) bo).move(offset); }
From source file:edu.stanford.cfuller.imageanalysistools.util.VoronoiDiagram.java
protected Hyperplane<Euclidean2D> constructBisectingHyperplane(Vector2D firstPoint, Vector2D secondPoint) { Vector2D middlePoint = firstPoint.add(secondPoint).scalarMultiply(0.5); Vector2D difference = secondPoint.subtract(firstPoint); double angle = Math.atan2(difference.getY(), difference.getX()); angle -= Math.PI / 2.0; // rotate 90 degrees Line bisector = new Line(middlePoint, angle); return bisector; }
From source file:edu.stanford.cfuller.imageanalysistools.filter.VoronoiFilter.java
protected Vector2D projectPointOntoVector(Vector2D origin, Vector2D pointToProject, Vector2D pointOnVector) { Vector2D onto = pointOnVector.subtract(origin).normalize(); Vector2D toProj = pointToProject.subtract(origin); Vector2D projected = origin.add(onto.scalarMultiply(onto.dotProduct(toProj))); return projected; }
From source file:edu.stanford.cfuller.imageanalysistools.util.VoronoiDiagram.java
/** * Gets the number of the region in which a supplied point lies. * * @param point a Vector2D describing the point whose region is being queried. * @return an int that is the label of the region in which the supplied vector lies. * this label corresponds to the (1-indexed) order in which the points were supplied * to the constructor.//www. j a v a2s . c o m */ public int getRegionNumber(Vector2D point) { final int unlabeledValue = 100; try { BSPTree<Euclidean2D> node = this.diagram.getCell(point); while (node.getAttribute() == null) { if (isLeaf(node)) { Integer value = findClosestRegion(point); node.setAttribute(value); break; } final double eps = 1e-6; // bump it slightly if it's exactly on an edge. Vector2D newpoint = point.add(new Vector2D(eps, 0)); node = this.diagram.getCell(newpoint); if (node.getAttribute() != null) break; if (isLeaf(node)) { Integer value = findClosestRegion(point); node.setAttribute(value); break; } newpoint = point.add(new Vector2D(0, eps)); node = this.diagram.getCell(newpoint); } return ((Integer) node.getAttribute()); //return (node.hashCode()); } catch (ClassCastException e) { return 0; } }
From source file:nova.core.util.math.Vector2DUtil.java
public static Vector2D midpoint(Vector2D a, Vector2D b) { return a.add(b).scalarMultiply(0.5); }
From source file:org.kalypso.model.wspm.ewawi.utils.profiles.EwawiProfilePoint.java
/** * This function returns the point as shape. * /*w ww .ja va 2 s . c o m*/ * @return The point as shape. */ public SHPPoint getShape() { /* g Rechtswert (Projektion auf Abszisse) von links nach rechts aufsteigend */ /* h Hochwert (Abweichung von der Achse) rechts positiv, links negativer Wert. */ final double rechtswert = m_proLine.getRechtswert().doubleValue(); final double hochwert = m_proLine.getHochwert().doubleValue(); /* Get the normalized vector of the fix points (length 1). */ final Vector2D normalizedProfileAxis = getNormalizedProfileAxis(); /* Get the projection vector. */ final Vector2D projectionVector = normalizedProfileAxis.scalarMultiply(rechtswert); /* Create the start point. */ final double xLeft = m_left.getRechtswert().doubleValue(); final double yLeft = m_left.getHochwert().doubleValue(); final Vector2D startPoint = new Vector2D(xLeft, yLeft); /* Create the projection point. */ final Vector2D projectionPoint = startPoint.add(projectionVector); /* Create the orthogonal vector from the normalized profile axis (has then also length 1). */ final Vector2D orthVector = new Vector2D(normalizedProfileAxis.getY(), -normalizedProfileAxis.getX()); /* Add hochwert * orthVector to the projection point. */ final Vector2D targetPoint = projectionPoint.add(hochwert, orthVector); return new SHPPoint(targetPoint.getX(), targetPoint.getY()); }
From source file:org.kalypso.model.wspm.ewawi.utils.profiles.EwawiProfilePoint.java
/** * This function returns the point as shape. * It ignores the hochwert, so that the point will be the projected point on the idealized line (left fixpoint to right fixpoint). * /*from w w w . ja va2 s .c o m*/ * @return The point as shape. */ public SHPPoint getShapeIdealized() { /* g Rechtswert (Projektion auf Abszisse) von links nach rechts aufsteigend */ final double rechtswert = m_proLine.getRechtswert().doubleValue(); /* Get the normalized vector of the fix points (length 1). */ final Vector2D normalizedProfileAxis = getNormalizedProfileAxis(); /* Get the projection vector. */ final Vector2D projectionVector = normalizedProfileAxis.scalarMultiply(rechtswert); /* Create the start point. */ final double xLeft = m_left.getRechtswert().doubleValue(); final double yLeft = m_left.getHochwert().doubleValue(); final Vector2D startPoint = new Vector2D(xLeft, yLeft); /* Create the projection point. */ final Vector2D projectionPoint = startPoint.add(projectionVector); return new SHPPoint(projectionPoint.getX(), projectionPoint.getY()); }