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

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

Introduction

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

Prototype

Vector3D PLUS_J

To view the source code for org.apache.commons.math3.geometry.euclidean.threed Vector3D PLUS_J.

Click Source Link

Document

Second canonical vector (coordinates: 0, 1, 0).

Usage

From source file:org.jtrfp.trcl.obj.ObjectDirection.java

public ObjectDirection(int legacyRoll, int legacyPitch, int legacyYaw) {
    Vector3D headingAccumulator, topAccumulator;
    Rotation rot;/*from  ww w .j  ava  2s .  c  o m*/
    yaw = ((double) legacyYaw / 65535.) * 2 * Math.PI;
    roll = ((double) legacyRoll / 65535.) * 2 * Math.PI;
    tilt = ((double) legacyPitch / 65535.) * 2 * Math.PI;
    /*
     * Rotation hRot = new Rotation(//yaw only. new Vector3D(0,1,0), new
     * Vector3D(0,0,1), new Vector3D(0,1,0), new
     * Vector3D(Math.cos(yaw),0.,Math.sin(yaw))); heading =
     * hRot.applyTo(heading);
     */
    topAccumulator = new Vector3D(0, 1, 0);
    /*
     * Rotation tRot = new Rotation(//Pitch and roll new Vector3D(0,1,0),
     * new Vector3D(0,1,0), new Vector3D(Math.sin(roll),1,Math.cos(roll)),
     * new Vector3D(0.,Math.cos(tilt),Math.cos(tilt)));
     */
    headingAccumulator = Vector3D.PLUS_K;
    rot = new Rotation(Vector3D.PLUS_I, tilt);
    headingAccumulator = rot.applyTo(headingAccumulator);
    topAccumulator = rot.applyTo(topAccumulator);
    rot = new Rotation(Vector3D.PLUS_J, yaw + 1.5 * Math.PI);
    headingAccumulator = rot.applyTo(headingAccumulator);
    topAccumulator = rot.applyTo(topAccumulator);
    // Commit the values
    heading = headingAccumulator;
    top = topAccumulator;
}

From source file:org.jtrfp.trcl.obj.Sprite2D.java

public Sprite2D(TR tr, double z, double width, double height, TextureDescription tex, boolean useAlpha) {
    super(tr);/* ww w  .  j  a  v a  2s .c o m*/
    if (tex == null)
        throw new NullPointerException("Supplied texture intolerably null.");
    this.texture = tex;
    final Model m = new Model(false, tr);
    Triangle[] tris = Triangle.quad2Triangles(new double[] { -width / 2, width / 2, width / 2, -width / 2 },
            new double[] { -height / 2, -height / 2, height / 2, height / 2 }, new double[] { z, z, z, z },
            new double[] { 0, 1, 1, 0 }, new double[] { 0, 0, 1, 1 }, tex, RenderMode.DYNAMIC, useAlpha,
            Vector3D.ZERO, "Sprite2D non-segmented");
    m.addTriangles(tris);
    setModel(m);
    setTop(Vector3D.PLUS_J);
    setActive(true);
    setVisible(true);
}

From source file:org.jtrfp.trcl.obj.Sprite2D.java

public Sprite2D(TR tr, double z, double width, double height, TextureDescription[] tex, boolean useAlpha) {
    super(tr);/* w w  w  .j  a v a 2  s  . com*/
    if (tex == null)
        throw new NullPointerException("Supplied texture intolerably null.");
    this.texture = tex[0];
    final Model m = new Model(false, tr);
    final int numSegs = tex.length;
    for (int seg = 0; seg < numSegs; seg++) {
        final double segWidth = width / numSegs;
        final double x = (-width / 2) + segWidth * seg;

        Triangle[] tris = Triangle.quad2Triangles(new double[] { x, x + segWidth, x + segWidth, x },
                new double[] { -height / 2, -height / 2, height / 2, height / 2 }, new double[] { z, z, z, z },
                new double[] { 0, 1, 1, 0 }, new double[] { 0, 0, 1, 1 }, tex[seg], RenderMode.DYNAMIC,
                Vector3D.ZERO, "Sprite2D " + numSegs + " segments");
        tris[0].setAlphaBlended(true);
        tris[1].setAlphaBlended(true);
        m.addTriangles(tris);
    } // end for(segs)
    setModel(m.finalizeModel());
    setTop(Vector3D.PLUS_J);
    setHeading(Vector3D.PLUS_K);
    setActive(true);
    setVisible(true);
}

