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

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

Introduction

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

Prototype

Vector3D PLUS_I

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

Click Source Link

Document

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

Usage

From source file:fr.cs.examples.attitude.EarthObservation_day_night_switch_with_spinned_transitions.java

/** Program entry point.
 * @param args program arguments (unused here)
 *//* w w w. j a  v a 2 s . co m*/
public static void main(String[] args) {
    try {

        // configure Orekit
        Autoconfiguration.configureOrekit();
        final SortedSet<String> output = new TreeSet<String>();

        //----------------------------------------
        //  Initial state definition : date, orbit
        //----------------------------------------
        final AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 02, 00, 00, 00.000,
                TimeScalesFactory.getUTC());
        final Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
        final Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231);
        final Orbit initialOrbit = new KeplerianOrbit(new PVCoordinates(position, velocity),
                FramesFactory.getEME2000(), initialDate, Constants.EIGEN5C_EARTH_MU);

        //------------------------------
        // Attitudes sequence definition
        //------------------------------
        final AttitudesSequence attitudesSequence = new AttitudesSequence();

        // Attitude laws definition
        final double settingRate = FastMath.toRadians(1.0);
        final AttitudeProvider dayObservationLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH,
                RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(40), 0);
        final AttitudeProvider nightRestingLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH);
        final AttitudeProvider transitionLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH,
                RotationOrder.XYZ, FastMath.toRadians(20), 0, 0);
        final AttitudeProvider rollSetUpLaw = new SpinStabilized(nightRestingLaw, AbsoluteDate.J2000_EPOCH,
                Vector3D.PLUS_I, settingRate);
        final AttitudeProvider pitchSetUpLaw = new SpinStabilized(transitionLaw, AbsoluteDate.J2000_EPOCH,
                Vector3D.PLUS_J, settingRate);
        final AttitudeProvider pitchTearDownLaw = new SpinStabilized(dayObservationLaw,
                AbsoluteDate.J2000_EPOCH, Vector3D.PLUS_J, -settingRate);
        final AttitudeProvider rollTearDownLaw = new SpinStabilized(transitionLaw, AbsoluteDate.J2000_EPOCH,
                Vector3D.PLUS_I, -settingRate);

        // Event detectors definition
        //---------------------------
        final PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
        final PVCoordinatesProvider earth = CelestialBodyFactory.getEarth();

        // Detectors : end day-night rdv 2
        final DateDetector endDayNightRdV2Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-day-night-2 night-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endDayNightRdV2Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to night law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-day-night-2 night-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end day-night rdv 1
        final DateDetector endDayNightRdV1Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-day-night-1 day-night-rdv2-mode");
                            endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endDayNightRdV1Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-day-night-1 day-night-rdv2-mode");
                            endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detector : eclipse entry
        final EventDetector dayNightEvent = new EclipseDetector(sun, 696000000., earth,
                Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 1 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " eclipse-entry day-night-rdv1-mode");
                            endDayNightRdV1Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endDayNightRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end night-day rdv 2
        final DateDetector endNightDayRdV2Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to day law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-night-day-2 day-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endNightDayRdV2Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-night-day-2 day-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end night-day rdv 1
        final DateDetector endNightDayRdV1Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-night-day-1 night-day-rdv2-mode");
                            endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endNightDayRdV1Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-night-day-1 night-day-rdv2-mode");
                            endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detector : eclipse exit
        final EventDetector nightDayEvent = new EclipseDetector(sun, 696000000., earth,
                Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 1 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " eclipse-exit night-day-rdv1-mode");
                            endNightDayRdV1Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endNightDayRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Attitude sequences definition
        //------------------------------
        attitudesSequence.addSwitchingCondition(dayObservationLaw, dayNightEvent, false, true,
                pitchTearDownLaw);
        attitudesSequence.addSwitchingCondition(pitchTearDownLaw, endDayNightRdV1Event_increase, true, false,
                rollTearDownLaw);
        attitudesSequence.addSwitchingCondition(pitchTearDownLaw, endDayNightRdV1Event_decrease, false, true,
                rollTearDownLaw);
        attitudesSequence.addSwitchingCondition(rollTearDownLaw, endDayNightRdV2Event_increase, true, false,
                nightRestingLaw);
        attitudesSequence.addSwitchingCondition(rollTearDownLaw, endDayNightRdV2Event_decrease, false, true,
                nightRestingLaw);
        attitudesSequence.addSwitchingCondition(nightRestingLaw, nightDayEvent, true, false, rollSetUpLaw);
        attitudesSequence.addSwitchingCondition(rollSetUpLaw, endNightDayRdV1Event_increase, true, false,
                pitchSetUpLaw);
        attitudesSequence.addSwitchingCondition(rollSetUpLaw, endNightDayRdV1Event_decrease, false, true,
                pitchSetUpLaw);
        attitudesSequence.addSwitchingCondition(pitchSetUpLaw, endNightDayRdV2Event_increase, true, false,
                dayObservationLaw);
        attitudesSequence.addSwitchingCondition(pitchSetUpLaw, endNightDayRdV2Event_decrease, false, true,
                dayObservationLaw);

        // Initialisation
        //---------------
        if (dayNightEvent.g(new SpacecraftState(initialOrbit)) >= 0) {
            // initial position is in daytime
            attitudesSequence.resetActiveProvider(dayObservationLaw);
            System.out
                    .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY)
                            + " begin with day law");
        } else {
            // initial position is in nighttime
            attitudesSequence.resetActiveProvider(nightRestingLaw);
            System.out
                    .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY)
                            + " begin with night law");
        }

        //----------------------
        // Propagator definition
        //----------------------

        // Propagator : consider the analytical Eckstein-Hechler model
        final Propagator propagator = new EcksteinHechlerPropagator(initialOrbit, attitudesSequence,
                Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS, Constants.EIGEN5C_EARTH_MU,
                Constants.EIGEN5C_EARTH_C20, Constants.EIGEN5C_EARTH_C30, Constants.EIGEN5C_EARTH_C40,
                Constants.EIGEN5C_EARTH_C50, Constants.EIGEN5C_EARTH_C60);
        // Register the switching events to the propagator
        attitudesSequence.registerSwitchEvents(propagator);

        propagator.setMasterMode(10.0, new OrekitFixedStepHandler() {
            private DecimalFormat f1 = new DecimalFormat("0.0000000000000000E00",
                    new DecimalFormatSymbols(Locale.US));
            private Vector3DFormat f2 = new Vector3DFormat(" ", " ", " ", f1);
            private PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
            private PVCoordinatesProvider moon = CelestialBodyFactory.getMoon();
            private Frame eme2000 = FramesFactory.getEME2000();
            private Frame itrf2005 = FramesFactory.getITRF(IERSConventions.IERS_2010, true);

            private String printVector3D(final String name, final Vector3D v) {
                return name + " " + f2.format(v);
            }

            private String printRotation(final String name, final Rotation r) {
                return name + " " + f1.format(r.getQ1()) + " " + f1.format(r.getQ2()) + " "
                        + f1.format(r.getQ3()) + " " + f1.format(r.getQ0());
            }

            private String printRotation2(final String name, final Rotation r) {
                return name + " " + f1.format(-r.getQ1()) + " " + f1.format(-r.getQ2()) + " "
                        + f1.format(-r.getQ3()) + " " + f1.format(-r.getQ0());
            }

            public void init(final SpacecraftState s0, final AbsoluteDate t) {
            }

            public void handleStep(SpacecraftState currentState, boolean isLast) throws PropagationException {
                try {
                    // the Earth position in spacecraft should be along spacecraft Z axis
                    // during nigthtime and away from it during daytime due to roll and pitch offsets
                    final Vector3D earth = currentState.toTransform().transformPosition(Vector3D.ZERO);
                    final double pointingOffset = Vector3D.angle(earth, Vector3D.PLUS_K);

                    // the g function is the eclipse indicator, its an angle between Sun and Earth limb,
                    // positive when Sun is outside of Earth limb, negative when Sun is hidden by Earth limb
                    final double eclipseAngle = dayNightEvent.g(currentState);

                    final double endNightDayTimer1 = endNightDayRdV1Event_decrease.g(currentState);
                    final double endNightDayTimer2 = endNightDayRdV2Event_decrease.g(currentState);
                    final double endDayNightTimer1 = endDayNightRdV1Event_decrease.g(currentState);
                    final double endDayNightTimer2 = endDayNightRdV2Event_decrease.g(currentState);

                    output.add(currentState.getDate() + " " + FastMath.toDegrees(eclipseAngle) + " "
                            + endNightDayTimer1 + " " + endNightDayTimer2 + " " + endDayNightTimer1 + " "
                            + endDayNightTimer2 + " " + FastMath.toDegrees(pointingOffset));
                    final AbsoluteDate date = currentState.getDate();
                    final PVCoordinates pv = currentState.getPVCoordinates(eme2000);
                    final Rotation lvlhRot = new Rotation(pv.getPosition(), pv.getMomentum(), Vector3D.MINUS_K,
                            Vector3D.MINUS_J);
                    final Rotation earthRot = eme2000.getTransformTo(itrf2005, date).getRotation();
                    System.out.println("Scenario::setVectorMap 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " "
                            + printVector3D("sun", sun.getPVCoordinates(date, eme2000).getPosition()) + " "
                            + printVector3D("moon", moon.getPVCoordinates(date, eme2000).getPosition()) + " "
                            + printVector3D("satPos", pv.getPosition()) + " "
                            + printVector3D("satVel", pv.getVelocity()) + " "
                            + printVector3D("orbMom", pv.getMomentum()));
                    System.out.println("Scenario::setQuatMap 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " "
                            + printRotation("earthFrame", earthRot) + " "
                            + printRotation("LVLHFrame", lvlhRot));
                    System.out.println("Scenario::computeStep 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY));
                    System.out.println("  -> " + printRotation2("", currentState.getAttitude().getRotation())
                            + " " + printVector3D("", currentState.getAttitude().getSpin()));
                } catch (OrekitException oe) {
                    throw new PropagationException(oe);
                }
            }
        });

        //----------
        // Propagate
        //----------

        // Propagate from the initial date for the fixed duration
        propagator.propagate(initialDate.shiftedBy(1.75 * 3600.));

        //--------------
        // Print results
        //--------------

        // we print the lines according to lexicographic order, which is chronological order here
        // to make sure out of orders calls between step handler and event handlers don't mess things up
        for (final String line : output) {
            System.out.println(line);
        }

    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}

