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

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

Introduction

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

Prototype

public Vector3D getDirection() 

Source Link

Document

Get the normalized direction vector.

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 a  va 2  s.  com
    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:ru.jts_dev.gameserver.movement.MovementService.java

public void moveTo(final GameSession session, final GameCharacter character, final Vector3D end) {
    final Vector3D start = character.getVector3D();

    final Line line = new Line(start, end, 1.0D);
    final double distance = start.distance(end);
    final Vector3D direction = line.getDirection();
    final double angle = Vector3D.angle(start, direction);
    final double degree = FastMath.toDegrees(angle);
    //final Rotation rotation = new Rotation(start, end);
    //final double angle = rotation.getAngle();
    logger.info("MovementService angle = {}", angle);
    logger.info("MovementService degree = {}", degree);
    character.setVector3D(start);/*  ww w  .  j  a  va 2 s  . c o m*/
    final int clientHeading = rotationUtils.convertAngleToClientHeading((int) degree);
    //broadcastService.send(session, new StartRotating(character, clientHeading, 0, 200));
    character.setAngle(degree);
    character.setMoving(true);

    final Runnable moveTask = new MoveTask(session, character, start, end, direction, distance, true);
    ScheduledFuture<?> future = scheduledExecutorService.schedule(moveTask, MOVE_TASK_INTERVAL_MILLIS,
            TimeUnit.MILLISECONDS);
    tasks.put(character.getObjectId(), future);
}