Java 类javax.vecmath.AxisAngle4d 实例源码

项目:cmoct-sourcecode    文件:RotationControlPanel.java   
public void copyData()
{
    Quat4d dat = panel.getRender().getRotationAttr().getValue();

    // Transform3D rot = new Transform3D();
    // rot.setRotation(dat);

    AxisAngle4d rot = new AxisAngle4d();
    rot.set(dat);

    int rotX = (int) (dat.x * steps);
    int rotY = (int) (dat.y * steps);
    int rotZ = (int) (dat.z * steps);
    int rotW = (int) (dat.w * steps);

    setAllowUpdate(false);
    xSlide.setValue(rotX);
    ySlide.setValue(rotY);
    zSlide.setValue(rotZ);
    wManualSlide.setValue(rotW);
    setAllowUpdate(true);
}
项目:ct-sim    文件:ThreeDBot.java   
/**
 * Setzt Heading
 * @param headingInWorldCoord   Heading in Welt-Koordinaten
 */ 
public final synchronized void setHeading(Vector3d headingInWorldCoord) {
    // Optimierung (Transform-Kram ist teuer)
    if (this.headingInWorldCoord.equals(headingInWorldCoord)) {
        return;
    }

    /*
     * Sinn der Methode: Transform3D aktualisieren, das von Bot- nach
     * Weltkoordinaten transformiert. (Dieses steckt in unserer
     * TransformGroup.)
     */
    this.headingInWorldCoord = headingInWorldCoord;

    // Winkel zwischen Welt pos. y-Achse und Bot pos. y-Achse
    double angleInRad = radiansToYAxis(headingInWorldCoord);

    Transform3D t = new Transform3D();
    transformgrp.getTransform(t);
    t.setRotation(new AxisAngle4d(0, 0, 1, angleInRad));
    transformgrp.setTransform(t);
}
项目:Hard-Science    文件:QuadHelper.java   
/**
 * Builds the appropriate quaternion to rotate around the given orthogonalAxis.
 */
public static Quat4f rotationForAxis(EnumFacing.Axis axis, double degrees)
{
    Quat4f retVal = new Quat4f();
    switch (axis) {
    case X:
        retVal.set(new AxisAngle4d(1, 0, 0, Math.toRadians(degrees)));
        break;
    case Y:
        retVal.set(new AxisAngle4d(0, 1, 0, Math.toRadians(degrees)));
        break;
    case Z:
        retVal.set(new AxisAngle4d(0, 0, 1, Math.toRadians(degrees)));
        break;
    }
    return retVal;
}
项目:vzome-core    文件:Camera.java   
/**
 * Get the mapping from view to world coordinates
 * @param trans
 */
public void getViewTransform( Matrix4d matrix, double angle )
{
    Point3d eyePoint = new Point3d( mLookAtPoint );
    Vector3d dir = new Vector3d( mLookDirection );
    if ( angle != 0d ) {
        double[] rotMat = new double[16];
        AxisAngle4d rotAA = new AxisAngle4d( mUpDirection, angle );
        set( rotAA, rotMat );
        transform( rotMat, dir );
    }
    dir .scale( -mDistance );
    eyePoint .add( dir );

    double[] mat = new double[16];
    lookAt( mat, eyePoint, mLookAtPoint, mUpDirection );
    matrix .set( mat );
}
项目:biojava    文件:RotationGroup.java   
public void setC1(int n) {
    Rotation r = new Rotation();
    List<Integer> permutation = new ArrayList<Integer>(n);
    for (int i = 0; i < n; i++) {
        permutation.add(i);
    }
    r.setPermutation(permutation);
    Matrix4d m = new Matrix4d();
    m.setIdentity();
    r.setTransformation(m);
    r.setAxisAngle(new AxisAngle4d());
    r.setFold(1);
    r.setScores(new QuatSymmetryScores());
    rotations.add(r);
    pointGroup = "C1";
}
项目:NK-VirtualGlobe    文件:J3DVisibilitySensor.java   
/**
 * Invoked when the user enters or leaves an area.
 *
 * @param visible true when the user enters the area
 * @param position The position of the user on entry/exit
 * @param orientation The orientation of the user there
 * @param localPosition The vworld transform object for the class
 *   that implemented this listener
 */
