Example usage for org.apache.commons.math3.geometry.euclidean.threed Line pointAt

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Line pointAt

Introduction

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

Prototype

public Vector3D pointAt(final double abscissa) 

Source Link

Document

Get one point from the line.

Usage

From source file:org.orekit.frames.Transform.java

/** Transform a line.
 * @param line to transform//from w ww. j  a va 2  s  .co m
 * @return transformed line
 */
public Line transformLine(final Line line) {
    final Vector3D transformedP0 = transformPosition(line.getOrigin());
    final Vector3D transformedP1 = transformPosition(line.pointAt(1.0e6));
    return new Line(transformedP0, transformedP1, 1.0e-10);
}

From source file:org.orekit.frames.TransformTest.java

@Test
public void testLine() {
    RandomGenerator random = new Well19937a(0x4a5ff67426c5731fl);
    for (int i = 0; i < 100; ++i) {
        Transform transform = randomTransform(random);
        for (int j = 0; j < 20; ++j) {
            Vector3D p0 = randomVector(1.0e3, random);
            Vector3D p1 = randomVector(1.0e3, random);
            Line l = new Line(p0, p1, 1.0e-10);
            Line transformed = transform.transformLine(l);
            for (int k = 0; k < 10; ++k) {
                Vector3D p = l.pointAt(random.nextDouble() * 1.0e6);
                Assert.assertEquals(0.0, transformed.distance(transform.transformPosition(p)), 1.0e-9);
            }//ww  w.  ja va 2  s  . c o  m
        }
    }
}

From source file:org.orekit.models.earth.Geoid.java

/**
 * {@inheritDoc}//from   ww w.j  a  v  a  2s  . co m
 *
 * <p> The intersection point is computed using a line search along the
 * specified line. This is accurate when the geoid is slowly varying.
 */
@Override
public GeodeticPoint getIntersectionPoint(final Line lineInFrame, final Vector3D closeInFrame,
        final Frame frame, final AbsoluteDate date) throws OrekitException {
    /*
     * It is assumed that the geoid is slowly varying over it's entire
     * surface. Therefore there will one local intersection.
     */
    // transform to body frame
    final Frame bodyFrame = this.getBodyFrame();
    final Transform frameToBody = frame.getTransformTo(bodyFrame, date);
    final Vector3D close = frameToBody.transformPosition(closeInFrame);
    final Line lineInBodyFrame = frameToBody.transformLine(lineInFrame);

    // set the line's direction so the solved for value is always positive
    final Line line;
    if (lineInBodyFrame.getAbscissa(close) < 0) {
        line = lineInBodyFrame.revert();
    } else {
        line = lineInBodyFrame;
    }

    final ReferenceEllipsoid ellipsoid = this.getEllipsoid();
    // calculate end points
    // distance from line to center of earth, squared
    final double d2 = line.pointAt(0.0).getNormSq();
    // the minimum abscissa, squared
    final double minAbscissa2 = FastMath.pow(ellipsoid.getPolarRadius() + MIN_UNDULATION, 2) - d2;
    // smaller end point of the interval = 0.0 or intersection with
    // min_undulation sphere
    final double lowPoint = FastMath.sqrt(FastMath.max(minAbscissa2, 0.0));
    // the maximum abscissa, squared
    final double maxAbscissa2 = FastMath.pow(ellipsoid.getEquatorialRadius() + MAX_UNDULATION, 2) - d2;
    // larger end point of the interval
    final double highPoint = FastMath.sqrt(maxAbscissa2);

    // line search function
    final UnivariateFunction heightFunction = new UnivariateFunction() {
        @Override
        public double value(final double x) {
            try {
                final GeodeticPoint geodetic = transform(line.pointAt(x), bodyFrame, date);
                return geodetic.getAltitude();
            } catch (OrekitException e) {
                // due to frame transform -> re-throw
                throw new RuntimeException(e);
            }
        }
    };

    // compute answer
    if (maxAbscissa2 < 0) {
        // ray does not pierce bounding sphere -> no possible intersection
        return null;
    }
    // solve line search problem to find the intersection
    final UnivariateSolver solver = new BracketingNthOrderBrentSolver();
    try {
        final double abscissa = solver.solve(MAX_EVALUATIONS, heightFunction, lowPoint, highPoint);
        // return intersection point
        return this.transform(line.pointAt(abscissa), bodyFrame, date);
    } catch (TooManyEvaluationsException e) {
        // no intersection
        return null;
    } catch (MathIllegalArgumentException e) {
        // no intersection
        return null;
    }
}