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

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

Introduction

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

Prototype

public Vector3D add(double factor, final Vector<Euclidean3D> v) 

Source Link

Usage

From source file:jtrace.Camera.java

/**
 * Obtain camera ray to trace through scene.
 * /*from  www .  ja va2 s. co m*/
 * @param width Width of image in pixels.
 * @param height Height of image in pixels.
 * @param x X-coordinate of pixel to trace.
 * @param y Y-coordinate of pixel to trace.
 * @return 
 */
public Ray getRay(int width, int height, int x, int y) {

    // Determine angles in each direction.  Note the negative
    // in the expression for the vertical angle - this flips
    // the image in that direction to account for the matrix
    // coordinate scheme used in images.
    double tanThetaUp = -fovUp * (y / (double) height - 0.5);
    double tanThetaRight = fovRight * (x / (double) width - 0.5);

    Vector3D raydir = new Vector3D(1.0, direction);
    raydir = raydir.add(tanThetaUp, up);
    raydir = raydir.add(tanThetaRight, right);

    return new Ray(location, raydir.normalize());
}

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

/** Compute line of sight intersection with body.
 * @param scToBody transform from spacecraft frame to body frame
 * @return intersection point in body frame (only the position is set!)
 * @exception OrekitException if line of sight does not intersect body
 *///  w  w  w.j a  v a2 s  . com
private TimeStampedPVCoordinates losIntersectionWithBody(final Transform scToBody) throws OrekitException {

    // compute satellite pointing axis and position/velocity in body frame
    final Vector3D pointingBodyFrame = scToBody.transformVector(satPointingVector);
    final Vector3D pBodyFrame = scToBody.transformPosition(Vector3D.ZERO);

    // Line from satellite following pointing direction
    // we use arbitrarily the Earth radius as a scaling factor, it could be anything else
    final Line pointingLine = new Line(pBodyFrame,
            pBodyFrame.add(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, pointingBodyFrame), 1.0e-10);

    // Intersection with body shape
    final GeodeticPoint gpIntersection = shape.getIntersectionPoint(pointingLine, pBodyFrame,
            shape.getBodyFrame(), scToBody.getDate());
    final Vector3D pIntersection = (gpIntersection == null) ? null : shape.transform(gpIntersection);

    // Check there is an intersection and it is not in the reverse pointing direction
    if ((pIntersection == null)
            || (Vector3D.dotProduct(pIntersection.subtract(pBodyFrame), pointingBodyFrame) < 0)) {
        throw new OrekitException(OrekitMessages.ATTITUDE_POINTING_LAW_DOES_NOT_POINT_TO_GROUND);
    }

    return new TimeStampedPVCoordinates(scToBody.getDate(), pIntersection, Vector3D.ZERO, Vector3D.ZERO);

}

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

/** Test if defined target belongs to the direction pointed by the satellite
 *//*from  ww w  . j  a  v a  2 s.co  m*/
@Test
public void testTargetInPointingDirection() throws OrekitException {

    // Create computation date
    AbsoluteDate date = new AbsoluteDate(new DateComponents(2008, 04, 07), TimeComponents.H00,
            TimeScalesFactory.getUTC());

    // Reference frame = ITRF 2005
    Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);

    // Elliptic earth shape
    OneAxisEllipsoid earthShape = new OneAxisEllipsoid(6378136.460, 1 / 298.257222101, itrf);

    // Create target pointing attitude provider
    GeodeticPoint geoTarget = new GeodeticPoint(FastMath.toRadians(43.36), FastMath.toRadians(1.26), 600.);
    TargetPointing targetAttitudeLaw = new TargetPointing(FramesFactory.getEME2000(), geoTarget, earthShape);

    //  Satellite position
    // ********************
    // Create satellite position as circular parameters
    CircularOrbit circ = new CircularOrbit(7178000.0, 0.5e-4, -0.5e-4, FastMath.toRadians(50.),
            FastMath.toRadians(270.), FastMath.toRadians(5.300), PositionAngle.MEAN, FramesFactory.getEME2000(),
            date, mu);

    // Transform satellite position to position/velocity parameters in EME2000 frame
    PVCoordinates pvSatEME2000 = circ.getPVCoordinates();

    //  Pointing direction
    // ********************
    // Get satellite attitude rotation, i.e rotation from EME2000 frame to satellite frame
    Rotation rotSatEME2000 = targetAttitudeLaw.getAttitude(circ, date, circ.getFrame()).getRotation();

    // Transform Z axis from satellite frame to EME2000
    Vector3D zSatEME2000 = rotSatEME2000.applyInverseTo(Vector3D.PLUS_K);

    // Line containing satellite point and following pointing direction
    Vector3D p = eme2000ToItrf.transformPosition(pvSatEME2000.getPosition());
    Line pointingLine = new Line(p,
            p.add(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, eme2000ToItrf.transformVector(zSatEME2000)),
            1.0e-10);

    // Check that the line contains earth center
    double distance = pointingLine.distance(earthShape.transform(geoTarget));

    Assert.assertEquals(0, distance, 1.e-7);
}

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