public void visibilityStateChange(boolean visible,
                                  Point3d position,
                                  AxisAngle4d orientation,
                                  Transform3D localPosition) {

    if(visible) {
        vfEnterTime = vrmlClock.getTime();

        hasChanged[FIELD_ENTER_TIME] = true;
        fireFieldChanged(FIELD_ENTER_TIME);

        vfIsActive = true;
        hasChanged[FIELD_IS_ACTIVE] = true;
    } else {
        vfExitTime = vrmlClock.getTime();

        hasChanged[FIELD_EXIT_TIME] = true;
        fireFieldChanged(FIELD_EXIT_TIME);

        vfIsActive = false;
        hasChanged[FIELD_IS_ACTIVE] = true;
    }

    fireFieldChanged(FIELD_IS_ACTIVE);
}
项目:CustomWorldGen    文件:ForgeBlockStateV1.java   
public static Quat4f parseAxisRotation(JsonElement e)
{
    if (!e.isJsonObject()) throw new JsonParseException("Axis rotation: object expected, got: " + e);
    JsonObject obj  = e.getAsJsonObject();
    if (obj.entrySet().size() != 1) throw new JsonParseException("Axis rotation: expected single axis object, got: " + e);
    Map.Entry<String, JsonElement> entry = obj.entrySet().iterator().next();
    Quat4f ret = new Quat4f();
    try
    {
        if (entry.getKey().equals("x"))
        {
            ret.set(new AxisAngle4d(1, 0, 0, Math.toRadians(entry.getValue().getAsNumber().floatValue())));
        }
        else if (entry.getKey().equals("y"))
        {
            ret.set(new AxisAngle4d(0, 1, 0, Math.toRadians(entry.getValue().getAsNumber().floatValue())));
        }
        else if (entry.getKey().equals("z"))
        {
            ret.set(new AxisAngle4d(0, 0, 1, Math.toRadians(entry.getValue().getAsNumber().floatValue())));
        }
        else throw new JsonParseException("Axis rotation: expected single axis key, got: " + entry.getKey());
    }
    catch(ClassCastException ex)
    {
        throw new JsonParseException("Axis rotation value: expected number, got: " + entry.getValue());
    }
    return ret;
}
项目:AquaRegia    文件:VectorUtils.java   
/**
 * Create a matrix that rotates around the specified axis by the specified angle.
 *
 * @param axis    The axis
 * @param radians The angle in radians
 * @return The rotation matrix
 */
public static Matrix3d getRotationMatrix(EnumFacing.Axis axis, double radians) {
    final Vec3i axisDirectionVector = AXIS_DIRECTION_VECTORS.get(axis);
    final AxisAngle4d axisAngle = new AxisAngle4d(axisDirectionVector.getX(), axisDirectionVector.getY(), axisDirectionVector.getZ(), radians);

    final Matrix3d rotationMatrix = new Matrix3d();
    rotationMatrix.set(axisAngle);

    return rotationMatrix;
}
项目:BlockSystems    文件:Matrix.java   
public Matrix(int poolSize) {
    Preconditions.checkArgument(poolSize >= 0, "poolSize must be greater or equal to zero");
    this.matrixPool = new Pool<>(Matrix4d::new, poolSize);
    this.vectorPool = new Pool<>(Vector3d::new, poolSize);
    this.axisAnglePool = new Pool<>(AxisAngle4d::new, poolSize);
    this.matrixStack = new Stack<>();
    Matrix4d mat = new Matrix4d();
    mat.setIdentity();
    this.matrixStack.push(mat);
}
项目:BlockSystems    文件:Matrix.java   
public void rotate(double angle, double x, double y, double z) {
    Matrix4d mat = this.matrixStack.peek();
    Matrix4d rotation = this.getMatrix();
    rotation.setIdentity();
    AxisAngle4d axisAngle = this.getAxisAngle(x, y, z, angle);
    rotation.setRotation(axisAngle);
    this.freeAxisAngle(axisAngle);
    mat.mul(rotation);
    this.freeMatrix(rotation);
}
项目:cmoct-sourcecode    文件:RotationControlPanel.java   
public void updateRotation()
{
    double xRot = xSlide.getValue() / (double) (steps);
    double yRot = ySlide.getValue() / (double) (steps);
    double zRot = zSlide.getValue() / (double) (steps);
    double wRot = wManualSlide.getValue() / (double) (steps);

    wRot *= 3.14;
    // System.out.println(steps);
    // System.out.println(xSlide.getValue() + " - " + xRot);
    // System.out.println(ySlide.getValue() + " - " + yRot);
    // System.out.println(zSlide.getValue() + " - " + zRot);
    // System.out.println(wManualSlide.getValue() + " - " + wRot);

    Transform3D tra = new Transform3D();
    AxisAngle4d rotation = new AxisAngle4d();
    rotation.setX(xRot);
    rotation.setY(yRot);
    rotation.setZ(zRot);
    rotation.setAngle(wRot);

    tra.set(rotation);

    Quat4d dat = new Quat4d();
    tra.get(dat);
    // System.out.println("\nSetting Values\n" + dat.x);
    // System.out.println(dat.y);
    // System.out.println(dat.z);
    // System.out.println(dat.w);
    panel.getRender().getRotationAttr().set(tra);
    panel.getRender().restoreXform();

}
项目:ct-sim    文件:ThreeDBot.java   
/**
 * Zeichnet eine Box zu Debug-Zwecken, indem sie zu TestBG hinzugefuegt wird
 * @param x Groesse in X-Richtung
 * @param y Groesse in Y-Richtung
 * @param z Groesse in Z-Richtung
 * @param transform Transformation, die auf die Box angewendet werden soll
 * @param angle Winkel, um den die Box gedreht werden soll
 */