From source file:ch.zweivelo.renderer.simple.math.RayTest.java

@Before
public void prepareTest() {
    ray = new Ray(Vector3D.ZERO, Vector3D.PLUS_I, new DoubleRange(EPSILON, EPSIPON_MAX));
}

From source file:jtrace.object.Cube.java

/**
 * Create cube with unit side./*from ww w .j  ava2s.  c o  m*/
 */
public Cube() {
    super();

    normals = new Ray[6];
    for (int i = 0; i < 6; i++)
        normals[i] = new Ray();

    normals[0].origin = new Vector3D(0.5, Vector3D.PLUS_I);
    normals[1].origin = new Vector3D(0.5, Vector3D.MINUS_I);
    normals[2].origin = new Vector3D(0.5, Vector3D.PLUS_J);
    normals[3].origin = new Vector3D(0.5, Vector3D.MINUS_J);
    normals[4].origin = new Vector3D(0.5, Vector3D.PLUS_K);
    normals[5].origin = new Vector3D(0.5, Vector3D.MINUS_K);

    normals[0].direction = Vector3D.PLUS_I;
    normals[1].direction = Vector3D.MINUS_I;
    normals[2].direction = Vector3D.PLUS_J;
    normals[3].direction = Vector3D.MINUS_J;
    normals[4].direction = Vector3D.PLUS_K;
    normals[5].direction = Vector3D.MINUS_K;
}

