Search in sources :

Example 76 with Point3d

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

the class PolygonalMesh method extendOpenEdges.

/**
 * Extends the first open edge loop found.
 *
 * @param amount
 * The amount to extend it by.
 */
public void extendOpenEdges(double amount) {
    // Vertex3d v0;
    HalfEdge he0 = null;
    boolean found = false;
    for (Object fo : myFaces) {
        Face f = (Face) fo;
        he0 = f.he0;
        do {
            if (isOpen(he0)) {
                found = true;
                break;
            }
            he0 = he0.next;
        } while (he0 != f.he0);
        if (found)
            break;
    }
    Vector3d i = new Vector3d(), j = new Vector3d();
    HalfEdge he = he0;
    ArrayList<Vertex3d> iverts = new ArrayList<Vertex3d>(), overts = new ArrayList<Vertex3d>();
    do {
        HalfEdgeNode hen = he.tail.getIncidentHedges();
        while (hen != null) {
            if (isOpen(hen.he)) {
                break;
            }
            hen = hen.next;
        }
        he.computeUnitVec(i);
        hen.he.computeUnitVec(j);
        double angleFactor = 1.0 - i.angle(j) / Math.PI;
        i.add(j);
        i.cross(he.face.getNormal());
        i.normalize();
        Point3d p = new Point3d();
        p.scaledAdd(amount * angleFactor, i, he.tail.pnt);
        iverts.add(he.tail);
        overts.add(addVertex(p));
        he = hen.he;
    } while (he != he0);
    Vertex3d lastiv = iverts.get(iverts.size() - 1), lastov = overts.get(overts.size() - 1);
    for (int v = 0; v < iverts.size(); v++) {
        Vertex3d iv = iverts.get(v), ov = overts.get(v);
        addFace(new int[] { lastiv.idx, iv.idx, ov.idx });
        addFace(new int[] { ov.idx, lastov.idx, lastiv.idx });
        lastiv = iv;
        lastov = ov;
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList)

Example 77 with Point3d

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

the class PolygonalMesh method computePrincipalAxes.

public static RigidTransform3d computePrincipalAxes(PolygonalMesh mesh) {
    Vector3d mov1 = new Vector3d();
    Vector3d mov2 = new Vector3d();
    Vector3d pov = new Vector3d();
    double vol = mesh.computeVolumeIntegrals(mov1, mov2, pov);
    double mass = vol;
    Point3d cov = new Point3d();
    // center of volume
    cov.scale(1.0 / vol, mov1);
    // [c], skew symmetric
    Matrix3d covMatrix = new Matrix3d(0, -cov.z, cov.y, cov.z, 0, -cov.x, -cov.y, cov.x, 0);
    // J
    Matrix3d J = new Matrix3d((mov2.y + mov2.z), -pov.z, -pov.y, -pov.z, (mov2.x + mov2.z), -pov.x, -pov.y, -pov.x, (mov2.x + mov2.y));
    // Jc = J + m[c][c]
    Matrix3d Jc = new Matrix3d();
    Jc.mul(covMatrix, covMatrix);
    Jc.scale(mass);
    Jc.add(J);
    // Compute eigenvectors and eigenvlaues of Jc
    SymmetricMatrix3d JcSymmetric = new SymmetricMatrix3d(Jc);
    Vector3d lambda = new Vector3d();
    Matrix3d U = new Matrix3d();
    JcSymmetric.getEigenValues(lambda, U);
    // Construct the rotation matrix
    RotationMatrix3d R = new RotationMatrix3d();
    R.set(U);
    lambda.absolute();
    if (lambda.x > lambda.y && lambda.z > lambda.y) {
        R.rotateZDirection(new Vector3d(R.m01, R.m11, R.m21));
    } else if (lambda.x > lambda.z && lambda.y > lambda.z) {
        R.rotateZDirection(new Vector3d(R.m00, R.m10, R.m20));
    }
    return (new RigidTransform3d(cov, R));
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) RotationMatrix3d(maspack.matrix.RotationMatrix3d) Matrix3d(maspack.matrix.Matrix3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 78 with Point3d

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

the class NURBSObject method drawControlPoints.

protected void drawControlPoints(Renderer renderer, RenderProps props, int flags) {
    Point3d tmp = new Point3d();
    boolean selecting = renderer.isSelecting();
    for (int i = 0; i < myCtrlPnts.size(); i++) {
        if (selecting) {
            renderer.beginSelectionQuery(i);
            drawControlPoint(renderer, props, i, tmp);
            renderer.endSelectionQuery();
        } else {
            drawControlPoint(renderer, props, i, tmp);
        }
    }
    renderer.setPointSize(1);
}
Also used : Point3d(maspack.matrix.Point3d)

Example 79 with Point3d

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

the class OBB method computeBoundsFromConvexHullPoints.

// protected void setUsingConvexHullOfPoints (
// double[] pnts, int npnts, double margin) {
// 
// Matrix3d C = new Matrix3d();
// Point3d cent = new Point3d();
// 
// quickhull3d.Point3d[] hullPnts =
// computeConvexHullAndCovariance (C, cent, pnts, npnts);
// 
// setTransform (C, cent);
// Point3d max = new Point3d (-INF, -INF, -INF);
// Point3d min = new Point3d (INF, INF, INF);
// computeBoundsFromConvexHullPoints (min, max, hullPnts, hullPnts.length);
// setWidthsAndCenter (min, max, margin);
// }
// 
private void computeBoundsFromConvexHullPoints(Point3d min, Point3d max, quickhull3d.Point3d[] pnts, int num) {
    Vector3d xpnt = new Point3d();
    for (int i = 0; i < num; i++) {
        xpnt.set(pnts[i].x, pnts[i].y, pnts[i].z);
        xpnt.inverseTransform(myX);
        xpnt.updateBounds(min, max);
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 80 with Point3d

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

the class OBB method set.

public void set(Boundable[] elems, int num, double margin, Method method) {
    Matrix3d C = new Matrix3d();
    Point3d cent = new Point3d();
    Point3d max = new Point3d(-INF, -INF, -INF);
    Point3d min = new Point3d(INF, INF, INF);
    switch(method) {
        case ConvexHull:
            {
                HashedPointSet pointSet = createPointSetForOBB(elems, num);
                quickhull3d.Point3d[] hullPnts = computeConvexHullAndCovariance(C, cent, pointSet.getPointsAsDoubleArray(), pointSet.size());
                setTransform(C, cent);
                computeBoundsFromConvexHullPoints(min, max, hullPnts, hullPnts.length);
                break;
            }
        case Covariance:
            {
                computeCovarianceFromElements(C, cent, elems, num);
                setTransform(C, cent);
                computeBoundsFromElements(min, max, elems, num);
                break;
            }
        case Points:
            {
                HashedPointSet pointSet = createPointSetForOBB(elems, num);
                Point3d[] pnts = pointSet.getPoints();
                computeCovarianceFromPoints(C, cent, pnts);
                setTransform(C, cent);
                computeBoundsFromPoints(min, max, pnts);
                break;
            }
        default:
            throw new InternalErrorException("Unimplemented method " + method);
    }
    setWidthsAndCenter(min, max, margin);
}
Also used : SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) RotationMatrix3d(maspack.matrix.RotationMatrix3d) Matrix3d(maspack.matrix.Matrix3d) Point3d(maspack.matrix.Point3d) InternalErrorException(maspack.util.InternalErrorException)

Aggregations

Point3d (maspack.matrix.Point3d)464 Vector3d (maspack.matrix.Vector3d)128 ArrayList (java.util.ArrayList)59 RigidTransform3d (maspack.matrix.RigidTransform3d)48 Vertex3d (maspack.geometry.Vertex3d)35 Point (artisynth.core.mechmodels.Point)30 PolygonalMesh (maspack.geometry.PolygonalMesh)30 Face (maspack.geometry.Face)25 ReaderTokenizer (maspack.util.ReaderTokenizer)19 IOException (java.io.IOException)18 RotationMatrix3d (maspack.matrix.RotationMatrix3d)17 Vector2d (maspack.matrix.Vector2d)16 VectorNd (maspack.matrix.VectorNd)16 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)15 HashMap (java.util.HashMap)14 Muscle (artisynth.core.mechmodels.Muscle)13 FemNode3d (artisynth.core.femmodels.FemNode3d)12 Particle (artisynth.core.mechmodels.Particle)12 BufferedReader (java.io.BufferedReader)11 Plane (maspack.matrix.Plane)11