use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class FemMeshComp method createVertex.
private Vertex3d createVertex(double s0, double s1, double s2, FemElement3d elem, FemNode3d n0, FemNode3d n1, FemNode3d n2) {
Vector3d coords = new Vector3d();
addNodeCoords(coords, s0, s1, s2, elem, n0, n1, n2);
addNodeCoords(coords, s1, s0, s2, elem, n1, n0, n2);
if (n2 != null) {
addNodeCoords(coords, s2, s1, s0, elem, n2, n1, n0);
}
ArrayList<FemNode> nodes = new ArrayList<FemNode>();
VectorNd weights = new VectorNd();
Point3d pos = new Point3d();
for (int i = 0; i < elem.numNodes(); i++) {
double w = elem.getN(i, coords);
if (Math.abs(w) > EPS) {
FemNode3d n = elem.getNodes()[i];
nodes.add(n);
weights.append(w);
pos.scaledAdd(w, n.getPosition());
}
}
Vertex3d vtx = new Vertex3d(pos);
PointFem3dAttachment attacher = new PointFem3dAttachment();
attacher.setFromNodes(nodes, weights);
myVertexAttachments.add(attacher);
getMesh().addVertex(vtx);
return vtx;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class PointFem3dAttachment method dosetNodes.
private void dosetNodes(FemNode[] nodes, double[] weights) {
if (nodes.length == 0) {
throw new IllegalArgumentException("Must have at least one node");
}
if (nodes.length > weights.length) {
throw new IllegalArgumentException("Number of weights is less than the number of nodes");
}
removeBackRefsIfConnected();
myCoords = new VectorNd(nodes.length);
myNodes = new FemNode[nodes.length];
for (int i = 0; i < nodes.length; i++) {
myNodes[i] = nodes[i];
if (weights != null) {
myCoords.set(i, weights[i]);
}
}
invalidateMasters();
addBackRefsIfConnected();
notifyParentOfChange(DynamicActivityChangeEvent.defaultEvent);
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class PointFem3dAttachment method create.
/**
* Create an attachment that connects a point to a FemElement
* within a specified element.
*
* @param pnt Point to be attached
* @param elem FemElement3d to attach the point to
* @param loc point location with respect to the element. If <code>null</code>,
* will be assumed to be pnt.getPosition().
* @param reduceTol try to reduce the number of attached nodes by
* removing those whose coordinate values are less then this number.
* A value of zero ensures no reduction. If reduction is desired,
* a value around 1e-5 is reasonable.
* @return an attachment for
*/
public static PointFem3dAttachment create(Point pnt, FemElement3d elem, Point3d loc, double reduceTol) {
PointFem3dAttachment ax = null;
// Figure out the coordinates for the attachment point
VectorNd coords = new VectorNd(elem.numNodes());
elem.getMarkerCoordinates(coords, loc != null ? loc : pnt.getPosition(), false);
// if (reduceTol > 0) {
// FemNode3d[] nodes = elem.getNodes();
// // Find number of coordinates which are close to zero
// int numZero = 0;
// for (int i=0; i<elem.numNodes(); i++) {
// if (Math.abs(coords.get(i)) < reduceTol) {
// numZero++;
// }
// }
// // If we have coordinates close to zero, and the number of remaining
// // coords is <= 4, then specify the nodes and coords explicitly
// if (numZero > 0 && elem.numNodes()-numZero <= 4) {
// int numc = elem.numNodes()-numZero;
// double[] reducedCoords = new double[numc];
// FemNode3d[] reducedNodes = new FemNode3d[numc];
// int k = 0;
// for (int i=0; i<elem.numNodes(); i++) {
// if (Math.abs(coords.get(i)) >= reduceTol) {
// reducedCoords[k] = coords.get(i);
// reducedNodes[k] = nodes[i];
// k++;
// }
// }
// ax = new PointFem3dAttachment (pnt);
// ax.setFromNodes (reducedNodes, reducedCoords);
// return ax;
// }
// }
ax = new PointFem3dAttachment(pnt);
ax.setFromElement(pnt.getPosition(), elem, reduceTol);
// ax.myCoords.set (coords);
return ax;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class PointFem3dAttachment method setFromNodes.
public boolean setFromNodes(Point3d pos, FemNode[] nodes) {
ArrayList<Vector3d> support = new ArrayList<Vector3d>(nodes.length);
for (int i = 0; i < nodes.length; i++) {
support.add(nodes[i].getPosition());
}
InverseDistanceWeights idweights = new InverseDistanceWeights(1, 1, /*normalize=*/
true);
VectorNd weights = new VectorNd();
boolean status = idweights.compute(weights, pos, support);
dosetNodes(nodes, weights.getBuffer());
myElement = null;
return status;
}
use of maspack.matrix.VectorNd in project artisynth_core by artisynth.
the class ForceTargetTerm method getTargetWeights.
public VectorNd getTargetWeights() {
VectorNd out = new VectorNd(myForceTargets.size());
getTargetWeights(out);
return out;
}
Aggregations