List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D add
public Vector3D add(final Vector<Euclidean3D> v)
From source file:lambertmrev.conversions.java
public static Vector3D radec2geo(Tracklet tracklet, double rho, TopocentricFrame staF, Frame inertialFrame, TimeScale utc) {/*from ww w.j av a2 s .c om*/ double rho_k = rho * FastMath.sin(tracklet.getDEC()); double rho_j = rho * FastMath.cos(tracklet.getDEC()) * FastMath.sin(tracklet.getRA()); double rho_i = rho * FastMath.cos(tracklet.getDEC()) * FastMath.cos(tracklet.getRA()); Vector3D rho_vec = new Vector3D(rho_i, rho_j, rho_k); // System.out.println("rho used: " + rho_vec); AbsoluteDate year = new AbsoluteDate(Main.YEAR, utc); AbsoluteDate epoch = new AbsoluteDate(year, tracklet.getDOY() * 24 * 3600); Vector3D out = new Vector3D(0, 0, 0); try { // System.out.println("at epoch " + epoch + "\t the station is at: " + staF.getPVCoordinates(epoch, inertialFrame).getPosition()); out = rho_vec.add(staF.getPVCoordinates(epoch, inertialFrame).getPosition()); } catch (OrekitException e) { System.out.println("station coordinates not computed"); } return out; }
From source file:jtrace.object.transformation.Translation.java
@Override public Vector3D apply(Vector3D vec) { return vec.add(delta); }
From source file:Engine.Projectile.java
public IRenderableGameObject CalculatePosition(double dt, Screen screen) { IRenderableGameObject iRenderableGameObject = null; iRenderableGameObject = CoolideWithGameObjectsOnMap(screen); if (iRenderableGameObject != null) { Remove = true;/*ww w . 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:com.mapr.synth.drive.Car.java
public double simulate(double t, GeoPoint currentPosition, Random rand, Segment segment, Callback progress) { double targetSpeed = segment.travelSpeed(); double currentSpeed = 0; final double dt = 1; final double dv = 0.1 * Constants.G * dt; Vector3D start = currentPosition.as3D(); double distanceToGo = currentPosition.distance(segment.end); engine.setDistance(0);/*from ww w . j a v a2 s .c o m*/ Vector3D travelDirection = segment.end.as3D().subtract(currentPosition.as3D()).normalize(); double previousDistance = distanceToGo; while (distanceToGo <= previousDistance) { if (rand.nextDouble() < 0.05) { targetSpeed = Math.max(20 * Constants.MPH, targetSpeed + (rand.nextInt(5) - 2) * 5 * Constants.MPH); } targetSpeed = Math.min(segment.maxSpeed(), targetSpeed); if (currentSpeed < targetSpeed) { currentSpeed += dv; } else { currentSpeed -= dv; } currentSpeed = Math.min(currentSpeed, maxSpeed(distanceToGo * 1000, segment.exitSpeed())); engine.stepToTime(t, currentSpeed, BRAKING_ACCELERATION); t += dt; currentPosition.setPosition(start .add(travelDirection.scalarMultiply(engine.getDistance() / 1000 / Constants.EARTH_RADIUS_KM))); progress.call(t, engine, currentPosition); previousDistance = distanceToGo; distanceToGo = currentPosition.distance(segment.end); } return t; }
From source file:nova.core.util.math.Vector3DUtil.java
/** * Calculates middle point between two vectors. * @param a first vector.//from w w w .ja va 2s . co m * @param b second vector. * @return new vectors that is in the middle of a and b. */ public static Vector3D midpoint(Vector3D a, Vector3D b) { return a.add(b).scalarMultiply(0.5); }
From source file:org.esa.s2tbx.dataio.s2.l1b.CoordinateUtils.java
public static double distanceToSegment(Vector3D v, Vector3D w, Vector3D p) { // Return minimum distance between line segment vw and point p final double l2 = Vector3D.distanceSq(v, w); // i.e. |w-v|^2 - avoid a sqrt if (l2 == 0.0) return Vector3D.distance(p, v); // v == w case // Consider the line extending the segment, parameterized as v + t (w - v). // We find projection of point p onto the line. // It falls where t = [(p-v) . (w-v)] / |w-v|^2 double t = Vector3D.dotProduct(p.subtract(v), w.subtract(v)) / l2; if (t < 0.0) return Vector3D.distance(p, v); // Beyond the 'v' end of the segment else if (t > 1.0) return Vector3D.distance(p, w); // Beyond the 'w' end of the segment Vector3D projection = v.add(w.subtract(v).scalarMultiply(t)); // Projection falls on the segment return Vector3D.distance(p, projection); }
From source file:org.gearvrf.scene_objects.GVRCylinderSceneObject.java
private void createBody(float bottomRadius, float topRadius, float height, int stackNumber, int sliceNumber) { float difference = bottomRadius - topRadius; float halfHeight = height / 2.0f; for (int stack = 0; stack < stackNumber; stack++) { int initVertexCount = vertexCount; float stackPercentage0 = ((float) (stack) / stackNumber); float stackPercentage1 = ((float) (stack + 1) / stackNumber); float t0 = 1.0f - stackPercentage0; float t1 = 1.0f - stackPercentage1; float y0 = -halfHeight + (stackPercentage0 * height); float y1 = -halfHeight + (stackPercentage1 * height); float nx, ny, nz; for (int slice = 0; slice < sliceNumber; slice++) { float slicePercentage0 = ((float) (slice) / sliceNumber); float slicePercentage1 = ((float) (slice + 1) / sliceNumber); double theta0 = slicePercentage0 * 2.0 * Math.PI; double theta1 = slicePercentage1 * 2.0 * Math.PI; double cosTheta0 = Math.cos(theta0); double sinTheta0 = Math.sin(theta0); double cosTheta1 = Math.cos(theta1); double sinTheta1 = Math.sin(theta1); float radius = (bottomRadius - (difference * stackPercentage0)); float x0 = (float) (radius * cosTheta0); float z0 = (float) (-radius * sinTheta0); float x1 = (float) (radius * cosTheta1); float z1 = (float) (-radius * sinTheta1); radius = (bottomRadius - (difference * stackPercentage1)); float x2 = (float) (radius * cosTheta0); float z2 = (float) (-radius * sinTheta0); float x3 = (float) (radius * cosTheta1); float z3 = (float) (-radius * sinTheta1); float s0 = slicePercentage0; float s1 = slicePercentage1; vertices[vertexCount + 0] = x0; vertices[vertexCount + 1] = y0; vertices[vertexCount + 2] = z0; vertices[vertexCount + 3] = x1; vertices[vertexCount + 4] = y0; vertices[vertexCount + 5] = z1; vertices[vertexCount + 6] = x2; vertices[vertexCount + 7] = y1; vertices[vertexCount + 8] = z2; vertices[vertexCount + 9] = x3; vertices[vertexCount + 10] = y1; vertices[vertexCount + 11] = z3; // calculate normal Vector3D v1 = new Vector3D(x1 - x0, 0, z1 - z0); Vector3D v2 = new Vector3D(x2 - x0, y1 - y0, z2 - z0); Vector3D v3 = v1.crossProduct(v2).normalize(); nx = (float) v3.getX(); ny = (float) v3.getY(); nz = (float) v3.getZ(); normals[vertexCount + 0] = nx; normals[vertexCount + 1] = ny; normals[vertexCount + 2] = nz; normals[vertexCount + 3] = nx; normals[vertexCount + 4] = ny; normals[vertexCount + 5] = nz; normals[vertexCount + 6] = nx; normals[vertexCount + 7] = ny; normals[vertexCount + 8] = nz; normals[vertexCount + 9] = nx; normals[vertexCount + 10] = ny; normals[vertexCount + 11] = nz; texCoords[texCoordCount + 0] = s0; texCoords[texCoordCount + 1] = t0; texCoords[texCoordCount + 2] = s1; texCoords[texCoordCount + 3] = t0; texCoords[texCoordCount + 4] = s0; texCoords[texCoordCount + 5] = t1; texCoords[texCoordCount + 6] = s1; texCoords[texCoordCount + 7] = t1; indices[indexCount + 0] = (char) (triangleCount + 0); // 0 indices[indexCount + 1] = (char) (triangleCount + 1); // 1 indices[indexCount + 2] = (char) (triangleCount + 2); // 2 indices[indexCount + 3] = (char) (triangleCount + 2); // 2 indices[indexCount + 4] = (char) (triangleCount + 1); // 1 indices[indexCount + 5] = (char) (triangleCount + 3); // 3 vertexCount += 12;// w w w . j a va 2 s . c o m texCoordCount += 8; indexCount += 6; triangleCount += 4; } for (int i = initVertexCount; i < vertexCount - 12; i += 12) { Vector3D v1 = new Vector3D(normals[i + 3], normals[i + 4], normals[i + 5]); Vector3D v2 = new Vector3D(normals[i + 12], normals[i + 13], normals[i + 14]); Vector3D v3 = v1.add(v2).normalize(); nx = (float) v3.getX(); ny = (float) v3.getY(); nz = (float) v3.getZ(); normals[i + 3] = nx; normals[i + 4] = ny; normals[i + 5] = nz; normals[i + 12] = nx; normals[i + 13] = ny; normals[i + 14] = nz; v1 = new Vector3D(normals[i + 9], normals[i + 10], normals[i + 11]); v2 = new Vector3D(normals[i + 18], normals[i + 19], normals[i + 20]); v3 = v1.add(v2).normalize(); nx = (float) v3.getX(); ny = (float) v3.getY(); nz = (float) v3.getZ(); normals[i + 9] = nx; normals[i + 10] = ny; normals[i + 11] = nz; normals[i + 18] = nx; normals[i + 19] = ny; normals[i + 20] = nz; } int i1 = vertexCount - 12; Vector3D v1 = new Vector3D(normals[i1 + 3], normals[i1 + 4], normals[i1 + 5]); int i2 = initVertexCount; Vector3D v2 = new Vector3D(normals[i2 + 0], normals[i2 + 1], normals[i2 + 2]); Vector3D v3 = v1.add(v2).normalize(); nx = (float) v3.getX(); ny = (float) v3.getY(); nz = (float) v3.getZ(); normals[i1 + 3] = nx; normals[i1 + 4] = ny; normals[i1 + 5] = nz; normals[i2 + 0] = nx; normals[i2 + 1] = ny; normals[i2 + 2] = nz; v1 = new Vector3D(normals[i1 + 9], normals[i1 + 10], normals[i1 + 11]); v2 = new Vector3D(normals[i2 + 6], normals[i2 + 7], normals[i2 + 8]); v3 = v1.add(v2).normalize(); nx = (float) v3.getX(); ny = (float) v3.getY(); nz = (float) v3.getZ(); normals[i1 + 9] = nx; normals[i1 + 10] = ny; normals[i1 + 11] = nz; normals[i2 + 6] = nx; normals[i2 + 7] = ny; normals[i2 + 8] = nz; } }
From source file:org.jtrfp.trcl.beh.AutoFiring.java
@Override public void _tick(long timeMillis) { final WorldObject thisObject = getParent(); final Player player = thisObject.getTr().getGame().getPlayer(); if (player.getBehavior().probeForBehavior(Cloakable.class).isCloaked()) return;/* ww w. ja va2 s. c om*/ final double[] thisPos = thisObject.getPosition(); final double[] playerPos = player.getPosition(); final double dist = Vect3D.distance(thisPos, playerPos); if (dist < maxFiringDistance || dist > minFiringDistance) { final int patIndex = (int) (((timeMillis + patternOffsetMillis) % totalFiringPatternTimeMillis) / timePerPatternEntry); if (patIndex != lastIndexVisited) {//end if(lastVisited) if (firingPattern[patIndex]) { Vector3D result; if (smartFiring) { final Vector3D playerVelocity = player.getBehavior().probeForBehavior(Velocible.class) .getVelocity(); final double projectileSpeed = projectileFiringBehavior.getProjectileFactory().getWeapon() .getSpeed() / TR.crossPlatformScalar; Vector3D virtualPlayerPos = interceptOf(new Vector3D(playerPos), playerVelocity, new Vector3D(thisPos), projectileSpeed); if (virtualPlayerPos == null) virtualPlayerPos = new Vector3D(playerPos); Vect3D.subtract(virtualPlayerPos.toArray(), thisPos, firingVector); } else { Vect3D.subtract(playerPos, thisPos, firingVector); } result = new Vector3D(Vect3D.normalize(firingVector, firingVector)); final double[] objectHeading = thisObject.getHeadingArray(); Vect3D.subtract(objectHeading, result.toArray(), headingDelta); if (Vect3D.norm(headingDelta) > maxFireVectorDeviation) return; if (berzerk) result = new Vector3D(Math.random(), Math.random(), Math.random()).normalize(); Vector3D rand = new Vector3D((Math.random() * 2. - 1.) * aimRandomness, (Math.random() * 2. - 1.) * aimRandomness, (Math.random() * 2. - 1.) * aimRandomness); result = result.add(rand).normalize(); projectileFiringBehavior.requestFire(result); } } lastIndexVisited = patIndex; } //end in range }
From source file:org.jtrfp.trcl.beh.SpawnsRandomSmoke.java
@Override public void _tick(long timeMillis) { if (Math.random() < .6) { Vector3D pos = new Vector3D(getParent().getPositionWithOffset()); Smokes.triggerSmoke(pos.add(new Vector3D(Math.random() * 2000 - 1000, 0, Math.random() * 2000 - 1000)), SmokeType.Puff);//www . j a va 2 s. com } }
From source file:org.jtrfp.trcl.gpu.Vertex.java
public Vector3D getNormal() { if (normal != null) return normal; Vector3D result = Vector3D.ZERO; for (Triangle triangle : triangles) { result = result.add(triangle.getCentroidNormal()); } //end for(triangles) return result.scalarMultiply(1. / (double) triangles.size()); }