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);
}
}
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;
}
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;
}
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();
}
Aggregations