Search in sources :

Example 16 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class Polyline method render.

@Override
public void render(LineRenderSystem renderer, ICamera camera, float alpha) {
    // Render line CPU
    alpha *= cc[3];
    if (pointCloudData != null && pointCloudData.getNumPoints() > 1) {
        Vector3d prev = D31.get();
        for (int i = 0; i < pointCloudData.getNumPoints(); i++) {
            pointCloudData.loadPoint(prev, i);
            prev.add(translation);
            renderer.addPoint(this, (float) prev.x, (float) prev.y, (float) prev.z, cc[0], cc[1], cc[2], alpha);
        }
        renderer.breakLine();
        // Render cap if needed
        if (arrowCap) {
            // Get two last points of line
            Vector3d p1 = D32.get().set(pointCloudData.getX(0), pointCloudData.getY(0), pointCloudData.getZ(0));
            Vector3d p2 = D33.get().set(pointCloudData.getX(1), pointCloudData.getY(1), pointCloudData.getZ(1));
            Vector3d ppm = D34.get().set(p1).sub(p2);
            double p1p2len = ppm.len();
            p1.sub(camera.getPos());
            p2.sub(camera.getPos());
            // Add Arrow cap
            Vector3d p3 = ppm.nor().scl(p1p2len * 0.7).add(p2);
            p3.rotate(p1, 30);
            renderer.addPoint(this, p1.x, p1.y, p1.z, cc[0], cc[1], cc[2], alpha);
            renderer.addPoint(this, p3.x, p3.y, p3.z, cc[0], cc[1], cc[2], alpha);
            renderer.breakLine();
            p3.rotate(p1, -60);
            renderer.addPoint(this, p1.x, p1.y, p1.z, cc[0], cc[1], cc[2], alpha);
            renderer.addPoint(this, p3.x, p3.y, p3.z, cc[0], cc[1], cc[2], alpha);
            renderer.breakLine();
        }
    }
}
Also used : Vector3d(gaiasky.util.math.Vector3d)

Example 17 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class LocationLogManager method addRecord.

/**
 * Adds a new record with the given object, camera and time
 */
public void addRecord(final IFocus object, final ICamera camera, final ITimeFrameProvider time) {
    if (object != null) {
        final Instant entryTime = Instant.now();
        final Instant simulationTime = time.getTime();
        final String name = object.getClosestName();
        // Check if the new record is already in the 10 most recent items
        boolean found = false;
        int stop = Math.max(0, locations.size() - 10);
        for (int i = locations.size() - 1; i >= stop; i--) {
            if (locations.get(i).name.equalsIgnoreCase(name)) {
                found = true;
                break;
            }
        }
        if (!found) {
            // Create record
            final LocationRecord record = new LocationRecord();
            record.name = name;
            record.entryTime = entryTime;
            record.simulationTime = simulationTime;
            record.position = new Vector3b().set(camera.getPos());
            record.direction = new Vector3d().set(camera.getDirection());
            record.up = new Vector3d().set(camera.getUp());
            if (locations.size() == MAX_SIZE) {
                locations.pollFirst();
            }
            locations.add(record);
            EventManager.publish(Event.NEW_LOCATION_RECORD, this, locations);
            logger.debug(I18n.txt("gui.locationlog.newrecord", record.toStringFull()));
        }
    }
}
Also used : Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) Instant(java.time.Instant)

Example 18 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class AttitudeConverter method heliotropicToQuaternionSrsRates.

/**
 * Converts heliotropic angles and rates to the attitude quaternion
 * components and the inertial rates in SRS
 *
 * @param lSun
 *            longitude of the nominal sun [rad]
 * @param xi
 *            solar aspect angle [rad]
 * @param nu
 *            revolving phase angle [rad]
 * @param omega
 *            scan phase angle [rad]
 * @param lSunDot
 *            time derivative of lSun [rad/day]
 * @param nuDot
 *            time derivative of nu [rad/day]
 * @param omegaDot
 *            time derivative of omega [rad/day]
 * @return double[] array {qx, qy, qz, qw, rateX, rateY, rateZ} with rates in [rad/day]
 */