From source file:org.jtrfp.trcl.obj.WorldObject2D.java

public WorldObject2D(TR tr) {
    super(tr);//from  w  w  w  .  ja  v  a 2 s  . c o  m
    setTop(Vector3D.PLUS_J);
    setHeading(Vector3D.PLUS_K);
    //Setup matrices
    rMd[15] = 1;

    tMd[0] = 1;
    tMd[5] = 1;
    tMd[10] = 1;
    tMd[15] = 1;

    setRenderFlags((byte) 1);
}

From source file:org.jtrfp.trcl.Tunnel.java

private Vector3D buildTunnel(TDFFile.Tunnel _tun, Vector3D groundVector, boolean entrance)
        throws IllegalAccessException, UnrecognizedFormatException, FileNotFoundException, FileLoadException,
        IOException {//  ww  w .  j av a2s  .  co m
    // Entrance uses only a stub. Player is warped to TUNNEL_POS facing
    // TUNNEL_START_DIRECTION
    ResourceManager rm = tr.getResourceManager();
    LVLFile tlvl = rm.getLVL(_tun.getTunnelLVLFile());
    final ColorPaletteVectorList tunnelColorPalette = new ColorPaletteVectorList(
            tr.getResourceManager().getPalette(lvl.getGlobalPaletteFile()));
    TextureDescription[] tunnelTexturePalette = rm.getTextures(tlvl.getLevelTextureListFile(), paletteVL,
            ESTuTvPalette, true);
    TNLFile tun = tr.getResourceManager().getTNLData(tlvl.getHeightMapOrTunnelFile());

    final double segLen = 65536;
    final double bendiness = 18;
    List<Segment> segs = tun.getSegments();
    final LoadingProgressReporter[] reporters = tunnelAssemblyReporter.generateSubReporters(segs.size());
    // Vector3D tunnelEnd = TUNNEL_START_POS;
    Rotation rotation = entrance ? new Rotation(new Vector3D(0, 0, 1), groundVector)
            : new Rotation(new Vector3D(0, 0, 1), new Vector3D(1, 0, 0));
    Vector3D startPoint = TUNNEL_START_POS;

    Vector3D segPos = Vector3D.ZERO;

    final Vector3D top = rotation.applyTo(new Vector3D(0, 1, 0));
    /*
    if (entrance) {
        // Entrance is just a stub so we only need a few of the segments
        List<Segment> newSegs = new ArrayList<Segment>();
        for (int i = 0; i < 10; i++) {
       newSegs.add(segs.get(i));
        }
        segs = newSegs;
    }*/
    // CONSTRUCT AND INSTALL SEGMENTS
    int segIndex = 0;
    Vector3D finalPos = TUNNEL_START_POS;
    for (Segment s : segs) {
        reporters[segIndex].complete();
        tr.getReporter().report(
                "org.jtrfp.trcl.Tunnel." + _tun.getTunnelLVLFile() + ".segment" + (segIndex++) + "",
                s.getObstacle().name());
        // Figure out the space the segment will take
        Vector3D positionDelta = new Vector3D((double) (s.getEndX() - s.getStartX()) * bendiness * -1,
                (double) (s.getEndY() - s.getStartY()) * bendiness, segLen);
        // Create the segment
        Vector3D position = startPoint.add(rotation.applyTo(segPos));
        TunnelSegment ts = new TunnelSegment(tr, s, tunnelTexturePalette, segLen, positionDelta.getX(),
                positionDelta.getY());
        ts.setPosition(position.toArray());
        ts.setHeading(entrance ? groundVector : Vector3D.PLUS_I);
        ts.setTop(entrance ? top : Vector3D.PLUS_J);
        // Install the segment
        add(ts);
        installObstacles(s, tunnelColorPalette, ESTuTvPalette, tunnelTexturePalette,
                entrance ? groundVector : Vector3D.PLUS_I, entrance ? top : Vector3D.PLUS_J, position,
                TR.legacy2Modern(s.getStartWidth() * TunnelSegment.TUNNEL_DIA_SCALAR),
                TR.legacy2Modern(s.getStartWidth() * TunnelSegment.TUNNEL_DIA_SCALAR), tr);
        // Move origin to next segment
        segPos = segPos.add(positionDelta);
        finalPos = position;
    } // end for(segments)
    return finalPos;
}