public void showDebugBox(final double x, final double y, final double z, Transform3D transform, double angle) {
    final Box box = new Box((float) x, (float) y, (float) z, null);
    transform.setRotation(new AxisAngle4d(0, 0, 1, angle));
    TransformGroup tg = new TransformGroup();
    tg.setTransform(transform);
    tg.addChild(box);
    BranchGroup bg = new BranchGroup();
    bg.setCapability(BranchGroup.ALLOW_DETACH);
    bg.addChild(tg);
    testBG.addChild(bg);
}
项目:vzome-desktop    文件:Trackball.java   
private  void trackballRolled( MouseEvent e )
  {
      // get the new coordinates
      int newX = e .getX();
      int newY = e .getY();
      // the angle in degrees is just the pixel differences
      int angleX = newX - oldX;
      int angleY = newY - oldY;
      // set the old values
      oldX = newX;
      oldY = newY;

      double radians = ((double) angleY) * mSpeed;
      AxisAngle4d yAngle = new AxisAngle4d( new Vector3d( 1d, 0d, 0d ), radians );

      radians = ((double) angleX) * mSpeed;
      AxisAngle4d xAngle = new AxisAngle4d( new Vector3d( 0d, 1d, 0d ), radians );

Matrix4d x = new Matrix4d();
      x.set( xAngle );
Matrix4d y = new Matrix4d();
      y.set( yAngle );
      x .mul( y );
      Quat4d q = new Quat4d();
      x .get( q );

      trackballRolled( q );
  }
项目:geometria    文件:GCamera.java   
public void turn(Vector3d axis, int stroke, GFigure figure) {
    double angle = stroke * GCameraSpinner.SPIN_ANGLE;
    AxisAngle4d axisAngle = new AxisAngle4d(axis, angle);
    Matrix3d rotMatrix = new Matrix3d();
    rotMatrix.set(axisAngle);
    rotMatrix.mulNormalize(attitude);
    attitude.set(rotMatrix);
    figure.cameraTurned();
}
项目:geometria    文件:GCamera.java   
public static Matrix3d defaultAttitude() {
    AxisAngle4d axisAngle1 = new AxisAngle4d(1, 1, 1, -Math.PI * 2 / 3);
    Matrix3d m1 = new Matrix3d();
    m1.set(axisAngle1);
    AxisAngle4d axisAngle2 = new AxisAngle4d(0, 1, 0, Math.PI / 7);
    Matrix3d m2 = new Matrix3d();
    m2.set(axisAngle2);
    AxisAngle4d axisAngle3 = new AxisAngle4d(1, 0, 0, Math.PI / 15);
    Matrix3d m3 = new Matrix3d();
    m3.set(axisAngle3);
    m2.mul(m1);
    m3.mul(m2);
    return m3;
}
项目:geometria    文件:GCamera.java   
public void turn(Vector3d axis, int stroke, GFigure figure) {
    double angle = stroke * GCameraSpinner.SPIN_ANGLE;
    AxisAngle4d axisAngle = new AxisAngle4d(axis, angle);
    Matrix3d rotMatrix = new Matrix3d();
    rotMatrix.set(axisAngle);
    rotMatrix.mulNormalize(attitude);
    attitude.set(rotMatrix);
    figure.cameraTurned();
}
项目:geometria    文件:GCamera.java   
public static Matrix3d defaultAttitude() {
    AxisAngle4d axisAngle1 = new AxisAngle4d(1, 1, 1, -Math.PI * 2 / 3);
    Matrix3d m1 = new Matrix3d();
    m1.set(axisAngle1);
    AxisAngle4d axisAngle2 = new AxisAngle4d(0, 1, 0, Math.PI / 7);
    Matrix3d m2 = new Matrix3d();
    m2.set(axisAngle2);
    AxisAngle4d axisAngle3 = new AxisAngle4d(1, 0, 0, Math.PI / 15);
    Matrix3d m3 = new Matrix3d();
    m3.set(axisAngle3);
    m2.mul(m1);
    m3.mul(m2);
    return m3;
}
项目:vzome-desktop    文件:Trackball.java   
private  void trackballRolled( MouseEvent e )
  {
      // get the new coordinates
      int newX = e .getX();
      int newY = e .getY();
      // the angle in degrees is just the pixel differences
      int angleX = newX - oldX;
      int angleY = newY - oldY;
      // set the old values
      oldX = newX;
      oldY = newY;

      double radians = ((double) angleY) * mSpeed;
      AxisAngle4d yAngle = new AxisAngle4d( new Vector3d( 1d, 0d, 0d ), radians );

      radians = ((double) angleX) * mSpeed;
      AxisAngle4d xAngle = new AxisAngle4d( new Vector3d( 0d, 1d, 0d ), radians );

Matrix4d x = new Matrix4d();
      x.set( xAngle );
Matrix4d y = new Matrix4d();
      y.set( yAngle );
      x .mul( y );
      Quat4d q = new Quat4d();
      x .get( q );

      trackballRolled( q );
  }