/** Test that pointed target motion is along -X sat axis
 *//*from   ww  w  .j a  v  a2 s .c om*/
@Test
public void testAlignment() throws OrekitException {

    GroundPointing notCompensated = new NadirPointing(circOrbit.getFrame(), earthShape);
    YawCompensation compensated = new YawCompensation(circOrbit.getFrame(), notCompensated);
    Attitude att0 = compensated.getAttitude(circOrbit, circOrbit.getDate(), circOrbit.getFrame());

    // ground point in satellite Z direction
    Vector3D satInert = circOrbit.getPVCoordinates().getPosition();
    Vector3D zInert = att0.getRotation().applyInverseTo(Vector3D.PLUS_K);
    GeodeticPoint gp = earthShape.getIntersectionPoint(
            new Line(satInert, satInert.add(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, zInert), 1.0e-10),
            satInert, circOrbit.getFrame(), circOrbit.getDate());
    PVCoordinates pEarth = new PVCoordinates(earthShape.transform(gp), Vector3D.ZERO, Vector3D.ZERO);

    double minYWithoutCompensation = Double.POSITIVE_INFINITY;
    double maxYWithoutCompensation = Double.NEGATIVE_INFINITY;
    double minYDotWithoutCompensation = Double.POSITIVE_INFINITY;
    double maxYDotWithoutCompensation = Double.NEGATIVE_INFINITY;
    double minYWithCompensation = Double.POSITIVE_INFINITY;
    double maxYWithCompensation = Double.NEGATIVE_INFINITY;
    double minYDotWithCompensation = Double.POSITIVE_INFINITY;
    double maxYDotWithCompensation = Double.NEGATIVE_INFINITY;
    for (double dt = -0.2; dt < 0.2; dt += 0.002) {

        PVCoordinates withoutCompensation = toSpacecraft(pEarth, circOrbit.shiftedBy(dt), notCompensated);
        if (FastMath.abs(withoutCompensation.getPosition().getX()) <= 1000.0) {
            minYWithoutCompensation = FastMath.min(minYWithoutCompensation,
                    withoutCompensation.getPosition().getY());
            maxYWithoutCompensation = FastMath.max(maxYWithoutCompensation,
                    withoutCompensation.getPosition().getY());
            minYDotWithoutCompensation = FastMath.min(minYDotWithoutCompensation,
                    withoutCompensation.getVelocity().getY());
            maxYDotWithoutCompensation = FastMath.max(maxYDotWithoutCompensation,
                    withoutCompensation.getVelocity().getY());
        }

        PVCoordinates withCompensation = toSpacecraft(pEarth, circOrbit.shiftedBy(dt), compensated);
        if (FastMath.abs(withCompensation.getPosition().getX()) <= 1000.0) {
            minYWithCompensation = FastMath.min(minYWithCompensation, withCompensation.getPosition().getY());
            maxYWithCompensation = FastMath.max(maxYWithCompensation, withCompensation.getPosition().getY());
            minYDotWithCompensation = FastMath.min(minYDotWithCompensation,
                    withCompensation.getVelocity().getY());
            maxYDotWithCompensation = FastMath.max(maxYDotWithCompensation,
                    withCompensation.getVelocity().getY());
        }

    }

    // when the ground point is close to cross the push-broom line (i.e. when x decreases from +1000m to -1000m)
    // it will drift along the Y axis if we don't apply compensation
    // but will remain nearly at y=0 if we do apply compensation
    // in fact, as the yaw compensation mode removes the linear drift,
    // what remains is a parabola y = a ux
    Assert.assertEquals(-55.7056, minYWithoutCompensation, 0.0001);
    Assert.assertEquals(+55.7056, maxYWithoutCompensation, 0.0001);
    Assert.assertEquals(352.5667, minYDotWithoutCompensation, 0.0001);
    Assert.assertEquals(352.5677, maxYDotWithoutCompensation, 0.0001);
    Assert.assertEquals(0.0000, minYWithCompensation, 0.0001);
    Assert.assertEquals(0.0008, maxYWithCompensation, 0.0001);
    Assert.assertEquals(-0.0101, minYDotWithCompensation, 0.0001);
    Assert.assertEquals(0.0102, maxYDotWithCompensation, 0.0001);

}