public static double[] heliotropicToQuaternionSrsRates(double lSun, double xi, double nu, double omega, double lSunDot, double nuDot, double omegaDot) {
    /**
     * SOME AXES NEED TO BE SWAPPED TO ALIGN WITH OUR REF SYS:
     * 	GLOBAL	GAIASANDBOX
     * 	Z -> Y
     * 	X -> Z
     * 	Y -> X
     */
    /**
     * Calculate the attitude quaternion *
     */
    Quaterniond q = new Quaterniond(Z_AXIS, OBLIQUITY_DEG);
    q.mul(new Quaterniond(Y_AXIS, Math.toDegrees(lSun)));
    q.mul(new Quaterniond(Z_AXIS, Math.toDegrees(nu - PI_HALF)));
    q.mul(new Quaterniond(X_AXIS, Math.toDegrees(PI_HALF - xi)));
    q.mul(new Quaterniond(Y_AXIS, Math.toDegrees(omega)));
    /**
     * Calculate the inertial rate in SRS by adding the rotations around
     * k (ecliptic pole), s (solar direction), and z:
     */
    Vector3d k = new Vector3d(0, -sinObliquity, cosObliquity);
    k.mul(q);
    double sinLSun = Math.sin(lSun);
    double cosLSun = Math.cos(lSun);
    Vector3d sun = new Vector3d(cosLSun, cosObliquity * sinLSun, sinObliquity * sinLSun);
    sun.mul(q);
    double rateX = k.x * lSunDot + sun.x * nuDot;
    double rateY = k.y * lSunDot + sun.y * nuDot;
    double rateZ = k.z * lSunDot + sun.z * nuDot + omegaDot;
    return new double[] { q.z, q.x, q.y, q.w, rateZ, rateX, rateY };
}
Also used : Vector3d(gaiasky.util.math.Vector3d) Quaterniond(gaiasky.util.math.Quaterniond)

Example 19 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class AttitudeConverter method heliotropicToQuaternions.

/**
 * Converts heliotropic angles and rates to an attitude quaternion and its
 * derivative
 *
 * @param lSun
 *            longitude of the nominal sun [rad]
 * @param xi
 *            solar aspect angle [rad]
 * @param nu
 *            revolving phase angle [rad]
 * @param omega
 *            scan phase angle [rad]
 * @param lSunDot
 *            time derivative of lSun [rad/day]
 * @param nuDot
 *            time derivative of nu [rad/day]
 * @param omegaDot
 *            time derivative of omega [rad/day]
 * @return an array of two quaternions, q (the attitude quaternion) and qDot
 *         (the time derivative of q, per day)
 */
public static Quaterniond[] heliotropicToQuaternions(double lSun, double xi, double nu, double omega, double lSunDot, double nuDot, double omegaDot) {
    /**
     * SOME AXES NEED TO BE SWAPPED TO ALIGN WITH OUR REF SYS:
     * 	GLOBAL ->	GAIASANDBOX
     * 	Z -> Y
     * 	X -> Z
     * 	Y -> X
     */
    /**
     * Calculate the attitude quaternion *
     */
    Quaterniond q = new Quaterniond(Z_AXIS, OBLIQUITY_DEG);
    q.mul(new Quaterniond(Y_AXIS, Math.toDegrees(lSun)));
    q.mul(new Quaterniond(Z_AXIS, Math.toDegrees(nu - PI_HALF)));
    q.mul(new Quaterniond(X_AXIS, Math.toDegrees(PI_HALF - xi)));
    q.mul(new Quaterniond(Y_AXIS, Math.toDegrees(omega)));
    /**
     * Calculate the time derivative of the attitude quaternion using (A.17)
     * in AGIS paper, based on the rates in the ICRS:
     */
    double sinLSun = Math.sin(lSun);
    double cosLSun = Math.cos(lSun);
    Vector3d zInSrs = aux1;
    zInSrs.set(Y_AXIS).rotateVectorByQuaternion(q);
    double rateX = nuDot * cosLSun + omegaDot * zInSrs.x;
    double rateY = -lSunDot * sinObliquity + nuDot * sinLSun * cosObliquity + omegaDot * zInSrs.y;
    double rateZ = lSunDot * cosObliquity + nuDot * sinLSun * sinObliquity + omegaDot * zInSrs.z;
    Quaterniond halfSpinInIcrs = new Quaterniond(0.5 * rateZ, 0.5 * rateX, 0.5 * rateY, 0.0);
    Quaterniond qDot = halfSpinInIcrs.mul(q);
    return new Quaterniond[] { q, qDot };
}
Also used : Vector3d(gaiasky.util.math.Vector3d) Quaterniond(gaiasky.util.math.Quaterniond)