项目:geowave    文件:EarthVector.java   
/**
 * Rotates this coordinate about the input vector through the input angle
 * (radians - because we usually use this internally)
 * 
 * @param vecAxis
 *            The axis of rotation
 * @param ang
 *            The angle of rotation (in radians)
 */
// public Vector3d rotate( Vector3d vecAxis, double ang )
// {
// Vector3d vec1 = new Vector3d(vecAxis);
// vec1.normalize();
// Vector3d vec2 = new Vector3d();
// vec2.cross(vec1, ecfVector);
// Vector3d vec3 = new Vector3d();
// vec3.cross(vec2, vec1);
//
// double ang_sin = Math.sin(ang);
// double ang_cos = Math.cos(ang) - 1.0;
//
// Vector3d result = new Vector3d();
// result.x = ecfVector.x + ang_cos*vec3.x + ang_sin*vec2.x;
// result.y = ecfVector.y + ang_cos*vec3.y + ang_sin*vec2.y;
// result.z = ecfVector.z + ang_cos*vec3.z + ang_sin*vec2.z;
//
// return result;
// }
public Vector3d rotate(
        final Vector3d rotAxis,
        final double angle ) {
    final Vector3d thisVec = new Vector3d(
            ecfVector);
    final Vector3d axis = new Vector3d(
            rotAxis);
    axis.normalize();

    final Matrix3d trans = new Matrix3d();
    trans.set(new AxisAngle4d(
            axis,
            angle));

    trans.transform(thisVec);

    return thisVec;
}
项目:biojava    文件:SymmetryTools.java   
/**
 * Determines if two symmetry axis are equivalent inside the error
 * threshold. It only takes into account the direction of the vector where
 * the rotation is made: the angle and translation are not taken into
 * account.
 *
 * @param axis1
 * @param axis2
 * @param epsilon
 *            error allowed in the axis comparison
 * @return true if equivalent, false otherwise
 */
@Deprecated
public static boolean equivalentAxes(Matrix4d axis1, Matrix4d axis2,
        double epsilon) {

    AxisAngle4d rot1 = new AxisAngle4d();
    rot1.set(axis1);
    AxisAngle4d rot2 = new AxisAngle4d();
    rot2.set(axis2);

    // rot1.epsilonEquals(rot2, error); //that also compares angle
    // L-infinite distance without comparing the angle (epsilonEquals)
    List<Double> sameDir = new ArrayList<Double>();
    sameDir.add(Math.abs(rot1.x - rot2.x));
    sameDir.add(Math.abs(rot1.y - rot2.y));
    sameDir.add(Math.abs(rot1.z - rot2.z));

    List<Double> otherDir = new ArrayList<Double>();
    otherDir.add(Math.abs(rot1.x + rot2.x));
    otherDir.add(Math.abs(rot1.y + rot2.y));
    otherDir.add(Math.abs(rot1.z + rot2.z));

    Double error = Math.min(Collections.max(sameDir),
            Collections.max(otherDir));

    return error < epsilon;
}
项目:biojava    文件:RotationGroup.java   
/**
 * Add E operation to the highest order rotation axis. By definition
 * E belongs to the highest order axis.
 */