From source file:org.orekit.attitudes.AttitudeTest.java

@Test
public void testShift() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(), Rotation.IDENTITY,
            new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO);
    Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10);
    double dt = 10.0;
    double alpha = rate * dt;
    Attitude shifted = attitude.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10);
    Assert.assertEquals(alpha, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10);

    Vector3D xSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Assert.assertEquals(0.0, xSat.subtract(new Vector3D(FastMath.cos(alpha), FastMath.sin(alpha), 0)).getNorm(),
            1.0e-10);/*from  w w  w  .  j a va 2s  . c om*/
    Vector3D ySat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J);
    Assert.assertEquals(0.0,
            ySat.subtract(new Vector3D(-FastMath.sin(alpha), FastMath.cos(alpha), 0)).getNorm(), 1.0e-10);
    Vector3D zSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K);
    Assert.assertEquals(0.0, zSat.subtract(Vector3D.PLUS_K).getNorm(), 1.0e-10);

}

From source file:org.orekit.attitudes.AttitudeTest.java

@Test
public void testSpin() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(),
            new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO);
    Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10);
    double dt = 10.0;
    Attitude shifted = attitude.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10);
    Assert.assertEquals(rate * dt, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10);

    Vector3D shiftedX = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Vector3D shiftedY = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J);
    Vector3D shiftedZ = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K);
    Vector3D originalX = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Vector3D originalY = attitude.getRotation().applyInverseTo(Vector3D.PLUS_J);
    Vector3D originalZ = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K);
    Assert.assertEquals(FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedX, originalX), 1.0e-10);
    Assert.assertEquals(FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedX, originalY), 1.0e-10);
    Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedX, originalZ), 1.0e-10);
    Assert.assertEquals(-FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedY, originalX), 1.0e-10);
    Assert.assertEquals(FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedY, originalY), 1.0e-10);
    Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedY, originalZ), 1.0e-10);
    Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedZ, originalX), 1.0e-10);
    Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedZ, originalY), 1.0e-10);
    Assert.assertEquals(1.0, Vector3D.dotProduct(shiftedZ, originalZ), 1.0e-10);

    Vector3D forward = AngularCoordinates.estimateRate(attitude.getRotation(), shifted.getRotation(), dt);
    Assert.assertEquals(0.0, forward.subtract(attitude.getSpin()).getNorm(), 1.0e-10);

    Vector3D reversed = AngularCoordinates.estimateRate(shifted.getRotation(), attitude.getRotation(), dt);
    Assert.assertEquals(0.0, reversed.add(attitude.getSpin()).getNorm(), 1.0e-10);

}

From source file:org.orekit.attitudes.LofOffsetTest.java