Example 20 with Vector3d

use of gaiasky.util.math.Vector3d in project gaiasky by langurmonkey.

the class AttitudeConverter method getHeliotropicAnglesRates.

/**
 * Calculate the heliotropic angles and rates for a given attitude
 *
 * @param gt
 *            Time for the attitude
 * @param att
 *            attitude
 * @return
 */
public static HeliotropicAnglesRates getHeliotropicAnglesRates(long gt, Attitude att) {
    HeliotropicAnglesRates anglesAndRates = new HeliotropicAnglesRates();
    // k is a unit vector (in ICRS) towards the north ecliptic pole:
    Vector3d k = new Vector3d(0.0, -sinObliquity, cosObliquity);
    // s is a unit vector (in ICRS) towards the nominal sun:
    NslSun sun = new NslSun();
    sun.setTime(gt);
    double cosLSun = Math.cos(sun.getSolarLongitude());
    double sinLSun = Math.sin(sun.getSolarLongitude());
    Vector3d s = new Vector3d(cosLSun, sinLSun * cosObliquity, sinLSun * sinObliquity);
    // xyz[0], xyz[1], xyz[2] are unit vectors (in ICRS) along the SRS axes:
    att.getSrsAxes(xyz);
    // m = s x z is a non-unit vector (of length sinXi) normal to the plane
    // containing s and z:
    Vector3d m = new Vector3d(s);
    m.crs(xyz[2]);
    // compute solar aspect angle xi in range [0, pi]:
    double sinXi = m.len();
    double cosXi = s.dot(xyz[2]);
    anglesAndRates.setFirstAngle(Math.atan2(sinXi, cosXi));
    // NOTE: all subsequent computations fail if sinXi = 0
    // compute revolving phase angle nu in range [-pi, pi]:
    double sinXiCosNu = k.dot(m);
    double sinXiSinNu = k.dot(xyz[2]);
    anglesAndRates.setSecondAngle(Math.atan2(sinXiSinNu, sinXiCosNu));
    // compute spin phase Omega:
    double sinXiCosOmega = -m.dot(xyz[1]);
    double sinXiSinOmega = -m.dot(xyz[0]);
    anglesAndRates.setThirdAngle(Math.atan2(sinXiSinOmega, sinXiCosOmega));
    // inertial spin rate in ICRS:
    Vector3d spin = att.getSpinVectorInIcrs();
    // subtract motion of the nominal sun to get heliotropic spin rate:
    Vector3d spinHel = new Vector3d(spin);
    spinHel.add(k.scl(-sun.getSolarLongitudeDot()));
    // scalar products with s, z, and m are used to determine the angular
    // rates:
    double sSpinHel = s.dot(spinHel);
    double zSpinHel = xyz[2].dot(spinHel);
    double mSpinHel = m.dot(spinHel);
    // d(xi)/dt:
    anglesAndRates.setFirstRate(mSpinHel / sinXi);
    // d(nu)/dt:
    anglesAndRates.setSecondRate((sSpinHel - zSpinHel * cosXi) / (sinXi * sinXi));
    // d(Omega)/dt:
    anglesAndRates.setThirdRate((zSpinHel - sSpinHel * cosXi) / (sinXi * sinXi));
    return anglesAndRates;
}
Also used : Vector3d(gaiasky.util.math.Vector3d) NslSun(gaiasky.util.coord.NslSun)

Aggregations

Vector3d (gaiasky.util.math.Vector3d)120 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)11 Array (com.badlogic.gdx.utils.Array)10 Vector3 (com.badlogic.gdx.math.Vector3)8 Vector3b (gaiasky.util.math.Vector3b)8 PointCloudData (gaiasky.data.util.PointCloudData)7 Keyframe (gaiasky.desktop.util.camera.Keyframe)5 Matrix4d (gaiasky.util.math.Matrix4d)5 Quaterniond (gaiasky.util.math.Quaterniond)5 ArrayList (java.util.ArrayList)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)3 Vector2d (gaiasky.util.math.Vector2d)3 Path (java.nio.file.Path)3 Date (java.util.Date)3 Matrix4 (com.badlogic.gdx.math.Matrix4)2 OrbitComponent (gaiasky.scenegraph.component.OrbitComponent)2 ParticleRecord (gaiasky.scenegraph.particle.ParticleRecord)2