private void setEAxis() {
    Rotation e = rotations.get(0);
    Rotation h = rotations.get(principalAxisIndex);
    e.setAxisAngle(new AxisAngle4d(h.getAxisAngle()));
    e.getAxisAngle().angle = 0.0;
    e.setFold(h.getFold());
}
项目:biojava    文件:SystematicSolver.java   
private Rotation createSymmetryOperation(List<Integer> permutation, Matrix4d transformation, AxisAngle4d axisAngle, int fold, QuatSymmetryScores scores) {
    Rotation s = new Rotation();
    s.setPermutation(new ArrayList<Integer>(permutation));
    s.setTransformation(new Matrix4d(transformation));
    s.setAxisAngle(new AxisAngle4d(axisAngle));
    s.setFold(fold);
    s.setScores(scores);
    return s;
}
项目:biojava    文件:C2RotationSolver.java   
private void solve() {
        initialize();
        Vector3d trans = new Vector3d(subunits.getCentroid());
        trans.negate();
        List<Point3d[]> traces = subunits.getTraces();

//      Point3d[] x = SuperPosition.clonePoint3dArray(traces.get(0));
//      SuperPosition.center(x);
//      Point3d[] y = SuperPosition.clonePoint3dArray(traces.get(1));
//      SuperPosition.center(y);

        Point3d[] x = CalcPoint.clonePoint3dArray(traces.get(0));
        CalcPoint.translate(trans, x);
        Point3d[] y = CalcPoint.clonePoint3dArray(traces.get(1));
        CalcPoint.translate(trans, y);

        // TODO implement this piece of code using at origin superposition
        Quat4d quat = UnitQuaternions.relativeOrientation(
                x, y);
        AxisAngle4d axisAngle = new AxisAngle4d();
        Matrix4d transformation = new Matrix4d();

        transformation.set(quat);
        axisAngle.set(quat);

        Vector3d axis = new Vector3d(axisAngle.x, axisAngle.y, axisAngle.z);
        if (axis.lengthSquared() < 1.0E-6) {
            axisAngle.x = 0;
            axisAngle.y = 0;
            axisAngle.z = 1;
            axisAngle.angle = 0;
        } else {
            axis.normalize();
            axisAngle.x = axis.x;
            axisAngle.y = axis.y;
            axisAngle.z = axis.z;
        }

        CalcPoint.transform(transformation, y);

        // if rmsd or angle deviation is above threshold, stop
        double angleThresholdRadians = Math.toRadians(parameters.getAngleThreshold());
        double deltaAngle = Math.abs(Math.PI-axisAngle.angle);

        if (deltaAngle > angleThresholdRadians) {
            rotations.setC1(subunits.getSubunitCount());
            return;
        }

        // add unit operation
        addEOperation();

        // add C2 operation
        int fold = 2;
        combineWithTranslation(transformation);
        List<Integer> permutation = Arrays.asList(1,0);
        QuatSymmetryScores scores = QuatSuperpositionScorer.calcScores(subunits, transformation, permutation);
        scores.setRmsdCenters(0.0); // rmsd for superposition of two subunits centers is zero by definition

        if (scores.getRmsd() > parameters.getRmsdThreshold() || deltaAngle > angleThresholdRadians) {
            rotations.setC1(subunits.getSubunitCount());
            return;
        }

        Rotation symmetryOperation = createSymmetryOperation(permutation, transformation, axisAngle, fold, scores);
        rotations.addRotation(symmetryOperation);
    }
项目:biojava    文件:C2RotationSolver.java   
private void addEOperation() {
    List<Integer> permutation = Arrays.asList(new Integer[]{0,1});
    Matrix4d transformation = new Matrix4d();
    transformation.setIdentity();
    combineWithTranslation(transformation);
    AxisAngle4d axisAngle = new AxisAngle4d();
    QuatSymmetryScores scores = new QuatSymmetryScores();
    int fold = 1; // ??
    Rotation rotation = createSymmetryOperation(permutation, transformation, axisAngle, fold, scores);
    rotations.addRotation(rotation);
}
项目:biojava    文件:C2RotationSolver.java   
private Rotation createSymmetryOperation(List<Integer> permutation, Matrix4d transformation, AxisAngle4d axisAngle, int fold, QuatSymmetryScores scores) {
    Rotation s = new Rotation();
    s.setPermutation(new ArrayList<Integer>(permutation));
    s.setTransformation(new Matrix4d(transformation));
    s.setAxisAngle(new AxisAngle4d(axisAngle));
    s.setFold(fold);
    s.setScores(scores);
    return s;
}
项目:biojava    文件:RotationSolver.java   
private static Rotation createSymmetryOperation(List<Integer> permutation, Matrix4d transformation, AxisAngle4d axisAngle, int fold, QuatSymmetryScores scores) {
    Rotation s = new Rotation();
    s.setPermutation(new ArrayList<Integer>(permutation));
    s.setTransformation(new Matrix4d(transformation));
    s.setAxisAngle(new AxisAngle4d(axisAngle));
    s.setFold(fold);
    s.setScores(scores);

    return s;
}
项目:biojava    文件:SpaceGroup.java   
/**
 * Given a rotation matrix calculates the rotation axis and angle for it.
 * The angle is calculated from the trace, the axis from the eigenvalue
 * decomposition.
 * If given matrix is improper rotation or identity matrix then
 * axis (0,0,0) and angle 0 are returned.
 * @param m
 * @return
 * @throws IllegalArgumentException if given matrix is not a rotation matrix (determinant not 1 or -1)
 */
