List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D
public Vector3D(double x, double y, double z)
From source file:edu.mit.fss.examples.member.OrekitSurfaceElement.java
@Override public Vector3D getPosition() { Vector3D cartesianPosition = null; try {//from www . j a v a 2 s .c o m // transform (0,0,0) in topocentric frame to element frame cartesianPosition = topoFrame.getTransformTo(frame.getOrekitFrame(), getDate()) .transformPosition(new Vector3D(0, 0, 0)); } catch (OrekitException e) { logger.error(e.getMessage()); } return cartesianPosition; }
From source file:com.kircherelectronics.androidlinearacceleration.sensor.AccelerationSensor.java
/** * To avoid anomalies at the poles with Euler angles and Gimbal lock, * quaternions are used instead./*ww w . j a va2s .co m*/ */ private void initQuaternionRotations() { // Rotate by 90 degrees or pi/2 radians. double rotation = Math.PI / 2; // Create the rotation around the x-axis Vector3D xV = new Vector3D(1, 0, 0); xQuaternion = new Rotation(xV, rotation); // Create the rotation around the y-axis Vector3D yV = new Vector3D(0, 1, 0); yQuaternion = new Rotation(yV, -rotation); // Create the composite rotation. rotationQuaternion = yQuaternion.applyTo(xQuaternion); }
From source file:Engine.WorldMap.java
public Vector3D CorrectPosition(Vector3D position, Screen screen) { double x = (double) (position.getX()); double y = (double) (position.getY()); x = DoubleModulo(x, (screen.worldMap.mapSize - 1) * GenerateTerrain.Size); y = DoubleModulo(y, (screen.worldMap.mapSize - 1) * GenerateTerrain.Size); return new Vector3D(x, y, position.getZ()); }
From source file:magma.tools.benchmark.model.proxy.BenchmarkAgentProxy.java
private Vector3D getForce(String message, String which) { int forceIndex = message.indexOf(which); if (forceIndex >= 0) { int fIndex = message.indexOf("(f", forceIndex); if (fIndex >= 0) { int eIndex = message.indexOf(")", fIndex); String forceString = message.substring(fIndex + 3, eIndex); String[] values = forceString.split(" "); if (values.length == 3) { float x = Float.valueOf(values[0]); float y = Float.valueOf(values[1]); float z = Float.valueOf(values[2]); return new Vector3D(x, y, z); }// w w w .ja va 2 s . co m } System.out.println("Strange force message: " + message.substring(forceIndex, forceIndex + 30)); return null; } return Vector3D.ZERO; }
From source file:msi.gama.metamodel.shape.GamaShape.java
/** * Same as above, but applies a (optional) rotation along a given vector and * (optional) translation to the geometry * /*w w w .j a v a 2 s. c o m*/ * @param source * cannot be null * @param geom * can be null * @param rotation * can be null, expressed in degrees * @param newLocation * can be null */ public GamaShape(final IShape source, final Geometry geom, final Double rotation, final GamaPoint vector, final ILocation newLocation) { this(source, geom); if (!isPoint() && rotation != null) { if (vector == null) { final Coordinate c = geometry.getCentroid().getCoordinate(); geometry.apply(AffineTransform3D.createRotationOz(FastMath.toRadians(rotation), c.x, c.y)); } else { final Vector3D v3D = new Vector3D(vector.getX(), vector.getY(), vector.getZ()); final Rotation rot = new Rotation(v3D, FastMath.toRadians(rotation)); for (final Coordinate c : this.getInnerGeometry().getCoordinates()) { final Vector3D result = rot.applyTo(new Vector3D(c.x, c.y, c.z)); c.x = result.getX(); c.y = result.getY(); c.z = result.getZ(); } } } if (newLocation != null) { setLocation(newLocation); } }
From source file:Engine.Player.java
public void ApproachPlayer(Player p, WorldMap worldMap) { MoveDirection = null;/*from ww w .j a v a2 s . c o m*/ //PositionIFace = new Vector3D(p.ViewFrom[0], p.ViewFrom[1], p.ViewFrom[2]); PositionIFace = AlgebraUtils.ReturnClosestWectorMirror(p.ViewFrom, ViewFrom, worldMap); int algorithmSize = Math.min(GenerateTerrain.mapSize, worldMap.mapSize); int[][] obstacleMap = new int[algorithmSize][]; int halfSize = algorithmSize / 2; int goalX = halfSize; int goalY = halfSize; for (int a = 0; a < obstacleMap.length; a++) { obstacleMap[a] = new int[algorithmSize]; } for (int a = -halfSize + (int) (ViewFrom[0] / GenerateTerrain.Size), aa = 0; a < halfSize + (int) (ViewFrom[0] / GenerateTerrain.Size) - 1; a++, aa++) for (int b = -halfSize + (int) (ViewFrom[1] / GenerateTerrain.Size), bb = 0; b < halfSize + (int) (ViewFrom[1] / GenerateTerrain.Size) - 1; b++, bb++) { int MapIdX = a; int MapIdY = b; MapIdX %= (worldMap.getMapSize()); MapIdY %= (worldMap.getMapSize()); if (MapIdX < 0) MapIdX = worldMap.getMapSize() + MapIdX; if (MapIdY < 0) MapIdY = worldMap.getMapSize() + MapIdY; if (worldMap.ObjectsMap[MapIdX][MapIdY].size() > 0) { if (worldMap.ObjectsMap[MapIdX][MapIdY].contains(p)) { obstacleMap[aa][bb] = 0; goalX = aa; goalY = bb; } else { Object o = worldMap.ObjectsMap[MapIdX][MapIdY].get(0); /*if (o instanceof Cube) { Cube c = (Cube)o; double xx = c.width / GenerateTerrain.Size + 1.01; double yy = c.length / GenerateTerrain.Size + 1.01; int aaa = 0; aaa++; for (int a1 = - (int)(xx / 2); a1 <= (int)(xx / 2); a1++) for (int b1 = - (int)(yy / 2); b1 <= (int)(yy / 2); b1++) { if (aa + a1 >= 0 && bb + b1 >= 0 && aa + a1 < obstacleMap.length && bb + b1 < obstacleMap[0].length) { obstacleMap[aa + a1][bb + b1] = 1; if (worldMap.ObjectsMap[aa + a1][bb + b1].contains(p)) { obstacleMap[aa + a1][bb + b1] = 0; goalX = aa; goalY = bb; } } } }*/ if (o instanceof Cube) { Cube c = (Cube) o; double xx = c.width / GenerateTerrain.Size + .01; double yy = c.length / GenerateTerrain.Size + .01; int aaa = 0; aaa++; for (int a1 = 0; a1 <= (int) xx + 0; a1++) for (int b1 = 0; b1 <= (int) yy + 0; b1++) { if (aa + a1 >= 0 && bb + b1 >= 0 && aa + a1 < obstacleMap.length && bb + b1 < obstacleMap[0].length) { obstacleMap[aa + a1][bb + b1] = 1; if (worldMap.ObjectsMap[aa + a1][bb + b1].contains(p)) { obstacleMap[aa + a1][bb + b1] = 0; goalX = aa; goalY = bb; } } } } obstacleMap[aa][bb] = 1; } } else { if (obstacleMap[aa][bb] < 1) obstacleMap[aa][bb] = 0; } } obstacleMap[halfSize][halfSize] = 0; AreaMap map = new AreaMap(algorithmSize, algorithmSize, obstacleMap); IAStarHeuristic heuristic = new DiagonalHeuristic(); AStar aStar = new AStar(map, heuristic); ArrayList<Point> shortestPath = aStar.calcShortestPath(halfSize, halfSize, goalX, goalY); if (shortestPath != null) if (shortestPath.size() > 1) { MoveDirection = new Vector3D(shortestPath.get(0).x - halfSize, shortestPath.get(0).y - halfSize, 0); } //////////////// //REMOVE //MoveDirection = Vector3D.ZERO; }
From source file:edu.stanford.cfuller.imageanalysistools.clustering.ObjectClustering.java
/** * Sets up a set of ClusterObjects and a set of Clusters from an Image mask with each object labeled with a unique greylevel. * * @param im The Image mask with each cluster object labeled with a unique greylevel. These must start at 1 and be consecutive. * @param clusterObjects A Vector of ClusterObjects that will contain the initialized ClusterObjects on return; this may be empty, and any contents will be erased. * @param clusters A Vector of Clusters that will contain the initialized Clusters on return; this may be empty, and any contents will be erased. * @param k The number of Clusters to generate. * @return The number of ClusterObjects in the Image. */// www . j a v a 2 s .c o m public static int initializeObjectsAndClustersFromImage(Image im, Vector<ClusterObject> clusterObjects, Vector<Cluster> clusters, int k) { int n = 0; clusters.clear(); for (int j = 0; j < k; j++) { clusters.add(new Cluster()); clusters.get(j).setID(j + 1); } Histogram h = new Histogram(im); n = h.getMaxValue(); clusterObjects.clear(); for (int j = 0; j < n; j++) { clusterObjects.add(new ClusterObject()); clusterObjects.get(j).setCentroidComponents(0, 0, 0); clusterObjects.get(j).setnPixels(0); } for (ImageCoordinate i : im) { if (im.getValue(i) > 0) { ClusterObject current = clusterObjects.get((int) im.getValue(i) - 1); current.incrementnPixels(); current.setCentroid(current.getCentroid().add(new Vector3D(i.get(ImageCoordinate.X), i.get(ImageCoordinate.Y), i.get(ImageCoordinate.Z)))); } } for (int j = 0; j < n; j++) { ClusterObject current = clusterObjects.get(j); current.setCentroid(current.getCentroid().scalarMultiply(1.0 / current.getnPixels())); } //initialize clusters using kmeans++ strategy double[] probs = new double[n]; double[] cumulativeProbs = new double[n]; java.util.Arrays.fill(probs, 0); java.util.Arrays.fill(cumulativeProbs, 0); //choose the initial cluster int initialClusterObject = (int) Math.floor(n * RandomGenerator.rand()); clusters.get(0).setCentroid(clusterObjects.get(initialClusterObject).getCentroid()); clusters.get(0).getObjectSet().add(clusterObjects.get(initialClusterObject)); for (int j = 0; j < n; j++) { clusterObjects.get(j).setCurrentCluster(clusters.get(0)); } //assign the remainder of the clusters for (int j = 1; j < k; j++) { double probSum = 0; for (int m = 0; m < n; m++) { double minDist = Double.MAX_VALUE; Cluster bestCluster = null; for (int p = 0; p < j; p++) { double tempDist = clusterObjects.get(m).distanceTo(clusters.get(p)); if (tempDist < minDist) { minDist = tempDist; bestCluster = clusters.get(p); } } probs[m] = minDist; probSum += minDist; clusterObjects.get(m).setCurrentCluster(bestCluster); } for (int m = 0; m < n; m++) { probs[m] = probs[m] / probSum; if (m == 0) { cumulativeProbs[m] = probs[m]; } else { cumulativeProbs[m] = cumulativeProbs[m - 1] + probs[m]; } } double randNum = RandomGenerator.rand(); int nextCenter = 0; for (int m = 0; m < n; m++) { if (randNum < cumulativeProbs[m]) { nextCenter = m; break; } } clusters.get(j).setCentroid(clusterObjects.get(nextCenter).getCentroid()); } for (int m = 0; m < n; m++) { double minDist = Double.MAX_VALUE; Cluster bestCluster = null; for (int p = 0; p < k; p++) { double tempDist = clusterObjects.get(m).distanceTo(clusters.get(p)); if (tempDist < minDist) { minDist = tempDist; bestCluster = clusters.get(p); } } clusterObjects.get(m).setCurrentCluster(bestCluster); bestCluster.getObjectSet().add(clusterObjects.get(m)); } return n; }
From source file:edu.stanford.cfuller.imageanalysistools.fitting.ImageObject.java
/** * Initializes the fields of an ImageObject based on supplied image and parameter data. * * Both the mask and the parent will be unmodified, except for boxing a region of interest, so no other thread should * be using these images at the same time. * * @param label The numerical label of the object in the mask. * @param mask An image mask, containing a unique greylevel for each object; the greylevel of the object being initialized should correspond to the parameter {@link #label}. * @param parent The original imgae that the mask corresponds to. * @param p A {@link ParameterDictionary} containing the parameters for the current analysis. In particular, this routine makes use of the various box size parameters. *///from ww w. j av a2 s.c om protected void init(int label, Image mask, Image parent, ParameterDictionary p) { this.fitParametersByChannel = null; this.fitR2ByChannel = null; this.fitErrorByChannel = null; this.nPhotonsByChannel = null; this.positionsByChannel = new java.util.ArrayList<RealVector>(); this.correctedPositionsByChannel = new java.util.HashMap<Integer, RealVector>(); this.vectorDifferencesBetweenChannels = new java.util.HashMap<Integer, RealVector>(); this.scalarDifferencesBetweenChannels = new java.util.HashMap<Integer, Double>(); //this.parent = new Image(parent); //this.mask = new Image(mask); this.parent = parent; this.mask = mask; this.label = label; this.sizeInPixels = 0; this.centroidInMask = new Vector3D(0, 0, 0); this.imageID = null; this.hadFittingError = true; this.numberOfChannels = p.getIntValueForKey("num_wavelengths"); // use this so that if there's extra wavelengths not to be quantified at the end, these won't skew the initial guess for (ImageCoordinate i : mask) { if (mask.getValue(i) == label) { sizeInPixels++; this.centroidInMask = this.centroidInMask.add( new Vector3D(i.get(ImageCoordinate.X), i.get(ImageCoordinate.Y), i.get(ImageCoordinate.Z))); } } if (this.sizeInPixels == 0) { return; } this.centroidInMask = this.centroidInMask.scalarMultiply(1.0 / sizeInPixels); //System.out.println("for object " + label + " centroid is: " + this.centroidInMask.toString()); int xcoord = (int) Math.round(this.centroidInMask.getX() - p.getIntValueForKey("half_box_size")); int ycoord = (int) Math.round(this.centroidInMask.getY() - p.getIntValueForKey("half_box_size")); if (xcoord < 0) { xcoord = 0; } if (ycoord < 0) { ycoord = 0; } this.parentBoxMin = ImageCoordinate.createCoordXYZCT(xcoord, ycoord, 0, 0, 0); xcoord = (int) Math.round(this.centroidInMask.getX() + p.getIntValueForKey("half_box_size")) + 1; ycoord = (int) Math.round(this.centroidInMask.getY() + p.getIntValueForKey("half_box_size")) + 1; if (xcoord > mask.getDimensionSizes().get(ImageCoordinate.X)) { xcoord = mask.getDimensionSizes().get(ImageCoordinate.X); } if (ycoord > mask.getDimensionSizes().get(ImageCoordinate.Y)) { ycoord = mask.getDimensionSizes().get(ImageCoordinate.Y); } this.parentBoxMax = ImageCoordinate.createCoordXYZCT(xcoord, ycoord, parent.getDimensionSizes().get(ImageCoordinate.Z), parent.getDimensionSizes().get(ImageCoordinate.C), parent.getDimensionSizes().get(ImageCoordinate.T)); //handle either 2D or 3D masks //2D case: if (mask.getDimensionSizes().get(ImageCoordinate.Z) == 1) { //find the max intensity pixel in each channel and use this to refine the box this.maxIntensityZCoordByChannel = new int[parent.getDimensionSizes().get(ImageCoordinate.C)]; int minZOverall = parent.getDimensionSizes().get(ImageCoordinate.Z); int maxZOverall = 0; //for (int c = 0; c < parent.getDimensionSizes().getC(); c++) { for (int c = 0; c < this.numberOfChannels; c++) { this.parentBoxMin.set(ImageCoordinate.C, c); this.parentBoxMax.set(ImageCoordinate.C, c + 1); parent.setBoxOfInterest(this.parentBoxMin, this.parentBoxMax); double maxValue = 0; ImageCoordinate maxCoord = null; for (ImageCoordinate ic : parent) { if (!(ic.get(ImageCoordinate.X) == (int) Math.round(this.centroidInMask.getX())) || !(ic.get(ImageCoordinate.Y) == (int) Math.round(this.centroidInMask.getY()))) { continue; } if (parent.getValue(ic) > maxValue) { maxValue = parent.getValue(ic); if (maxCoord != null) maxCoord.recycle(); maxCoord = ImageCoordinate.cloneCoord(ic); } } if (maxCoord == null) continue; if (maxCoord.get(ImageCoordinate.Z) > maxZOverall) maxZOverall = maxCoord.get(ImageCoordinate.Z); if (maxCoord.get(ImageCoordinate.Z) < minZOverall) minZOverall = maxCoord.get(ImageCoordinate.Z); this.maxIntensityZCoordByChannel[c] = maxCoord.get(ImageCoordinate.Z); maxCoord.recycle(); parent.clearBoxOfInterest(); } if (minZOverall > maxZOverall) { minZOverall = 0; maxZOverall = 0; java.util.logging.Logger.getLogger("edu.stanford.cfuller.colocalization3d") .warning("Problem when calculating Z range of image stack."); } int zAverage = (minZOverall + maxZOverall) / 2; int zcoord = 0; this.parentBoxMin.set(ImageCoordinate.C, 0); zcoord = zAverage - p.getIntValueForKey("half_z_size"); if (zcoord < 0) zcoord = 0; this.parentBoxMin.set(ImageCoordinate.Z, zcoord); this.parentBoxMax.set(ImageCoordinate.C, parent.getDimensionSizes().get(ImageCoordinate.C)); zcoord = zAverage + p.getIntValueForKey("half_z_size") + 1; if (zcoord > parent.getDimensionSizes().get(ImageCoordinate.Z)) zcoord = parent.getDimensionSizes().get(ImageCoordinate.Z); this.parentBoxMax.set(ImageCoordinate.Z, zcoord); } else { //3D mask int zcoord = (int) Math.round(this.centroidInMask.getZ() - p.getIntValueForKey("half_z_size")); if (zcoord < 0) { zcoord = 0; } this.parentBoxMin.set(ImageCoordinate.Z, zcoord); zcoord = (int) Math.round(this.centroidInMask.getZ() + p.getIntValueForKey("half_z_size") + 1); this.parentBoxMax.set(ImageCoordinate.Z, zcoord); } }
From source file:Engine.Projectile.java
public IRenderableGameObject CalculatePosition(double dt, Screen screen) { IRenderableGameObject iRenderableGameObject = null; iRenderableGameObject = CoolideWithGameObjectsOnMap(screen); if (iRenderableGameObject != null) { Remove = true;// w ww . j a v a 2 s .c o m return iRenderableGameObject; } dt *= magicMultiplayer; Vector3D acc = new Vector3D(0, 0, 0); if (forces != null) for (int a = 0; a < forces.length; a++) { acc = acc.add(forces[a]); } Vector3D vel = new Vector3D(0, 0, 0); if (velocities != null) for (int a = 0; a < velocities.length; a++) { vel = vel.add(velocities[a]); } time += dt; acc = acc.scalarMultiply(0.5 * time * time); vel = vel.scalarMultiply(time); moveDirection = acc.add(vel); Vector3D oldActualPosition = new Vector3D(1, actualPosition); BoundingBox oldBoundingBox = boundingBox; actualPosition = intialPosition.add(acc).add(vel); actualPosition = screen.worldMap.CorrectPosition(actualPosition, screen); this.boundingBox = new BoundingBox(actualPosition.getX() - (size.getX() / 2.0), actualPosition.getY() - (size.getY() / 2.0), actualPosition.getZ() - (size.getZ() / 2.0), actualPosition.getX() + (size.getX() / 2.0), actualPosition.getY() + (size.getY() / 2.0), actualPosition.getZ() + (size.getZ() / 2.0), true); iRenderableGameObject = CoolideWithGameObjectsOnMap(screen); if (iRenderableGameObject != null) { actualPosition = oldActualPosition; boundingBox = oldBoundingBox; Remove = true; return iRenderableGameObject; } if (projectileFunction != null && screen != null) { if (actualPosition.getZ() < screen.worldMap.GetGroundPosition(actualPosition, screen.worldMap)) { projectileFunction.CallAfterGroundHit(this); } } //this. boundingSphere = new BoundingSphere(actualPosition.getX(),actualPosition.getY(), actualPosition.getZ(), Math.max(Math.max(size.getX(), size.getY()), size.getZ())); this.boundingBox = new BoundingBox(actualPosition.getX() - (size.getX() / 2.0), actualPosition.getY() - (size.getY() / 2.0), actualPosition.getZ() - (size.getZ() / 2.0), actualPosition.getX() + (size.getX() / 2.0), actualPosition.getY() + (size.getY() / 2.0), actualPosition.getZ() + (size.getZ() / 2.0), true); return null; }
From source file:fr.cs.examples.KeyValueFileParser.java
/** Get a vector value from a parameters map. * @param xKey parameter key for abscissa * @param yKey parameter key for ordinate * @param zKey parameter key for height//ww w. j av a2 s . co m * @param scale time scale in which the date is to be parsed * @return date value corresponding to the key * @exception NoSuchElementException if key is not in the map */ public Vector3D getVector(final Key xKey, final Key yKey, final Key zKey) throws NoSuchElementException { return new Vector3D(getDouble(xKey), getDouble(yKey), getDouble(zKey)); }