From source file:jtrace.object.Plane.java

/**
 * Create plane that passes through the origin and with a normal pointing
 * in the positive y direction. The positive u and v directions are the
 * x and y unit vectors./*from  w  ww.  j  a v  a 2  s  .  c o  m*/
 */
public Plane() {
    super();

    this.planeNormal = Vector3D.PLUS_K;
    this.planeNorth = Vector3D.PLUS_J;
    this.planeEast = Vector3D.PLUS_I;
}

From source file:ch.zweivelo.renderer.simple.shapes.ShapeTest.java

@Before
public void prepareRay() {
    when(ray.calculatePoint(anyDouble())).thenReturn(Vector3D.PLUS_I);
}

From source file:ch.zweivelo.renderer.simple.math.RayTest.java

@Test
public void testCalculatePoint() throws Exception {
    assertEquals(Vector3D.PLUS_I, ray.calculatePoint(1d));
}

From source file:ch.epfl.leb.sass.models.illuminations.commands.internal.GenerateSquareUniformElectricFieldIT.java

@Before
public void setUp() {
    builder = new GenerateSquareUniformElectricField.Builder();

    builder.width(20).height(30).orientation(Vector3D.PLUS_I).refractiveIndex(refractiveIndex)
            .wavelength(0.532);/*from  ww w  .j a v  a 2s.  co  m*/
}

From source file:ch.zweivelo.renderer.simple.shapes.ShapeTest.java