public static AxisAngle4d getRotAxisAndAngle(Matrix3d m) {
    double determinant = m.determinant();

    if (!(Math.abs(determinant)-1.0<DELTA)) throw new IllegalArgumentException("Given matrix is not a rotation matrix");

    AxisAngle4d axisAndAngle = new AxisAngle4d(new Vector3d(0,0,0),0);

    double[] d = {m.m00,m.m10,m.m20,
            m.m01,m.m11,m.m21,
            m.m02,m.m12,m.m22};

    Matrix r = new Matrix(d,3);

    if (!deltaComp(r.det(), 1.0, DELTA)) {
        // improper rotation: we return axis 0,0,0 and angle 0
        return axisAndAngle;
    }

    EigenvalueDecomposition evd = new EigenvalueDecomposition(r);

    Matrix eval = evd.getD();
    if (deltaComp(eval.get(0, 0),1.0,DELTA) && deltaComp(eval.get(1, 1),1.0,DELTA) && deltaComp(eval.get(2, 2),1.0,DELTA)) {
        // the rotation is an identity: we return axis 0,0,0 and angle 0
        return axisAndAngle;
    }
    int indexOfEv1;
    for (indexOfEv1=0;indexOfEv1<3;indexOfEv1++) {
        if (deltaComp(eval.get(indexOfEv1, indexOfEv1),1,DELTA)) break;
    }
    Matrix evec = evd.getV();
    axisAndAngle.set(new Vector3d(evec.get(0,indexOfEv1), evec.get(1, indexOfEv1), evec.get(2, indexOfEv1)),
            Math.acos((eval.trace()-1.0)/2.0));

    return axisAndAngle;
}
项目:biojava    文件:TestUnitQuaternions.java   
/**
 * Test {@link UnitQuaternions#relativeOrientation(Point3d[], Point3d[])} on
 * a real structure. Test recovering of the angle applied.
 * 
 * @throws StructureException
 * @throws IOException
 */
@Test
public void testRelativeOrientation() throws IOException,
        StructureException {

    // Get points from a structure.
    Structure pdb = StructureIO.getStructure("4hhb.A");
    Point3d[] cloud = Calc.atomsToPoints(StructureTools
            .getRepresentativeAtomArray(pdb));
    Point3d[] cloud2 = CalcPoint.clonePoint3dArray(cloud);

    // Test orientation angle equal to 0 at this point
    double angle = UnitQuaternions.orientationAngle(cloud, cloud2, false);
    assertEquals(angle, 0, 0.001);

    // Apply a 30 degree rotation to cloud
    AxisAngle4d axis = new AxisAngle4d(new Vector3d(1,1,1), Math.PI / 6);
    Matrix4d transform = new Matrix4d();
    transform.set(axis);

    CalcPoint.transform(transform, cloud);
    angle = UnitQuaternions.orientationAngle(cloud, cloud2, false);
    angle = Math.min(Math.abs(2 * Math.PI - angle), angle);

    // Test that angle was recovered
    assertEquals(angle, Math.PI / 6, 0.001);
}
项目:NK-VirtualGlobe    文件:J3DLOD.java   
/**
 * Notification that the object is still visible, but that the
 * viewer reference point has changed. Ignored for this implementation.
 *
 * @param position The new position of the user
 * @param orientation The orientation of the user there
 * @param localPosition The vworld transform object for the class
 *   that implemented this listener
 */
public void viewPositionChanged(Point3d position,
                                AxisAngle4d orientation,
                                Transform3D localPosition) {

    // Needs to account for vfCenter
    localPosition.get(translation);
    translation.sub(position);

    double total_d = translation.lengthSquared();

    // look through the range array and see if this matches. Only change
    // the visible object if they don't match.

    int active_now = rangeLen;
    for(int i = 0; i < rangeLen; i++) {
        if(total_d <= rangeSquared[i]) {
            active_now = i;
            break;
        }
    }

    if(active_now != activeObject) {
        viewableChild.clear(activeObject);
        viewableChild.set(active_now);
        implSwitch.setWhichChild(Switch.CHILD_MASK);
        implSwitch.setChildMask(viewableChild);
        activeObject = active_now;

        setLevelChanged(activeObject);
    }
}
项目:NK-VirtualGlobe    文件:DefaultSensorManager.java   
/**
 * Create a new default instance of the manager. It will only register a
 * handler for TimeSensors. Anything other than that will require the end
 * user code to register an appropriate manager.
 */
