Search in sources :

Example 96 with Vector3d

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

the class GLViewer method rotateContinuous.

// /**
// * Distance of pixel from center (Euchlidean)
// * @param x
// * @param y
// * @return
// */
// private double centerDistance (int x, int y) {
// int dx = x - width / 2;
// int dy = y - height / 2;
// return Math.sqrt (dx * dx + dy * dy);
// }
/**
 * Rotate the eye coordinate frame about the center point, independent
 * of the default up vector.
 *
 * @param xang
 * amount of horizontal rotation (in radians)
 * @param yang
 * amount of vertical rotation (in radians)
 */
protected void rotateContinuous(double xang, double yang) {
    Vector3d reye = new Vector3d();
    reye.sub(getEye(), myViewState.myCenter);
    // up-facing vector
    Vector3d yCam = new Vector3d();
    // right-facing vector
    Vector3d xCam = new Vector3d();
    synchronized (viewMatrix) {
        viewMatrix.R.getRow(1, yCam);
        viewMatrix.R.getRow(0, xCam);
    }
    // System.out.println("Transform: " + XEyeToWorld.R);
    if (yang != 0) {
        RotationMatrix3d R = new RotationMatrix3d(new AxisAngle(xCam, yang));
        reye.transform(R);
        yCam.transform(R);
    }
    if (xang != 0) {
        reye.transform(new RotationMatrix3d(new AxisAngle(yCam, xang)));
    }
    Point3d eye = new Point3d();
    eye.add(reye, myViewState.myCenter);
    setEyeToWorld(eye, myViewState.myCenter, yCam);
    repaint();
}
Also used : AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 97 with Vector3d

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

the class GLViewer method getEyeZDirection.

public Vector3d getEyeZDirection() {
    Vector3d zdir = new Vector3d();
    viewMatrix.R.getRow(2, zdir);
    return zdir;
}
Also used : Vector3d(maspack.matrix.Vector3d)

Example 98 with Vector3d

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

the class RotatableScaler3d method updatePosition.