@Test
public void testIntersect() throws Exception {
    Shape testShape;/*from  w w  w  . ja  v  a2s.com*/
    Optional<CollisionInformation> collisionInformationOptional;

    testShape = ray1 -> Optional.empty();
    collisionInformationOptional = testShape.intersect(ray);
    assertNotNull(collisionInformationOptional);
    assertFalse(collisionInformationOptional.isPresent());

    testShape = ray1 -> Optional.of(1d);
    collisionInformationOptional = testShape.intersect(ray);
    assertNotNull(collisionInformationOptional);
    CollisionInformation collisionInformation = collisionInformationOptional.get();
    assertNotNull(collisionInformation.getShape());
    assertEquals(Vector3D.PLUS_I, collisionInformation.getPoint());
}

From source file:jtrace.object.Cube.java

@Override
public List<Vector3D[]> getWireFrameObjectFrame() {

    Vector3D[] vertices = new Vector3D[8];
    vertices[0] = new Vector3D(0.5, Vector3D.PLUS_K).add(0.5, Vector3D.PLUS_I).add(0.5, Vector3D.PLUS_J);
    vertices[1] = new Vector3D(0.5, Vector3D.PLUS_K).subtract(0.5, Vector3D.PLUS_I).add(0.5, Vector3D.PLUS_J);
    vertices[2] = new Vector3D(0.5, Vector3D.PLUS_K).subtract(0.5, Vector3D.PLUS_I).subtract(0.5,
            Vector3D.PLUS_J);// www  . j a  v  a 2 s  .c  o m
    vertices[3] = new Vector3D(0.5, Vector3D.PLUS_K).add(0.5, Vector3D.PLUS_I).subtract(0.5, Vector3D.PLUS_J);

    vertices[4] = new Vector3D(-0.5, Vector3D.PLUS_K).add(0.5, Vector3D.PLUS_I).add(0.5, Vector3D.PLUS_J);
    vertices[5] = new Vector3D(-0.5, Vector3D.PLUS_K).subtract(0.5, Vector3D.PLUS_I).add(0.5, Vector3D.PLUS_J);
    vertices[6] = new Vector3D(-0.5, Vector3D.PLUS_K).subtract(0.5, Vector3D.PLUS_I).subtract(0.5,
            Vector3D.PLUS_J);
    vertices[7] = new Vector3D(-0.5, Vector3D.PLUS_K).add(0.5, Vector3D.PLUS_I).subtract(0.5, Vector3D.PLUS_J);

    Vector3D[][] edges = { { vertices[0], vertices[1] }, { vertices[1], vertices[2] },
            { vertices[2], vertices[3] }, { vertices[3], vertices[0] }, { vertices[4], vertices[5] },
            { vertices[5], vertices[6] }, { vertices[6], vertices[7] }, { vertices[7], vertices[4] },
            { vertices[0], vertices[4] }, { vertices[1], vertices[5] }, { vertices[2], vertices[6] },
            { vertices[3], vertices[7] } };

    return Arrays.asList(edges);
}

From source file:jtrace.Scene.java

/**
 * Add a set of axes to an image.  If the object parameter is not null,
 * the axes corresponding to the object's coordinate system are drawn.
 * /*from w  w w  .jav a 2  s.  c  o  m*/
 * @param image Image generated using scene's camera
 * @param object (Possibly null) object
 */
private void renderAxes(BufferedImage image, SceneObject object) {

    Graphics gr = image.getGraphics();
    int[] origin, xhat, yhat, zhat;

    if (object == null) {
        origin = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.ZERO);
        xhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_I);
        yhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_J);
        zhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_K);
    } else {
        origin = camera.getPixel(image.getWidth(), image.getHeight(),
                object.objectToSceneVector(Vector3D.ZERO));
        xhat = camera.getPixel(image.getWidth(), image.getHeight(),
                object.objectToSceneVector(Vector3D.PLUS_I));
        yhat = camera.getPixel(image.getWidth(), image.getHeight(),
                object.objectToSceneVector(Vector3D.PLUS_J));
        zhat = camera.getPixel(image.getWidth(), image.getHeight(),
                object.objectToSceneVector(Vector3D.PLUS_K));
    }

    String objName;
    if (object == null)
        objName = "";
    else
        objName = "(" + object.getClass().getSimpleName() + ")";

    gr.setColor(Color.red);
    gr.drawLine(origin[0], origin[1], xhat[0], xhat[1]);
    gr.setColor(Color.white);
    gr.drawString("x " + objName, xhat[0], xhat[1]);

    gr.setColor(Color.green);
    gr.drawLine(origin[0], origin[1], yhat[0], yhat[1]);
    gr.setColor(Color.white);
    gr.drawString("y " + objName, yhat[0], yhat[1]);

    gr.setColor(Color.blue);
    gr.drawLine(origin[0], origin[1], zhat[0], zhat[1]);
    gr.setColor(Color.white);
    gr.drawString("z " + objName, zhat[0], zhat[1]);
}