Search in sources :

Example 36 with RotationMatrix3d

use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.

the class AffineTransformWidget method updateInternalValue.

/**
 * Updates the internal representation of the value, updates any result
 * holders, and returns true if the new value differs from the old value.
 */
protected boolean updateInternalValue(Object value) {
    if (!valuesEqual(value, getInternalValue())) {
        maskValueChanges(true);
        if (value == Property.VoidValue) {
            for (LabeledTextField c : myFields) {
                c.setValue(Property.VoidValue);
            }
            myValueIsVoid = true;
        } else {
            RotationMatrix3d R = new RotationMatrix3d();
            Vector3d p = new Vector3d();
            Vector3d scale = new Vector3d(1, 1, 1);
            Vector3d shear = new Vector3d(0, 0, 0);
            if (value instanceof RigidTransform3d) {
                RigidTransform3d newX = (RigidTransform3d) value;
                p.set(newX.p);
                R.set(newX.R);
            // System.out.println ("newT\n" + newX.toString("%10.6f"));
            } else if (value instanceof AffineTransform3d) {
                AffineTransform3d newX = (AffineTransform3d) value;
                p.set(newX.p);
                newX.factorA(R, scale, shear);
            // System.out.println ("newX\n" + newX.toString("%10.6f"));
            } else {
                throw new InternalErrorException("Unknown value type " + value.getClass());
            }
            setTranslation(p);
            setRotation(R.getAxisAngle());
            setScale(scale);
            setShear(shear);
            myValueIsVoid = false;
        }
        maskValueChanges(false);
        return true;
    } else {
        return false;
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) InternalErrorException(maspack.util.InternalErrorException) RotationMatrix3d(maspack.matrix.RotationMatrix3d) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 37 with RotationMatrix3d

use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.

the class AxisAngleField method main.

public static void main(String[] args) {
    JFrame frame = new JFrame("AxisAngleField Test");
    LabeledComponentPanel panel = new LabeledComponentPanel();
    AxisAngleField widget = new AxisAngleField();
    frame.getContentPane().add(panel);
    RotationMatrix3d R = new RotationMatrix3d(1, 0, 0, Math.toRadians(45));
    widget.setValue(new AxisAngle(R));
    panel.addWidget("axisAng", widget);
    // panel.addWidget (widget);
    frame.pack();
    frame.setVisible(true);
}
Also used : AxisAngle(maspack.matrix.AxisAngle) JFrame(javax.swing.JFrame) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 38 with RotationMatrix3d

use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.

the class GLViewer method computeInverseTranspose.

protected Matrix3d computeInverseTranspose(Matrix3dBase M) {
    Matrix3d out = new Matrix3d(M);
    if (!(M instanceof RotationMatrix3d)) {
        boolean success = out.invert();
        if (!success) {
            SVDecomposition3d svd3 = new SVDecomposition3d(M);
            svd3.pseudoInverse(out);
        }
        out.transpose();
    }
    return out;
}
Also used : RotationMatrix3d(maspack.matrix.RotationMatrix3d) Matrix3d(maspack.matrix.Matrix3d) SVDecomposition3d(maspack.matrix.SVDecomposition3d) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 39 with RotationMatrix3d

use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.

the class GLViewer method rotateFixedUp.

/**
 * Rotate the eye coordinate frame about the center point, while maintaining
 * the default up vector.
 *
 * @param xang
 * amount of horizontal rotation (in radians)
 * @param yang
 * amount of vertical rotation (in radians)
 * @see #getUpVector
 */
protected void rotateFixedUp(double xang, double yang) {
    Vector3d reye = new Vector3d();
    reye.sub(getEye(), myViewState.myCenter);
    if (yang != 0) {
        // right-facing vector
        Vector3d xCam = new Vector3d();
        synchronized (viewMatrix) {
            viewMatrix.R.getRow(0, xCam);
        }
        double oldAngle = Math.acos(reye.dot(myViewState.myUp) / reye.norm());
        if (!((yang < 0 && (-yang) > oldAngle) || (yang > 0 && yang > (Math.PI - oldAngle)))) {
            reye.transform(new RotationMatrix3d(new AxisAngle(xCam, yang)));
        }
    }
    if (xang != 0) {
        reye.transform(new RotationMatrix3d(new AxisAngle(myViewState.myUp, xang)));
    }
    Point3d eye = new Point3d();
    eye.add(reye, myViewState.myCenter);
    setEyeToWorld(eye, myViewState.myCenter, myViewState.myUp);
    repaint();
}
Also used : AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 40 with RotationMatrix3d

use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.

the class Transrotator3d method updateRotation.

protected void updateRotation(RotationMatrix3d Rot, boolean constrained) {
    RigidTransform3d Tinc = (RigidTransform3d) myIncrementalTransform;
    RigidTransform3d T = (RigidTransform3d) myTransform;
    RotationMatrix3d R = new RotationMatrix3d();
    R.mulInverseLeft(myRot0, Rot);
    if (constrained) {
        AxisAngle axisAng = new AxisAngle();
        R.getAxisAngle(axisAng);
        double deg = Math.toDegrees(axisAng.angle);
        axisAng.angle = Math.toRadians(5 * Math.round(deg / 5));
        R.setAxisAngle(axisAng);
        myRotPnt.transform(R, myPnt0);
    }
    Tinc.R.mulInverseLeft(T.R, R);
    if (myConstrainer != null) {
        RotationMatrix3d Rnew = new RotationMatrix3d();
        Rnew.mul(myXDraggerToWorld.R, Tinc.R);
        RigidTransform3d Tnew = new RigidTransform3d(myXDraggerToWorld);
        if (myConstrainer.updateRotation(Rnew, myXDraggerToWorld)) {
            Tinc.R.mulInverseLeft(myXDraggerToWorld.R, Rnew);
            myXDraggerToWorld.R.set(Rnew);
            T.R.mul(Tinc.R);
            myRotPnt.transform(T.R, myPnt0);
        } else {
            Tinc.R.setIdentity();
        }
    } else {
        T.R.set(R);
        myXDraggerToWorld.R.mul(Tinc.R);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Aggregations

RotationMatrix3d (maspack.matrix.RotationMatrix3d)66 Vector3d (maspack.matrix.Vector3d)27 RigidTransform3d (maspack.matrix.RigidTransform3d)15 Point3d (maspack.matrix.Point3d)14 Matrix3d (maspack.matrix.Matrix3d)13 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)9 AxisAngle (maspack.matrix.AxisAngle)7 Matrix6d (maspack.matrix.Matrix6d)6 Point (artisynth.core.mechmodels.Point)4 AffineTransform3d (maspack.matrix.AffineTransform3d)4 SVDecomposition3d (maspack.matrix.SVDecomposition3d)4 VectorNd (maspack.matrix.VectorNd)3 InternalErrorException (maspack.util.InternalErrorException)3 FrameMaterial (artisynth.core.materials.FrameMaterial)2 RotAxisFrameMaterial (artisynth.core.materials.RotAxisFrameMaterial)2 JFrame (javax.swing.JFrame)2 AxisAlignedRotation (maspack.matrix.AxisAlignedRotation)2 Matrix6dBlock (maspack.matrix.Matrix6dBlock)2 Matrix6x3Block (maspack.matrix.Matrix6x3Block)2 Plane (maspack.matrix.Plane)2