public DefaultSensorManager() {
    super();

    inputHandler = new DefaultUserInputHandler();
    inputHandler.setVRMLClock(timeSensors);

    keyEvents = new KeyEvent[DEFAULT_EVENT_SIZE];

    vpMatrix = new Transform3D();
    localMatrix = new Transform3D();
    t3dPosition = new Vector3d();
    position = new Point3d();
    orientation = new Vector3d();
    oriAxisAngle = new AxisAngle4d();

    visibilityHandler = new VisibilityManager();
    areaHandler = new AreaManager();

    tmpTextures = new Texture2D[6];
    tmpTextureFlags = new boolean[6];
    tmpColor = new float[24];
    tmpAngle = new float[7];
    mat = new Matrix4d();

    orthoWarning = false;
}
项目:NK-VirtualGlobe    文件:OGLGeoLocation.java   
/**
 * Transform the orientation of the object to one in the local coordinate
 * system.
 */
private void getLocalOrientation(double[] position, AxisAngle4f axis) {
    posVec.x = position[0];
    posVec.y = position[1];
    posVec.z = position[2];

    double norm = posVec.x * posVec.x + posVec.y * posVec.y + posVec.z * posVec.z;

    if(norm != 0) {
        norm = 1 / Math.sqrt(norm);
        posVec.x *= norm;
        posVec.y *= norm;
        posVec.z *= norm;
    } else {
        posVec.x = 0.0f;
        posVec.y = 1.0f;
        posVec.z = 0.0f;
    }

    // Align Y and X axis
    double angle = YUP.angle(posVec);

    posVec.cross(YUP, posVec);

    axis.x = (float) posVec.x;
    axis.y = (float) posVec.y;
    axis.z = (float) posVec.z;
    axis.angle = (float) angle;

    angle = XUP.angle(posVec);

    posVec.cross(XUP, posVec);

    Quat4d orig = new Quat4d();
    orig.set(axis);
    Quat4d rot = new Quat4d();
    rot.set(new AxisAngle4d(posVec.x, posVec.y, posVec.z, angle));
    orig.mul(rot);
    axis.set(orig);
}
项目:EnderIO    文件:RotatingSmartItemModel.java   
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
  Pair<? extends IBakedModel, Matrix4f> perspective = parent.handlePerspective(cameraTransformType);

  double r = (EnderIO.proxy.getTickCount() % 360) + Minecraft.getMinecraft().getRenderPartialTicks();

  TRSRTransformation transformOrig = new TRSRTransformation(perspective.getRight());
  Quat4f leftRot = transformOrig.getLeftRot();
  Quat4f yRotation = new Quat4f();
  yRotation.set(new AxisAngle4d(0, 1, 0, Math.toRadians(r * speed)));
  leftRot.mul(yRotation);
  TRSRTransformation transformNew = new TRSRTransformation(transformOrig.getTranslation(), leftRot, transformOrig.getScale(), transformOrig.getRightRot());

  return Pair.of(perspective.getLeft(), transformNew.getMatrix());
}
项目:BlockSystems    文件:Matrix.java   
private AxisAngle4d getAxisAngle(double x, double y, double z, double angle) {
    AxisAngle4d axisAngle = this.axisAnglePool.getInstance();
    axisAngle.set(x, y, z, angle);
    return axisAngle;
}
项目:BlockSystems    文件:Matrix.java   
private void freeAxisAngle(AxisAngle4d axisAngle) {
    this.axisAnglePool.freeInstance(axisAngle);
}
项目:vzome-core    文件:Camera.java   
/**
 * Sets the value of this transform to the matrix conversion
 * of the double precision axis-angle argument; all of the matrix
 * values are modified.
 * @param a1 the axis-angle to be converted (x, y, z, angle)
 */
private static void set( AxisAngle4d a1, double[] mat )
{
    double mag = Math.sqrt( a1.x*a1.x + a1.y*a1.y + a1.z*a1.z);

    if (almostZero(mag)) {
        setIdentity( mat );
    } else {
        mag = 1.0/mag;
        double ax = a1.x*mag;
        double ay = a1.y*mag;
        double az = a1.z*mag;

        double sinTheta = Math.sin(a1.angle);
        double cosTheta = Math.cos(a1.angle);
        double t = 1.0 - cosTheta;

        double xz = ax * az;
        double xy = ax * ay;
        double yz = ay * az;

        mat[0] = t * ax * ax + cosTheta;
        mat[1] = t * xy - sinTheta * az;
        mat[2] = t * xz + sinTheta * ay;
        mat[3] = 0.0;

        mat[4] = t * xy + sinTheta * az;
        mat[5] = t * ay * ay + cosTheta;
        mat[6] = t * yz - sinTheta * ax;
        mat[7] = 0.0;

        mat[8] = t * xz - sinTheta * ay;
        mat[9] = t * yz + sinTheta * ax;
        mat[10] = t * az * az + cosTheta;
        mat[11] = 0.0;

        mat[12] = 0.0;
        mat[13] = 0.0;
        mat[14] = 0.0;
        mat[15] = 1.0;
    }
}
项目:geowave    文件:EarthVector.java   
/**
 * Locate a coordinate at a specific distance (km), elevation angle
 * (radians), and heading (radians) from this one.
 */