private void updatePosition(Point3d p1, boolean constrained, boolean repositioning) {
    if (repositioning) {
        Vector3d del = new Vector3d();
        del.sub(p1, myPnt0);
        if (constrained) {
            double s = getConstrainedStepSize();
            del.x = s * Math.round(del.x / s);
            del.y = s * Math.round(del.y / s);
            del.z = s * Math.round(del.z / s);
        }
        myXDraggerToWorld.mulXyz(del.x, del.y, del.z);
    } else {
        AffineTransform3d Tinc = (AffineTransform3d) myIncrementalTransform;
        AffineTransform3d T = (AffineTransform3d) myTransform;
        Vector3d d = new Vector3d(), o = new Vector3d();
        o.sub(myPnt0, T.p);
        if (constrained) {
            d.sub(p1, myPnt0);
            double s = getConstrainedStepSize();
            d.x = s * Math.round(d.x / s);
            d.y = s * Math.round(d.y / s);
            d.z = s * Math.round(d.z / s);
            d.add(o);
        } else {
            d.sub(p1, T.p);
        }
        double x, y, z;
        x = d.x == 0 ? 1 : (o.x == 0 ? 1e-10 : Math.abs(d.x / o.x));
        y = d.y == 0 ? 1 : (o.y == 0 ? 1e-10 : Math.abs(d.y / o.y));
        z = d.z == 0 ? 1 : (o.z == 0 ? 1e-10 : Math.abs(d.z / o.z));
        // x = d.x == 0 ? 1 : (o.x == 0 ? 1e-10 : d.x / o.x);
        // y = d.y == 0 ? 1 : (o.y == 0 ? 1e-10 : d.y / o.y);
        // z = d.z == 0 ? 1 : (o.z == 0 ? 1e-10 : d.z / o.z);
        Tinc.set(T);
        T.setIdentity();
        T.applyScaling(x, y, z);
        Tinc.mulInverseLeft(Tinc, T);
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 99 with Vector3d

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

the class Scaler3d method updatePosition.

private void updatePosition(Point3d p1, boolean constrained) {
    Vector3d d = new Vector3d(), o = new Vector3d();
    o.sub(myPnt0, myTransform.p);
    if (constrained) {
        d.sub(p1, myPnt0);
        double s = getConstrainedStepSize();
        d.x = s * Math.round(d.x / s);
        d.y = s * Math.round(d.y / s);
        d.z = s * Math.round(d.z / s);
        d.add(o);
    } else {
        d.sub(p1, myTransform.p);
    }
    double x, y, z;
    x = d.x == 0 ? 1 : (o.x == 0 ? 1e-10 : Math.abs(d.x / o.x));
    y = d.y == 0 ? 1 : (o.y == 0 ? 1e-10 : Math.abs(d.y / o.y));
    z = d.z == 0 ? 1 : (o.z == 0 ? 1e-10 : Math.abs(d.z / o.z));
    // x = d.x == 0 ? 1 : (o.x == 0 ? 1e-10 : d.x / o.x);
    // y = d.y == 0 ? 1 : (o.y == 0 ? 1e-10 : d.y / o.y);
    // z = d.z == 0 ? 1 : (o.z == 0 ? 1e-10 : d.z / o.z);
    myIncrementalTransform.set(myTransform);
    myTransform.setIdentity();
    myTransform.applyScaling(x, y, z);
    myIncrementalTransform.mulInverseLeft(myIncrementalTransform, myTransform);
}
Also used : Vector3d(maspack.matrix.Vector3d)

Example 100 with Vector3d

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

the class CGSolverTest method createConstraintProblem.

public SparseMatrixNd createConstraintProblem(int nbodies) {
    SparseMatrixNd M = new SparseMatrixNd(5 * nbodies, 5 * nbodies);
    Matrix3d mass = new Matrix3d();
    for (int k = 0; k < nbodies; k++) {
        mass.setRandom(-0.5, 0.5, randGen);
        mass.mulTranspose(mass);
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                M.set(3 * k + i, 3 * k + j, mass.get(i, j));
            }
        }
    }
    int[] connectionCount = new int[nbodies * nbodies];
    Vector3d n = new Vector3d();
    for (int k = 0; k < 2 * nbodies; k++) {
        // find a random connection between two bodies
        int bod1, bod2;
        do {
            bod1 = randGen.nextInt(nbodies);
            bod2 = randGen.nextInt(nbodies);
            if (bod1 < bod2) {
                int l = bod1;
                bod1 = bod2;
                bod2 = l;
            }
        } while (bod1 == bod2 || connectionCount[bod1 * nbodies + bod2] >= 2);
        connectionCount[bod1 * nbodies + bod2]++;
        n.setRandom(-0.5, 0.5, randGen);
        for (int i = 0; i < 3; i++) {
            M.set(bod1 * 3 + i, 3 * nbodies + k, n.get(i));
            M.set(bod2 * 3 + i, 3 * nbodies + k, -n.get(i));
            M.set(3 * nbodies + k, bod1 * 3 + i, n.get(i));
            M.set(3 * nbodies + k, bod2 * 3 + i, -n.get(i));
        }
    }
    return M;
}
Also used : Matrix3d(maspack.matrix.Matrix3d) Vector3d(maspack.matrix.Vector3d) SparseMatrixNd(maspack.matrix.SparseMatrixNd)

Aggregations

Vector3d (maspack.matrix.Vector3d)441 Point3d (maspack.matrix.Point3d)128 RigidTransform3d (maspack.matrix.RigidTransform3d)56 ArrayList (java.util.ArrayList)38 Matrix3d (maspack.matrix.Matrix3d)32 RotationMatrix3d (maspack.matrix.RotationMatrix3d)30 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)24 PolygonalMesh (maspack.geometry.PolygonalMesh)23 Vertex3d (maspack.geometry.Vertex3d)23 Face (maspack.geometry.Face)20 AxisAngle (maspack.matrix.AxisAngle)19 Vector3i (maspack.matrix.Vector3i)19 Point (artisynth.core.mechmodels.Point)18 RenderProps (maspack.render.RenderProps)17 VectorNd (maspack.matrix.VectorNd)15 AffineTransform3d (maspack.matrix.AffineTransform3d)14 IOException (java.io.IOException)13 Vector2d (maspack.matrix.Vector2d)11 Plane (maspack.matrix.Plane)10 GLViewer (maspack.render.GL.GLViewer)9