use of artisynth.core.mechmodels.Point in project artisynth_core by artisynth.
the class FemMuscleDemo method addStrand.
/**
* Adds a strand of muscles interpolated between two points, using FemNodes
* if they are close enough, or otherwise inserting markers.
*/
protected void addStrand(MuscleBundle bundle, double p0x, double p0y, double p0z, double p1x, double p1y, double p1z, double quadTerm, int numPnts) {
Point pnt;
Point prevPnt = null;
Point3d pos0 = new Point3d(p0x, p0y, p0z);
Point3d pos1 = new Point3d(p1x, p1y, p1z);
Point3d pos = new Point3d();
for (int i = 0; i < numPnts; i++) {
double s = i / (numPnts - 1.0);
pos.combine(1 - s, pos0, s, pos1);
double r = Math.sqrt(pos.x * pos.x + pos.y * pos.y);
pos.z += quadTerm * r * r;
pnt = findNearestNode(pos);
if (pnt.distance(pos) > 0.0001) {
FemMarker mkr = new FemMarker(pos);
tissue.addMarker(mkr);
pnt = mkr;
}
if (prevPnt != null) {
Muscle muscle = new Muscle();
muscle.setConstantMuscleMaterial(1, 1);
muscle.setFirstPoint(prevPnt);
muscle.setSecondPoint(pnt);
bundle.addFibre(muscle);
}
prevPnt = pnt;
}
}
use of artisynth.core.mechmodels.Point in project artisynth_core by artisynth.
the class PointModel method add1dMuscles.
public void add1dMuscles() {
boolean[] dyn = new boolean[] { false, true, false };
int[] x = new int[] { -1, 0, 1 };
// boolean[] dyn = new boolean[]{false,true, true, true,false};
// int[] x = new int[]{-2,-1,0,1,2};
// double eps = 1e-4;
ArrayList<Point> pts = new ArrayList<Point>(x.length);
for (int i = 0; i < x.length; i++) {
Point3d pnt = new Point3d(x[i], 0, 0);
// pnt.normalize();
pnt.scale(len);
Particle pt = new Particle(mass, pnt);
pt.setPointDamping(pointDamping);
pt.setDynamic(dyn[i]);
model.addParticle(pt);
pts.add(pt);
if (x[i] == 0) {
// center = pt;
}
}
for (int i = 1; i < pts.size(); i++) {
AxialSpring m;
Point p0 = pts.get(i - 1);
Point p1 = pts.get(i);
// if (p0==center || p1==center)
// m = addAxialSpring(p0, p1);
// else
m = addMuscle(p0, p1);
m.setName("m" + Integer.toString(m.getNumber()));
}
}
use of artisynth.core.mechmodels.Point in project artisynth_core by artisynth.
the class FemElement3d method computeCovariance.
public double computeCovariance(Matrix3d C) {
double vol = 0;
Point3d pnt = new Point3d();
IntegrationPoint3d[] ipnts = getIntegrationPoints();
for (int i = 0; i < ipnts.length; i++) {
IntegrationPoint3d pt = ipnts[i];
// compute the current position of the integration point in pnt:
pnt.setZero();
for (int k = 0; k < pt.N.size(); k++) {
pnt.scaledAdd(pt.N.get(k), myNodes[k].getPosition());
}
// now get dv, the current volume at the integration point
pt.computeJacobian(myNodes);
double detJ = pt.getJ().determinant();
double dv = detJ * pt.getWeight();
C.addScaledOuterProduct(dv, pnt, pnt);
vol += dv;
}
return vol;
}
use of artisynth.core.mechmodels.Point in project artisynth_core by artisynth.
the class FemElement3d method computeVolumes.
// /**
// * Default method to get the element volume. Uses quadrature. Individual
// * elements can override this with a more efficient method if needed.
// */
// public double getVolume() {
// return computeVolume();
// }
/**
* Default method to compute an element's volume and partial volumes. Uses
* quadrature. If the number of pressure values is 1, then there is only one
* partial rest volume which is equal to the overall rest volume. The volume
* at each quadrature point is also stored in the <code>dv</code> field of
* the elements integration data, for possible future use.
*
* <p>The method should return the minimum Jacobian value found when
* computing the volume for this element. A negative value indicates
* element inversion.
*
* <p>Individual elements can override this with a more efficient
* method if needed.
*/
public double computeVolumes() {
int npvals = numPressureVals();
double vol = 0;
for (int k = 0; k < npvals; k++) {
myVolumes[k] = 0;
}
double minDetJ = Double.MAX_VALUE;
IntegrationPoint3d[] ipnts = getIntegrationPoints();
IntegrationData3d[] idata = getIntegrationData();
for (int i = 0; i < ipnts.length; i++) {
IntegrationPoint3d pt = ipnts[i];
pt.computeJacobian(myNodes);
double detJ = pt.getJ().determinant();
double dv = detJ * pt.getWeight();
// normalize detJ to get true value relative to rest position
detJ /= idata[i].getDetJ0();
idata[i].setDv(dv);
if (npvals > 1) {
double[] H = pt.getPressureWeights().getBuffer();
for (int k = 0; k < npvals; k++) {
myVolumes[k] += H[k] * dv;
}
}
if (detJ < minDetJ) {
minDetJ = detJ;
}
vol += dv;
}
if (npvals == 1) {
myVolumes[0] = vol;
}
myVolume = vol;
return minDetJ;
}
use of artisynth.core.mechmodels.Point in project artisynth_core by artisynth.
the class FemElement3d method setFrame.
/**
* Set reference frame information for this element. This can be used for
* computing anisotropic material parameters. In principle, each integration
* point can have its own frame information, but this method simply sets the
* same frame information for all the integration points, storing it in each
* IntegrationData structure. Setting <code>M</code> to <code>null</code>
* removes the frame information.
*
* @param M frame information (is copied by the method)
*/
public void setFrame(Matrix3dBase M) {
Matrix3d F = null;
if (M != null) {
F = new Matrix3d(M);
}
IntegrationData3d[] idata = doGetIntegrationData();
for (int i = 0; i < idata.length; i++) {
idata[i].myFrame = F;
}
}
Aggregations