public EarthVector findPoint(
        final double distanceKM,
        final double azimuth,
        final double elevAngle ) {
    // convert distance to radians
    // final double distR = distanceKM / KMPerDegree() / DPR;
    final double lon = getLongitude();
    final double lat = getLatitude();
    // convert local enu to ecf to get east and north vectors
    // east vector
    final Vector3d eastVec = new Vector3d(
            1,
            0,
            0);
    final Vector3d northVec = new Vector3d(
            0,
            1,
            0);
    final double sinLon = Math.sin(lon);
    final double cosLon = Math.cos(lon);
    final double sinLat = Math.sin(lat);
    final double cosLat = Math.cos(lat);
    final Matrix3d enuToEcf = new Matrix3d();
    enuToEcf.m00 = -sinLon;
    enuToEcf.m01 = -(sinLat * cosLon);
    enuToEcf.m02 = cosLat * cosLon;
    enuToEcf.m10 = cosLon;
    enuToEcf.m11 = -(sinLat * sinLon);
    enuToEcf.m12 = cosLat * sinLon;
    enuToEcf.m20 = 0;
    enuToEcf.m21 = cosLat;
    enuToEcf.m22 = sinLat;
    enuToEcf.transform(eastVec);
    enuToEcf.transform(northVec);
    eastVec.normalize();
    northVec.normalize();
    northVec.scale(distanceKM);
    final Matrix3d elevTrans = new Matrix3d();
    elevTrans.set(new AxisAngle4d(
            eastVec,
            elevAngle));

    elevTrans.transform(northVec);
    final Matrix3d azTrans = new Matrix3d();
    final Vector3d unitEcf = new Vector3d(
            ecfVector);
    unitEcf.normalize();
    azTrans.set(new AxisAngle4d(
            unitEcf,
            azimuth));
    azTrans.transform(northVec);
    final Vector3d transformedEcf = new Vector3d();
    transformedEcf.add(
            ecfVector,
            northVec);
    final EarthVector transformedEv = new EarthVector(
            transformedEcf);
    return transformedEv;
}
项目:biojava    文件:IcosahedralSampler.java   
public static void getAxisAngle(int index, AxisAngle4d axisAngle) {
    quat.set(orientations[index]);
    axisAngle.set(quat);
}
项目:biojava    文件:SystematicSolver.java   
private boolean evaluatePermutation(List<Integer> permutation) {
    // permutate subunits
    for (int j = 0, n = subunits.getSubunitCount(); j < n; j++) {
        transformedCoords[j].set(originalCoords[permutation.get(j)]);
    }

    int fold = PermutationGroup.getOrder(permutation);

    // TODO implement this piece of code using at origin superposition
    Quat4d quat = UnitQuaternions.relativeOrientation(
            originalCoords, transformedCoords);
    AxisAngle4d axisAngle = new AxisAngle4d();
    Matrix4d transformation = new Matrix4d();

    transformation.set(quat);
    axisAngle.set(quat);

    Vector3d axis = new Vector3d(axisAngle.x, axisAngle.y, axisAngle.z);
    if (axis.lengthSquared() < 1.0E-6) {
        axisAngle.x = 0;
        axisAngle.y = 0;
        axisAngle.z = 1;
        axisAngle.angle = 0;
    } else {
        axis.normalize();
        axisAngle.x = axis.x;
        axisAngle.y = axis.y;
        axisAngle.z = axis.z;
    }

    CalcPoint.transform(transformation, transformedCoords);

    double subunitRmsd = CalcPoint.rmsd(transformedCoords, originalCoords);

    if (subunitRmsd <parameters.getRmsdThreshold()) {
        // transform to original coordinate system
        combineWithTranslation(transformation);
        QuatSymmetryScores scores = QuatSuperpositionScorer.calcScores(subunits, transformation, permutation);
        if (scores.getRmsd() < 0.0 || scores.getRmsd() > parameters.getRmsdThreshold()) {
            return false;
        }

        scores.setRmsdCenters(subunitRmsd);
        Rotation symmetryOperation = createSymmetryOperation(permutation, transformation, axisAngle, fold, scores);
        rotations.addRotation(symmetryOperation);
        return true;
    }
    return false;
}
项目:biojava    文件:Rotation.java   
/**
 * @return the axisAngle
 */
public AxisAngle4d getAxisAngle() {
    return axisAngle;
}
项目:biojava    文件:Rotation.java   
/**
 * @param axisAngle the axisAngle to set
 */
public void setAxisAngle(AxisAngle4d axisAngle) {
    this.axisAngle = axisAngle;
}