@Test
public void testAnglesSign() throws OrekitException {

    AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789),
            TimeScalesFactory.getUTC());
    KeplerianOrbit orbit = new KeplerianOrbit(7178000.0, 1.e-8, FastMath.toRadians(50.),
            FastMath.toRadians(10.), FastMath.toRadians(20.), FastMath.toRadians(0.), PositionAngle.MEAN,
            FramesFactory.getEME2000(), date, 3.986004415e14);

    double alpha = 0.1;
    double cos = FastMath.cos(alpha);
    double sin = FastMath.sin(alpha);

    // Roll//from w w w  .  ja  v  a2 s. c  o m
    Attitude attitude = new LofOffset(orbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, alpha, 0.0, 0.0)
            .getAttitude(orbit, date, orbit.getFrame());
    checkSatVector(orbit, attitude, Vector3D.PLUS_I, 1.0, 0.0, 0.0, 1.0e-8);
    checkSatVector(orbit, attitude, Vector3D.PLUS_J, 0.0, cos, sin, 1.0e-8);
    checkSatVector(orbit, attitude, Vector3D.PLUS_K, 0.0, -sin, cos, 1.0e-8);

    // Pitch
    attitude = new LofOffset(orbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, 0.0, alpha, 0.0)
            .getAttitude(orbit, date, orbit.getFrame());
    checkSatVector(orbit, attitude, Vector3D.PLUS_I, cos, 0.0, -sin, 1.0e-8);
    checkSatVector(orbit, attitude, Vector3D.PLUS_J, 0.0, 1.0, 0.0, 1.0e-8);
    checkSatVector(orbit, attitude, Vector3D.PLUS_K, sin, 0.0, cos, 1.0e-8);

    // Yaw
    attitude = new LofOffset(orbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, 0.0, 0.0, alpha)
            .getAttitude(orbit, date, orbit.getFrame());
    checkSatVector(orbit, attitude, Vector3D.PLUS_I, cos, sin, 0.0, 1.0e-8);
    checkSatVector(orbit, attitude, Vector3D.PLUS_J, -sin, cos, 0.0, 1.0e-8);
    checkSatVector(orbit, attitude, Vector3D.PLUS_K, 0.0, 0.0, 1.0, 1.0e-8);

}

From source file:org.orekit.bodies.EllipseTest.java

@Test
public void testMeridianShape() throws OrekitException {
    OneAxisEllipsoid model = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
            Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    Ellipse e = model.getPlaneSection(new Vector3D(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, 0, 0),
            Vector3D.PLUS_J);
    Assert.assertEquals(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, e.getA(),
            1.0e-15 * Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
    Assert.assertEquals(Constants.WGS84_EARTH_EQUATORIAL_RADIUS * (1 - Constants.WGS84_EARTH_FLATTENING),
            e.getB(), 1.0e-15 * Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_J, e.getU()), 1.0e-15);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_K, e.getU()), 1.0e-15);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_I, e.getV()), 1.0e-15);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_J, e.getV()), 1.0e-15);
}

From source file:org.orekit.bodies.EllipseTest.java

@Test
public void testProjectionDerivatives() throws OrekitException {
    Ellipse e = new Ellipse(Vector3D.ZERO, Vector3D.PLUS_I, Vector3D.PLUS_J, 6.4e6, 6.3e6,
            FramesFactory.getGCRF());/*ww  w . j av a 2  s.  com*/
    TimeStampedPVCoordinates linearMotion = new TimeStampedPVCoordinates(AbsoluteDate.J2000_EPOCH,
            new Vector3D(7.0e6, 5.0e6, 0.0), new Vector3D(3.0e3, 4.0e3, 0.0), Vector3D.ZERO);
    TimeStampedPVCoordinates g0 = e.projectToEllipse(linearMotion);
    List<TimeStampedPVCoordinates> sample = new ArrayList<TimeStampedPVCoordinates>();
    for (double dt = -0.25; dt <= 0.25; dt += 0.125) {
        sample.add(e.projectToEllipse(linearMotion.shiftedBy(dt)));
    }
    TimeStampedPVCoordinates ref = TimeStampedPVCoordinates.interpolate(g0.getDate(),
            CartesianDerivativesFilter.USE_P, sample);
    Assert.assertEquals(0, Vector3D.distance(g0.getPosition(), ref.getPosition()) / ref.getPosition().getNorm(),
            1.0e-15);
    Assert.assertEquals(0, Vector3D.distance(g0.getVelocity(), ref.getVelocity()) / ref.getVelocity().getNorm(),
            6.0e-12);
    Assert.assertEquals(0,
            Vector3D.distance(g0.getAcceleration(), ref.getAcceleration()) / ref.getAcceleration().getNorm(),
            8.0e-8);

}