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

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

Introduction

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

Prototype

public Vector3D getOrigin() 

Source Link

Document

Get the line point closest to the origin.

Usage

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

/** {@inheritDoc} */
public GeodeticPoint getIntersectionPoint(final Line line, final Vector3D close, final Frame frame,
        final AbsoluteDate date) throws OrekitException {

    // transform line and close to body frame
    final Transform frameToBodyFrame = frame.getTransformTo(bodyFrame, date);
    final Line lineInBodyFrame = frameToBodyFrame.transformLine(line);
    final Vector3D closeInBodyFrame = frameToBodyFrame.transformPosition(close);
    final double closeAbscissa = lineInBodyFrame.toSubSpace(closeInBodyFrame).getX();

    // compute some miscellaneous variables outside of the loop
    final Vector3D point = lineInBodyFrame.getOrigin();
    final double x = point.getX();
    final double y = point.getY();
    final double z = point.getZ();
    final double z2 = z * z;
    final double r2 = x * x + y * y;

    final Vector3D direction = lineInBodyFrame.getDirection();
    final double dx = direction.getX();
    final double dy = direction.getY();
    final double dz = direction.getZ();
    final double cz2 = dx * dx + dy * dy;

    // abscissa of the intersection as a root of a 2nd degree polynomial :
    // a k^2 - 2 b k + c = 0
    final double a = 1.0 - e2 * cz2;
    final double b = -(g2 * (x * dx + y * dy) + z * dz);
    final double c = g2 * (r2 - ae2) + z2;
    final double b2 = b * b;
    final double ac = a * c;
    if (b2 < ac) {
        return null;
    }//from  w w  w .j  av  a 2 s .  c om
    final double s = FastMath.sqrt(b2 - ac);
    final double k1 = (b < 0) ? (b - s) / a : c / (b + s);
    final double k2 = c / (a * k1);

    // select the right point
    final double k = (FastMath.abs(k1 - closeAbscissa) < FastMath.abs(k2 - closeAbscissa)) ? k1 : k2;
    final Vector3D intersection = lineInBodyFrame.toSpace(new Vector1D(k));
    final double ix = intersection.getX();
    final double iy = intersection.getY();
    final double iz = intersection.getZ();

    final double lambda = FastMath.atan2(iy, ix);
    final double phi = FastMath.atan2(iz, g2 * FastMath.sqrt(ix * ix + iy * iy));
    return new GeodeticPoint(phi, lambda, 0.0);

}

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

/** Transform a line.
 * @param line to transform//from  w w  w  . ja  va  2s .  c  om
 * @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);
}