Example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D scalarMultiply

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D scalarMultiply

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D scalarMultiply.

Prototype

public Vector3D scalarMultiply(double a) 

Source Link

Usage

From source file:lambertmrev.LambertMRev.java

/**
 * @param args the command line arguments
 *///from  www  . j av  a  2 s  .  co  m
public static void main(String[] args) {
    // Want to test the Lambert class so you can specify the number of revs for which to compute
    //System.out.print("this is the frames tutorial \n");
    try {
        Frame inertialFrame = FramesFactory.getEME2000();
        TimeScale utc = TimeScalesFactory.getTAI();
        AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, utc);
        double mu = 3.986004415e+14;

        double a = 24396159; // semi major axis in meters
        double e = 0.72831215; // eccentricity
        double i = Math.toRadians(7); // inclination
        double omega = Math.toRadians(180); // perigee argument
        double raan = Math.toRadians(261); // right ascension of ascending node
        double lM = 0; // mean anomaly

        Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame,
                initialDate, mu);
        //KeplerianPropagator kepler = new KeplerianPropagator(initialOrbit);

        // set geocentric positions
        Vector3D r1 = new Vector3D(-6.88999e3, 3.92763e4, 2.67053e3);
        Vector3D r2 = new Vector3D(-3.41458e4, 2.05328e4, 3.44315e3);
        Vector3D r1_site = new Vector3D(4.72599e3, 1.26633e3, 4.07799e3);
        Vector3D r2_site = new Vector3D(4.70819e3, 1.33099e3, 4.07799e3);

        // get the topocentric positions
        Vector3D top1 = Transform.geo2radec(r1.scalarMultiply(1000), r1_site.scalarMultiply(1000));
        Vector3D top2 = Transform.geo2radec(r2.scalarMultiply(1000), r2_site.scalarMultiply(1000));

        // time of flight in seconds
        double tof = 3 * 3600;

        // propagate to 0 and tof
        Lambert test = new Lambert();

        boolean cw = false;
        int multi_revs = 1;
        RealMatrix v1_mat;
        Random randomGenerator = new Random();

        PrintWriter out_a = new PrintWriter("out_java_a.txt");
        PrintWriter out_e = new PrintWriter("out_java_e.txt");
        PrintWriter out_rho1 = new PrintWriter("out_java_rho1.txt");
        PrintWriter out_rho2 = new PrintWriter("out_java_rho2.txt");

        // start the loop
        double A, Ecc, rho1, rho2, tof_hyp;

        long time1 = System.nanoTime();
        for (int ll = 0; ll < 1e6; ll++) {

            rho1 = top1.getZ() / 1000 + 1e-3 * randomGenerator.nextGaussian() * top1.getZ() / 1000;
            rho2 = top2.getZ() / 1000 + 1e-3 * randomGenerator.nextGaussian() * top2.getZ() / 1000;
            //tof_hyp = FastMath.abs(tof + 0.1*3600 * randomGenerator.nextGaussian());
            // from topo to geo
            Vector3D r1_hyp = Transform.radec2geo(top1.getX(), top1.getY(), rho1, r1_site);
            Vector3D r2_hyp = Transform.radec2geo(top2.getX(), top2.getY(), rho2, r2_site);
            //            System.out.println(r1_hyp.scalarMultiply(1000).getNorm());
            //            System.out.println(r2_hyp.scalarMultiply(1000).getNorm());
            //            System.out.println(tof/3600);
            test.lambert_problem(r1_hyp.scalarMultiply(1000), r2_hyp.scalarMultiply(1000), tof, mu, cw,
                    multi_revs);

            v1_mat = test.get_v1();

            Vector3D v1 = new Vector3D(v1_mat.getEntry(0, 0), v1_mat.getEntry(0, 1), v1_mat.getEntry(0, 2));
            //            System.out.println(v1);
            PVCoordinates rv1 = new PVCoordinates(r1_hyp.scalarMultiply(1000), v1);
            Orbit orbit_out = new KeplerianOrbit(rv1, inertialFrame, initialDate, mu);
            A = orbit_out.getA();
            Ecc = orbit_out.getE();

            //            System.out.println(ll + " - " +A);
            out_a.println(A);
            out_e.println(Ecc);
            out_rho1.println(rho1);
            out_rho2.println(rho2);
        }
        long time2 = System.nanoTime();
        long timeTaken = time2 - time1;

        out_a.close();
        out_e.close();
        out_rho1.close();
        out_rho2.close();

        System.out.println("Time taken " + timeTaken / 1000 / 1000 + " milli secs");

        // get the truth
        test.lambert_problem(r1.scalarMultiply(1000), r2.scalarMultiply(1000), tof, mu, cw, multi_revs);
        v1_mat = test.get_v1();
        Vector3D v1 = new Vector3D(v1_mat.getEntry(0, 0), v1_mat.getEntry(0, 1), v1_mat.getEntry(0, 2));
        PVCoordinates rv1 = new PVCoordinates(r1.scalarMultiply(1000), v1);
        Orbit orbit_out = new KeplerianOrbit(rv1, inertialFrame, initialDate, mu);
        //System.out.println(orbit_out.getA());
    } catch (FileNotFoundException ex) {
        Logger.getLogger(LambertMRev.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.mapr.synth.drive.GeoPoint.java

public GeoPoint project(double u, double v) {
    Vector3D ux = east();
    Vector3D vx = north(ux);/*from   w  ww. j a  v  a 2 s.  c  om*/

    return new GeoPoint(r.add(ux.scalarMultiply(u).add(vx.scalarMultiply(v))).normalize());
}

From source file:com.mapr.synth.drive.Producer.java

@Override
public void run() {
    Random rand = new Random(3);
    GeoPoint start = new GeoPoint((rand.nextDouble() - 0.5) * Math.PI / 2, rand.nextDouble() * Math.PI * 2);
    final Vector3D east = start.east();
    final Vector3D north = start.north(east);

    GeoPoint end = new GeoPoint(start.as3D().add(east.scalarMultiply(-12.0 / Constants.EARTH_RADIUS_KM))
            .add(north.scalarMultiply(7.0 / Constants.EARTH_RADIUS_KM)));

    Vector3D zz = project(east, north, end.as3D());
    System.out.printf("==> %.2f %.2f\n", zz.getX(), zz.getY());

    while (true) {
        double t = 0;
        final Car car = new Car();

        System.out.printf("%.2f\n", start.distance(end));
        car.driveTo(rand, t, start, end, new Car.Callback() {
            @Override/*from  w  w w  . j a  v a  2 s  .c om*/
            void call(double t, Engine eng, GeoPoint position) {
                final Vector3D here = project(east, north, position.as3D());
                try {
                    output.put(new Trails.State(new Engine(eng), here));
                } catch (InterruptedException e) {
                    throw new RuntimeException("Interrupted", e);
                }
            }
        });
    }
}

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 w w.  jav  a  2s . com*/
        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 w w  w  .j a  v  a  2s . co  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.wrapper.mc.forge.v17.wrapper.entity.forward.BWRigidBody.java

@Override
public void addForce(Vector3D force) {
    netForce = netForce.add(force.scalarMultiply(1 / mass()));
}

From source file:org.gearvrf.keyboard.util.Util.java

public static void rotateWithOpenGLLookAt(Vector3D cameraVector, Vector3D parentVector, GVRSceneObject object) {
    Vector3D globalUpVector = new Vector3D(0, 1, 0);
    Vector3D lookVector = parentVector.normalize();
    Vector3D rightVector = lookVector.crossProduct(globalUpVector);
    Vector3D upVector = rightVector.crossProduct(lookVector);
    Vector3D zAxis = cameraVector.subtract(parentVector).normalize();
    // Vector3D xAxis = upVector.crossProduct(zAxis).normalize();
    Vector3D xAxis = zAxis.crossProduct(upVector).normalize();
    Vector3D yAxis = xAxis.crossProduct(zAxis).normalize();
    // Vector3D yAxis = xAxis.crossProduct(zAxis).normalize();
    zAxis = zAxis.scalarMultiply(-1.f);

    float angle = (float) Vector3D.angle(parentVector, cameraVector);
    angle = (float) Math.toDegrees(angle);

    object.getTransform().rotateByAxis(angle, (float) xAxis.getX(), (float) xAxis.getY(), (float) xAxis.getZ());
    object.getTransform().rotateByAxis(angle, (float) yAxis.getX(), (float) yAxis.getY(), (float) yAxis.getZ());
    object.getTransform().rotateByAxis(angle, (float) zAxis.getX(), (float) zAxis.getY(), (float) zAxis.getZ());
}

From source file:org.jtrfp.trcl.beh.phy.AccelleratedByPropulsion.java

@Override
public void _tick(long timeInMillis) {
    WorldObject wo = getParent();/*from w  ww. j a  v  a 2 s  . c  o m*/
    Propelled p = wo.getBehavior().probeForBehavior(Propelled.class);
    Velocible v = wo.getBehavior().probeForBehavior(Velocible.class);
    double progressionInSeconds = (double) wo.getTr().getThreadManager()
            .getElapsedTimeInMillisSinceLastGameTick() / 1000.;
    if (progressionInSeconds > .25)
        progressionInSeconds = .25;
    Vector3D tVector = thrustVector != null ? thrustVector : wo.getHeading();
    v.accellerate(tVector.scalarMultiply(p.getPropulsion() * progressionInSeconds));
}

From source file:org.jtrfp.trcl.beh.phy.BouncesOffSurfaces.java

@Override
public void collidedWithSurface(WorldObject wo, double[] surfaceNormal) {
    final WorldObject parent = getParent();
    final Vector3D oldHeading = parent.getHeading();
    final Vector3D oldTop = parent.getTop();
    final Vector3D _surfaceNormal = new Vector3D(surfaceNormal);
    if (oldHeading == null)
        throw new NullPointerException("Parent heading is null.");
    if (surfaceNormal == null)
        throw new NullPointerException("Surface normal is null.");
    if (reflectHeading && new Rotation(oldHeading, _surfaceNormal).getAngle() > Math.PI / 2.) {
        Vector3D newHeading = (_surfaceNormal.scalarMultiply(_surfaceNormal.dotProduct(oldHeading) * -2)
                .add(oldHeading));/*from w ww .  j  av a 2  s . c  o m*/
        parent.setHeading(newHeading);
        final Rotation resultingRotation = new Rotation(oldHeading, newHeading);
        Vector3D newTop = resultingRotation.applyTo(oldTop);
        //if(newTop.getY()<0)newTop=newTop.negate();
        parent.setTop(newTop);
    } //end if(should reflect)
      //if(parent instanceof Velocible){
    final Velocible velocible = (Velocible) parent.probeForBehavior(Velocible.class);
    Vector3D oldVelocity = velocible.getVelocity();
    if (oldVelocity.getNorm() == 0)
        oldVelocity = Vector3D.PLUS_I;
    if (new Rotation(oldVelocity.normalize(), _surfaceNormal).getAngle() > Math.PI / 2.) {
        velocible.setVelocity(
                (_surfaceNormal.scalarMultiply(_surfaceNormal.dotProduct(oldVelocity) * -2).add(oldVelocity))
                        .scalarMultiply(velocityRetainmentCoefficient));
        //Nudge
        parent.setPosition(
                new Vector3D(parent.getPosition()).add(_surfaceNormal.scalarMultiply(1000.)).toArray());
    } //end if(should bounce)
    //}//end if(Velocible)
}

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());
}