Search in sources :

Example 11 with BVFeatureQuery

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

the class SurfaceMeshCollider method collideVerticesWithFaces.

/*
    * For each penetrating vertex, find the closest opposing face and add a
    * corresponding new element to the list of ContactPenetratingPoints
    */
public static void collideVerticesWithFaces(ArrayList<PenetratingPoint> cpps, PenetrationRegion region, PolygonalMesh otherMesh) {
    BVFeatureQuery query = new BVFeatureQuery();
    Vector2d uv = new Vector2d();
    Point3d nearPnt = new Point3d();
    Vector3d disp = new Vector3d();
    Point3d wpnt = new Point3d();
    PenetratingPoint cpp;
    for (Vertex3d vtx : region.myVertices) {
        vtx.getWorldPoint(wpnt);
        Face face = query.nearestFaceToPoint(nearPnt, uv, otherMesh, wpnt);
        disp.sub(nearPnt, wpnt);
        cpp = new PenetratingPoint(vtx, face, uv, nearPnt, disp, region);
        cpps.add(cpp);
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face) BVFeatureQuery(maspack.geometry.BVFeatureQuery)

Example 12 with BVFeatureQuery

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

the class MFreeMeshComp method createPointAttachment.

public PointFem3dAttachment createPointAttachment(Point pnt) {
    if (!(getMesh() instanceof PolygonalMesh)) {
        return null;
    }
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    if (!mesh.isTriangular()) {
        return null;
    }
    // Find nearest face to the point. The vertices of this face will be used
    // to find the nodes and weight for the attachment.
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d near = new Point3d();
    Vector2d uv = new Vector2d();
    Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
    Vertex3d[] vtxs = face.getTriVertices();
    double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
    HashMap<FemNode, Double> nodeWeights = new HashMap<FemNode, Double>();
    for (int i = 0; i < vtxs.length; i++) {
        PointAttachment va = myVertexAttachments.get(vtxs[i].getIndex());
        if (va instanceof PointParticleAttachment) {
            PointParticleAttachment ppa = (PointParticleAttachment) va;
            FemNode node = (FemNode) ppa.getParticle();
            accumulateNodeWeights(node, wgts[i], nodeWeights);
        } else if (va instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) va;
            for (int k = 0; k < pfa.numMasters(); k++) {
                FemNode node = pfa.getNodes()[k];
                double w = pfa.getCoordinate(k);
                accumulateNodeWeights(node, w * wgts[i], nodeWeights);
            }
        }
    }
    // Create a new PointFem3dAttachment
    PointFem3dAttachment ax = new PointFem3dAttachment(pnt);
    VectorNd weightVec = new VectorNd();
    for (Double d : nodeWeights.values()) {
        weightVec.append(d);
    }
    ax.setFromNodes(nodeWeights.keySet(), weightVec);
    return ax;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) FemNode(artisynth.core.femmodels.FemNode) HashMap(java.util.HashMap) PointAttachment(artisynth.core.mechmodels.PointAttachment) PolygonalMesh(maspack.geometry.PolygonalMesh) BVFeatureQuery(maspack.geometry.BVFeatureQuery) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Vector2d(maspack.matrix.Vector2d) Point3d(maspack.matrix.Point3d) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 13 with BVFeatureQuery

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

the class MFreeModel3d method findNearestElement.

/**
 * Finds the nearest element and node coordinates
 * @param nearest nearest point
 * @param N shape function evaluation at point
 * @return the nearest element
 */
public FemElement3d findNearestElement(Point3d nearest, Point3d pnt, VectorNd N) {
    BVFeatureQuery query = new BVFeatureQuery();
    NearestIPointCalculator dcalc = new NearestIPointCalculator(pnt);
    query.nearestObject(getElementBVTree(), dcalc);
    FemElement3d elem = dcalc.nearestObject();
    MFreeIntegrationPoint3d ipnt = dcalc.nearestIPoint();
    nearest.set(ipnt.getPosition());
    N.set(ipnt.getShapeWeights());
    return elem;
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) BVFeatureQuery(maspack.geometry.BVFeatureQuery)

Example 14 with BVFeatureQuery

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

the class MFreeModel3d method findNaturalCoordinates.

/**
 * Finds the containing element and node coordinates
 * @param pnt 3D point in world coordinates to find natural coordinates of
 * @param coords natural coordinates
 * @param N shape function values
 * @return the containing element if it exists
 */
public FemNode3d[] findNaturalCoordinates(Point3d pnt, Point3d coords, VectorNd N) {
    BVFeatureQuery query = new BVFeatureQuery();
    NearestIPointCalculator dcalc = new NearestIPointCalculator(pnt);
    query.nearestObject(getElementBVTree(), dcalc);
    FemElement3d elem = dcalc.nearestObject();
    MFreeIntegrationPoint3d ipnt = dcalc.nearestIPoint();
    // try to compute coords
    coords.set(ipnt.getRestPosition());
    int n = ((MFreeElement3d) elem).getNaturalCoordinates(coords, pnt, 1000, N);
    return elem.getNodes();
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) BVFeatureQuery(maspack.geometry.BVFeatureQuery) Point(artisynth.core.mechmodels.Point)

Aggregations

BVFeatureQuery (maspack.geometry.BVFeatureQuery)14 Point3d (maspack.matrix.Point3d)9 Vertex3d (maspack.geometry.Vertex3d)7 Vector2d (maspack.matrix.Vector2d)7 Face (maspack.geometry.Face)6 PolygonalMesh (maspack.geometry.PolygonalMesh)6 Vector3d (maspack.matrix.Vector3d)5 Point (artisynth.core.mechmodels.Point)4 ArrayList (java.util.ArrayList)4 ContactPoint (artisynth.core.mechmodels.ContactPoint)3 TriTriIntersection (maspack.geometry.TriTriIntersection)3 RigidTransform3d (maspack.matrix.RigidTransform3d)3 FemElement3d (artisynth.core.femmodels.FemElement3d)2 PointAttachment (artisynth.core.mechmodels.PointAttachment)2 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 HashMap (java.util.HashMap)2 BVTree (maspack.geometry.BVTree)2 VectorNd (maspack.matrix.VectorNd)2 FemNode (artisynth.core.femmodels.FemNode)1 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)1