Search in sources :

Example 11 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class FemMuscleModel method getSegmentInsideSphere.

// intersects segment with the given sphere, and returns
// the portion inside or null if no intersection
private static LineSegment getSegmentInsideSphere(LineSegment segment, Point3d pos, double rad) {
    Point3d p1 = segment.myVtx0.getPosition();
    Point3d p2 = segment.myVtx1.getPosition();
    // check if segment starts inside
    boolean isP1Inside = isInsideSphere(p1, pos, rad);
    // p2-c
    Point3d p = new Point3d();
    // p1-p2
    Point3d dp = new Point3d();
    double r2 = rad * rad;
    // for use with quadratic equation
    double a, b, c, d, lambda1, lambda2;
    p.sub(p2, pos);
    dp.sub(p1, p2);
    // find intersection with sphere
    a = dp.normSquared();
    b = 2 * dp.dot(p);
    c = p.normSquared() - r2;
    d = b * b - 4 * a * c;
    if (d >= 0) {
        d = Math.sqrt(d);
        lambda1 = (-b + d) / (2 * a);
        lambda2 = (-b - d) / (2 * a);
    } else {
        lambda1 = Double.NaN;
        lambda2 = Double.NaN;
    }
    // if p2 is inside, return
    if (p.normSquared() <= r2) {
        if (isP1Inside) {
            return segment;
        } else {
            // find intersection
            if (lambda1 >= 0 && lambda1 <= 1) {
                p1.scaledAdd(lambda1, dp, p2);
            } else {
                p1.scaledAdd(lambda2, dp, p2);
            }
            return new LineSegment(new Vertex3d(p1), new Vertex3d(p2));
        }
    } else {
        // if p1 inside, find single intersection
        if (isP1Inside) {
            if (lambda1 >= 0 && lambda1 <= 1) {
                p2.scaledAdd(lambda1, dp);
            } else {
                p2.scaledAdd(lambda2, dp);
            }
            return new LineSegment(new Vertex3d(p1), new Vertex3d(p2));
        } else {
            // check if passes entirely through sphere
            if (d >= 0) {
                if (lambda1 >= 0 && lambda1 <= 1 && lambda2 >= 0 && lambda2 <= 1) {
                    p1.scaledAdd(lambda1, dp, p2);
                    p2.scaledAdd(lambda2, dp);
                    return new LineSegment(new Vertex3d(p1), new Vertex3d(p2));
                }
            }
        // done checking if crossed sphere
        }
    // done checking if p1 outside
    }
    return null;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point3d(maspack.matrix.Point3d) LineSegment(maspack.geometry.LineSegment)

Example 12 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class SimpleFemWriter method writeSurfaceFile.

public void writeSurfaceFile(FemModel3d fem, PrintWriter surfaceWriter) {
    PolygonalMesh mesh = fem.getSurfaceMesh();
    for (Face face : mesh.getFaces()) {
        surfaceWriter.print(faceToken);
        for (Vertex3d vtx : face.getVertices()) {
            FemNode3d node = fem.getSurfaceNode(vtx);
            if (node != null) {
                surfaceWriter.print(" " + (node.getNumber() + nodeOffset));
            }
        }
        surfaceWriter.println();
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 13 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class SkinMeshBody method collectVertices.

private void collectVertices(Vertex3d vtx, int networkDist, ArrayList<Vertex3d> list) {
    if (list.contains(vtx)) {
        return;
    }
    list.add(vtx);
    if (networkDist > 0) {
        Iterator<HalfEdge> it = vtx.getIncidentHalfEdges();
        while (it.hasNext()) {
            HalfEdge he = it.next();
            Vertex3d vtxTail = he.tail;
            collectVertices(vtxTail, networkDist - 1, list);
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HalfEdge(maspack.geometry.HalfEdge)

Example 14 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class SkinMeshBody method resetBasePositions.

/**
 * Resets the base positions for all attachments in this SkinMeshBody
 * to the current vertex position.
 */
protected void resetBasePositions() {
    MeshBase mesh = getMesh();
    for (int i = 0; i < myVertexAttachments.size(); i++) {
        PointSkinAttachment a = myVertexAttachments.get(i);
        Vertex3d vtx = mesh.getVertices().get(a.getNumber());
        a.setBasePosition(vtx.getPosition());
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) MeshBase(maspack.geometry.MeshBase) SkinMeshBase(artisynth.core.mechmodels.SkinMeshBase) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 15 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class SkinMeshBody method computeDisplacementAttachments.

/**
 * Computes displacement-based attachments for each vertex attachment in
 * this skin mesh.  For each vertex, the weights are determined using the
 * relative distances from the vertex to the surface meshes of each of the
 * controlling bodies (Frame, FemModel, etc.). Controlling bodies which
 * don't have a surface mesh are ignored.
 *
 * <p>
 * Bodies further away have a lower weighting. If <code>sigma</code>
 * is non-positive, the weighting is determined using an inverse-square
 * attenuation. Otherwise, the weighting is determined using a
 * Gaussian attention controlled by <code>sigma</code>.
 *
 * @param sigma if greater than 0, specifies a Gaussian weighting
 * attenuation.
 */
public void computeDisplacementAttachments(double sigma) {
    MeshBase mesh = getMesh();
    MeshDistCalc dcalc = new MeshDistCalc();
    clearAttachments();
    for (int i = 0; i < mesh.numVertices(); i++) {
        Vertex3d vtx = mesh.getVertices().get(i);
        dcalc.computeDistancesAndWeights(vtx.getPosition(), sigma);
        PointSkinAttachment a = dcalc.computeDisplacementAttachment();
        addAttachment(a);
    }
    myLastSigma = sigma;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) MeshBase(maspack.geometry.MeshBase) SkinMeshBase(artisynth.core.mechmodels.SkinMeshBase) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Aggregations

Vertex3d (maspack.geometry.Vertex3d)81 Point3d (maspack.matrix.Point3d)35 Face (maspack.geometry.Face)30 PolygonalMesh (maspack.geometry.PolygonalMesh)24 Vector3d (maspack.matrix.Vector3d)23 ContactPoint (artisynth.core.mechmodels.ContactPoint)22 Point (artisynth.core.mechmodels.Point)22 ArrayList (java.util.ArrayList)19 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)15 HalfEdge (maspack.geometry.HalfEdge)13 PointAttachment (artisynth.core.mechmodels.PointAttachment)10 HashMap (java.util.HashMap)10 Vector2d (maspack.matrix.Vector2d)8 VectorNd (maspack.matrix.VectorNd)8 BVFeatureQuery (maspack.geometry.BVFeatureQuery)7 RenderProps (maspack.render.RenderProps)6 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)5 Color (java.awt.Color)5 FemNode (artisynth.core.femmodels.FemNode)4 BufferedWriter (java.io.BufferedWriter)4